vertica 0.10.2 → 0.10.3

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.10.2
1
+ 0.10.3
@@ -50,7 +50,7 @@ class Vertica::Connection
50
50
  end
51
51
 
52
52
  def ssl?
53
- Object.const_defined?('OpenSSL') && socket.kind_of?(OpenSSL::SSL::SSLSocket)
53
+ Object.const_defined?('OpenSSL') && @socket.kind_of?(OpenSSL::SSL::SSLSocket)
54
54
  end
55
55
 
56
56
  def opened?
@@ -69,17 +69,22 @@ class Vertica::Connection
69
69
  @current_job.nil?
70
70
  end
71
71
 
72
- def write(message)
72
+ def write_message(message)
73
73
  raise ArgumentError, "invalid message: (#{message.inspect})" unless message.respond_to?(:to_bytes)
74
74
  puts "=> #{message.inspect}" if @debug
75
- socket.write message.to_bytes
76
- rescue SystemCallError => e
75
+ begin
76
+ socket.write_nonblock message.to_bytes
77
+ rescue IO::WaitReadable, IO::WaitWritable => wait_error
78
+ io_select(wait_error)
79
+ retry
80
+ end
81
+ rescue SystemCallError, IOError => e
77
82
  close_socket
78
83
  raise Vertica::Error::ConnectionError.new(e.message)
79
84
  end
80
85
 
81
86
  def close
82
- write Vertica::Messages::Terminate.new
87
+ write_message Vertica::Messages::Terminate.new
83
88
  ensure
84
89
  close_socket
85
90
  end
@@ -87,7 +92,7 @@ class Vertica::Connection
87
92
  def close_socket
88
93
  socket.close
89
94
  @socket = nil
90
- rescue SystemCallError
95
+ rescue SystemCallError, IOError
91
96
  ensure
92
97
  reset_values
93
98
  end
@@ -104,8 +109,8 @@ class Vertica::Connection
104
109
 
105
110
  def cancel
106
111
  conn = self.class.new(options.merge(:skip_startup => true))
107
- conn.write Vertica::Messages::CancelRequest.new(backend_pid, backend_key)
108
- conn.write Vertica::Messages::Flush.new
112
+ conn.write_message Vertica::Messages::CancelRequest.new(backend_pid, backend_key)
113
+ conn.write_message Vertica::Messages::Flush.new
109
114
  conn.socket.close
110
115
  end
111
116
 
@@ -122,19 +127,13 @@ class Vertica::Connection
122
127
  end
123
128
 
124
129
  def read_message
125
- ready = IO.select([socket], nil, nil, @options[:read_timeout])
126
- if ready
127
- type = read_bytes(1)
128
- size = read_bytes(4).unpack('N').first
129
- raise Vertica::Error::MessageError.new("Bad message size: #{size}.") unless size >= 4
130
- message = Vertica::Messages::BackendMessage.factory type, read_bytes(size - 4)
131
- puts "<= #{message.inspect}" if @debug
132
- return message
133
- else
134
- close
135
- raise Vertica::Error::TimedOutError.new("Connection timed out.")
136
- end
137
- rescue SystemCallError => e
130
+ type = read_bytes(1)
131
+ size = read_bytes(4).unpack('N').first
132
+ raise Vertica::Error::MessageError.new("Bad message size: #{size}.") unless size >= 4
133
+ message = Vertica::Messages::BackendMessage.factory type, read_bytes(size - 4)
134
+ puts "<= #{message.inspect}" if @debug
135
+ return message
136
+ rescue SystemCallError, IOError => e
138
137
  close_socket
139
138
  raise Vertica::Error::ConnectionError.new(e.message)
140
139
  end
@@ -207,21 +206,30 @@ class Vertica::Connection
207
206
  end
208
207
 
209
208
  def read_bytes(n)
210
- bytes = socket.read(n)
211
-
212
- raise Errno::EIO if bytes.nil? || bytes.size != n
209
+ socket.read_nonblock(n)
210
+ rescue IO::WaitReadable, IO::WaitWritable => wait_error
211
+ io_select(wait_error)
212
+ retry
213
+ end
213
214
 
214
- return bytes
215
+ def io_select(exception)
216
+ readers, writers = nil, nil
217
+ readers = [socket] if exception.is_a?(IO::WaitReadable)
218
+ writers = [socket] if exception.is_a?(IO::WaitWritable)
219
+ if IO.select(readers, writers, nil, @options[:read_timeout]).nil?
220
+ close
221
+ raise Vertica::Error::TimedOutError.new("Connection timed out.")
222
+ end
215
223
  end
