vertica 0.10.5 → 0.11.0

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.5
1
+ 0.11.0
@@ -62,11 +62,11 @@ class Vertica::Connection
62
62
  end
63
63
 
64
64
  def busy?
65
- !ready_for_query?
65
+ @mutex.locked?
66
66
  end
67
67
 
68
68
  def ready_for_query?
69
- @current_job.nil?
69
+ !busy?
70
70
  end
71
71
 
72
72
  def write_message(message)
@@ -146,7 +146,7 @@ class Vertica::Connection
146
146
  @parameters[message.name] = message.value
147
147
  when Vertica::Messages::ReadyForQuery
148
148
  @transaction_status = message.transaction_status
149
- @current_job = nil
149
+ @mutex.unlock
150
150
  else
151
151
  raise Vertica::Error::MessageError, "Unhandled message: #{message.inspect}"
152
152
  end
@@ -155,7 +155,7 @@ class Vertica::Connection
155
155
  def query(sql, options = {}, &block)
156
156
  job = Vertica::Query.new(self, sql, { :row_style => @row_style }.merge(options))
157
157
  job.row_handler = block if block_given?
158
- run_with_job_lock(job)
158
+ run_with_mutex(job)
159
159
  end
160
160
 
161
161
  def copy(sql, source = nil, &block)
@@ -167,7 +167,7 @@ class Vertica::Connection
167
167
  elsif source.respond_to?(:read) && source.respond_to?(:eof?)
168
168
  job.copy_handler = lambda { |data| io_copy_handler(source, data) }
169
169
  end
170
- run_with_job_lock(job)
170
+ run_with_mutex(job)
171
171
  end
172
172
 
173
173
  def inspect
@@ -177,11 +177,13 @@ class Vertica::Connection
177
177
 
178
178
  protected
179
179
 
180
- def run_with_job_lock(job)
180
+ def run_with_mutex(job)
181
181
  boot_connection if closed?
182
- raise Vertica::Error::SynchronizeError.new(@current_job, job) if busy?
183
- @current_job = job
184
- job.run
182
+ if @mutex.try_lock
183
+ job.run
184
+ else
185
+ raise Vertica::Error::SynchronizeError.new(job)
186
+ end
185
187
  end
186
188
 
187
189
  COPY_FROM_IO_BLOCK_SIZE = 1024 * 4096
@@ -259,7 +261,7 @@ class Vertica::Connection
259
261
  @backend_key = nil
260
262
  @transaction_status = nil
261
263
  @socket = nil
262
- @current_job = '<initialization>'
264
+ @mutex = Mutex.new.lock
263
265
  end
264
266
  end
265
267
 
data/lib/vertica/error.rb CHANGED
@@ -11,9 +11,9 @@ class Vertica::Error < StandardError
11
11
  class SynchronizeError < Vertica::Error
12
12
  attr_reader :running_job, :requested_job
13
13
 
14
- def initialize(running_job, requested_job)
15
- @running_job, @requested_job = running_job, requested_job
16
- super("Cannot execute #{requested_job}, connection is in use for #{running_job}!")
14
+ def initialize(requested_job)
15
+ @requested_job = requested_job
16
+ super("Cannot execute #{requested_job}, connection is in use.")
17
17
  end
18
18
  end
19
19
 
@@ -115,4 +115,17 @@ class ConnectionTest < Test::Unit::TestCase
115
115
  assert_raises(Vertica::Error::ConnectionError) {connection.query('select 1')}
116
116
  assert connection.closed?
117
117
  end
118
+
119
+ def test_concurrent_access
120
+ connection = Vertica::Connection.new(TEST_CONNECTION_HASH)
121
+ t = Thread.new { connection.query("SELECT 1") }
122
+ sleep(0.01)
123
+
124
+ assert connection.busy?
125
+ assert_raises(Vertica::Error::SynchronizeError) { connection.query('SELECT 1') }
126
+
127
+ t.join
128
+ assert connection.ready_for_query?
129
+ connection.close
130
+ end
118
131
  end
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.5
4
+ version: 0.11.0
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-08-09 00:00:00.000000000 Z
14
+ date: 2013-08-28 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rake