216
224
 
217
225
  def startup_connection
218
- write Vertica::Messages::Startup.new(@options[:user] || @options[:username], @options[:database])
226
+ write_message Vertica::Messages::Startup.new(@options[:user] || @options[:username], @options[:database])
219
227
  message = nil
220
228
  begin
221
229
  case message = read_message
222
230
  when Vertica::Messages::Authentication
223
231
  if message.code != Vertica::Messages::Authentication::OK
224
- write Vertica::Messages::Password.new(@options[:password], message.code, {:user => @options[:user], :salt => message.salt})
232
+ write_message Vertica::Messages::Password.new(@options[:password], message.code, {:user => @options[:user], :salt => message.salt})
225
233
  end
226
234
  else
227
235
  process_message(message)
data/lib/vertica/query.rb CHANGED
@@ -15,7 +15,7 @@ class Vertica::Query
15
15
  end
16
16
 
17
17
  def run
18
- @connection.write Vertica::Messages::Query.new(sql)
18
+ @connection.write_message Vertica::Messages::Query.new(sql)
19
19
 
20
20
  begin
21
21
  process_message(message = @connection.read_message)
@@ -26,7 +26,7 @@ class Vertica::Query
26
26
  end
27
27
 
28
28
  def write(data)
29
- @connection.write Vertica::Messages::CopyData.new(data)
29
+ @connection.write_message Vertica::Messages::CopyData.new(data)
30
30
  return self
31
31
  end
32
32
 
@@ -59,16 +59,16 @@ class Vertica::Query
59
59
 
60
60
  def handle_copy_from_stdin
61
61
  if copy_handler.nil?
62
- @connection.write Vertica::Messages::CopyFail.new('no handler provided')
62
+ @connection.write_message Vertica::Messages::CopyFail.new('no handler provided')
63
63
  else
64
64
  begin
65
65
  if copy_handler.call(self) == :rollback
66
- @connection.write Vertica::Messages::CopyFail.new("rollback")
66
+ @connection.write_message Vertica::Messages::CopyFail.new("rollback")
67
67
  else
68
- @connection.write Vertica::Messages::CopyDone.new
68
+ @connection.write_message Vertica::Messages::CopyDone.new
69
69
  end
70
70
  rescue => e
71
- @connection.write Vertica::Messages::CopyFail.new(e.message)
71
+ @connection.write_message Vertica::Messages::CopyFail.new(e.message)
72
72
  raise
73
73
  end
74
74
  end
@@ -95,7 +95,7 @@ class ConnectionTest < Test::Unit::TestCase
95
95
  def test_socket_write_error
96
96
  connection = Vertica::Connection.new(TEST_CONNECTION_HASH)
97
97
  class << connection.socket
98
- def write(foo)
98
+ def write_nonblock(foo)
99
99
  raise Errno::ETIMEDOUT
100
100
  end
101
101
  end
@@ -107,7 +107,7 @@ class ConnectionTest < Test::Unit::TestCase
107
107
  def test_socket_read_error
108
108
  connection = Vertica::Connection.new(TEST_CONNECTION_HASH)
109
109
  class << connection.socket
110
- def read(foo)
110
+ def read_nonblock(foo)
111
111
  raise Errno::ETIMEDOUT
112
112
  end
113
113
  end
@@ -1,4 +1,5 @@
1
1
  require 'test_helper'
2
+ require 'zlib'
2
3
 
3
4
  class QueryTest < Test::Unit::TestCase
4
5
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vertica
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.2
4
+ version: 0.10.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2013-06-03 00:00:00.000000000 Z
14
+ date: 2013-08-07 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rake
@@ -119,9 +119,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
119
119
  - - ! '>='
120
120
  - !ruby/object:Gem::Version
121
121
  version: '0'
122
- segments:
123
- - 0
124
- hash: -2608349904200928087
125
122
  required_rubygems_version: !ruby/object:Gem::Requirement
126
123
  none: false
127
124
  requirements:
@@ -130,7 +127,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
130
127
  version: '0'
131
128
  requirements: []
132
129
  rubyforge_project:
133
- rubygems_version: 1.8.25
130
+ rubygems_version: 1.8.23
134
131
  signing_key:
135
132
  specification_version: 3
136
133
  summary: Pure ruby library for interacting with Vertica