neo4j-ruby-driver 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ac7628f26dea26f54328c47736001a148b7b864771b50036b659f7f4d92ffa50
4
- data.tar.gz: 318537bb1949cb5f917b0f34183edbffc9ff1927239d7a3d8180ea07fdb97924
3
+ metadata.gz: d120aee905184fbdec88e8492508aaf5ca5ab442e584d80d7047370b8d9b38f8
4
+ data.tar.gz: f029e5705dbdc89b2ed0f27e224f4711a6ddbdf5c9968925a0a7fe0e8cd164e1
5
5
  SHA512:
6
- metadata.gz: 03a0ed4e03c81c7ba6d3804adf329c8a44cf3a1a13437b2f147ca398789300b4736cfca683d1b928fb709351464e4d1cd930d89acf439efab8ac19d750dd75b0
7
- data.tar.gz: acff913f890a863009fe45ac24ca63ed56fd89414ba81183e5740fcbc77e2e3b10f9b0f444113f8f38ea615f43ecde81eb7813ebfc67aa6ce080a6d5fe3d6407
6
+ metadata.gz: cb2ee849c0c8952ae992ba23b4068a750454772a49b8d891c81abf184c5f6440f4295a38b266e51fc466521c8dfcd1a722f84db16f50e29bd28a6c2fd0e411a0
7
+ data.tar.gz: 5efbeb6d55973470fa765bb6b46417f02c63713c4a2637847ff99bda193483b8751b6b7ca378b40a550cf25a0ea2cd0c39a4e459effc886a11d0fb746e3654c0
data/ffi/bolt/status.rb CHANGED
@@ -3,6 +3,16 @@
3
3
  module Bolt
4
4
  module Status
5
5
  extend Bolt::Library
6
+ # Not connected
7
+ BOLT_CONNECTION_STATE_DISCONNECTED = 0
8
+ # Connected but not authenticated
9
+ BOLT_CONNECTION_STATE_CONNECTED = 1
10
+ # Connected and authenticated
11
+ BOLT_CONNECTION_STATE_READY = 2
12
+ # Recoverable failure
13
+ BOLT_CONNECTION_STATE_FAILED = 3
14
+ # Unrecoverable failure
15
+ BOLT_CONNECTION_STATE_DEFUNCT = 4
6
16
 
7
17
  typedef :int32, :bolt_connection_state
8
18
 
@@ -37,9 +37,10 @@ module Neo4j
37
37
  when :max_connection_pool_size
38
38
  check_error Bolt::Config.set_max_pool_size(bolt_config, value)
39
39
  when :max_connection_life_time
40
- check_error Bolt::Config.set_max_connection_life_time(bolt_config, value)
40
+ check_error Bolt::Config.set_max_connection_life_time(bolt_config, DurationNormalizer.milliseconds(value))
41
41
  when :connection_acquisition_timeout
42
- check_error Bolt::Config.set_max_connection_acquisition_time(bolt_config, value)
42
+ check_error Bolt::Config.set_max_connection_acquisition_time(bolt_config,
43
+ DurationNormalizer.milliseconds(value))
43
44
  end
44
45
  end
45
46
  check_error Bolt::Config.set_user_agent(bolt_config, 'seabolt-cmake/1.7')
@@ -51,7 +52,8 @@ module Neo4j
51
52
  config.each do |key, value|
52
53
  case key
53
54
  when :connection_timeout
54
- check_error Bolt::SocketOptions.set_connect_timeout(socket_options ||= Bolt::SocketOptions.create, value)
55
+ check_error Bolt::SocketOptions.set_connect_timeout(socket_options ||= Bolt::SocketOptions.create,
56
+ DurationNormalizer.milliseconds(value))
55
57
  end
56
58
  end
57
59
  check_error Bolt::Config.set_socket_options(bolt_config, socket_options) if socket_options
@@ -4,7 +4,7 @@ module Neo4j
4
4
  module Driver
5
5
  module Internal
6
6
  module ErrorHandling
7
- def check_error(error_code, status = nil, error_text = nil)
7
+ def check_error(error_code, status = nil)
8
8
  case error_code
9
9
  # Identifies a successful operation which is defined as 0
10
10
  when Bolt::Error::BOLT_SUCCESS # 0
@@ -23,19 +23,22 @@ module Neo4j
23
23
  throw Exceptions::ClientException.new(
24
24
  error_code,
25
25
  'Unable to acquire connection from the pool within configured maximum time of ' \
26
- "#{@config[:connection_acquisition_timeout] * 1000}ms"
26
+ "#{DurationNormalizer.milliseconds(@config[:connection_acquisition_timeout])}ms"
27
27
  )
28
28
 
29
29
  # Routing table retrieval failed
30
30
  when Bolt::Error::BOLT_ROUTING_UNABLE_TO_RETRIEVE_ROUTING_TABLE # 0x800
31
- throw Exceptions::ServiceUnavailableException.new(error_code, Bolt::Error.get_string(error_code))
31
+ throw Exceptions::ServiceUnavailableException.new(
32
+ error_code,
33
+ 'Could not perform discovery. No routing servers available.'
34
+ )
32
35
 
33
36
  # Error set in connection
34
37
  when Bolt::Error::BOLT_CONNECTION_HAS_MORE_INFO, Bolt::Error::BOLT_STATUS_SET # 0xFFE, 0xFFF
35
38
  status = Bolt::Connection.status(bolt_connection)
36
- unqualified_error(error_code, status, error_text)
39
+ unqualified_error(error_code, status)
37
40
  else
38
- unqualified_error(error_code, status, error_text)
41
+ unqualified_error(error_code, status)
39
42
  end
40
43
  end
41
44
 
@@ -69,18 +72,35 @@ module Neo4j
69
72
 
70
73
  private
71
74
 
75
+ def exception_class(state)
76
+ case state
77
+ when Bolt::Status::BOLT_CONNECTION_STATE_DEFUNCT
78
+ Exceptions::SessionExpiredException
79
+ else
80
+ Exceptions::Neo4jException
81
+ end
82
+ end
83
+
72
84
  def throw(error)
73
85
  on_failure(error)
74
86
  raise error
75
87
  end
76
88
 
77
- def unqualified_error(error_code, status, error_text)
78
- error_ctx = status && Bolt::Status.get_error_context(status)
79
- throw Exceptions::Neo4jException.new(
80
- error_code,
81
- "#{error_text || 'Unknown Bolt failure'} (code: #{error_code.to_s(16)}, " \
82
- "text: #{Bolt::Error.get_string(error_code)}, context: #{error_ctx})"
83
- )
89
+ def unqualified_error(error_code, status)
90
+ details = details(error_code, status)
91
+ throw exception_class(details[:state]).new(error_code,
92
+ details.map { |key, value| "#{key}: `#{value}`" }.join(', '))
93
+ end
94
+
95
+ def details(error_code, status)
96
+ details = {
97
+ code: error_code.to_s(16),
98
+ error: Bolt::Error.get_string(error_code)
99
+ }
100
+ return details unless status
101
+ details.merge(state: Bolt::Status.get_state(status),
102
+ error: Bolt::Status.get_error(status),
103
+ error_context: Bolt::Status.get_error_context(status))
84
104
  end
85
105
  end
86
106
  end
@@ -17,6 +17,7 @@ module Neo4j
17
17
 
18
18
  def begin(initial_bookmarks, config)
19
19
  chain @protocol.begin_transaction(@connection, initial_bookmarks, config)
20
+ finalize if initial_bookmarks.present?
20
21
  self
21
22
  rescue StandardError => e
22
23
  @connection.release
@@ -5,8 +5,8 @@ module Neo4j
5
5
  module Internal
6
6
  module Retry
7
7
  class ExponentialBackoffRetryLogic
8
- DEFAULT_MAX_RETRY_TIME = 30
9
- INITIAL_RETRY_DELAY = 1
8
+ DEFAULT_MAX_RETRY_TIME = 30.seconds
9
+ INITIAL_RETRY_DELAY = 1.second
10
10
  RETRY_DELAY_MULTIPLIER = 2.0
11
11
  RETRY_DELAY_JITTER_FACTOR = 0.2
12
12
 
@@ -19,8 +19,8 @@ module Neo4j
19
19
  next_delay = INITIAL_RETRY_DELAY
20
20
  start_time = nil
21
21
  errors = nil
22
- loop do
23
- return yield
22
+ begin
23
+ yield
24
24
  rescue Exceptions::Neo4jException => error
25
25
  if can_retry_on?(error)
26
26
  curr_time = current_time
@@ -28,11 +28,11 @@ module Neo4j
28
28
  elapsed_time = curr_time - start_time
29
29
  if elapsed_time < @max_retry_time
30
30
  delay_with_jitter = compute_delay_with_jitter(next_delay)
31
- @log&.warn("Transaction failed and will be retried in #{delay_with_jitter}ms", error)
32
- sleep(delay_with_jitter) # verify time units
31
+ @log&.warn { "Transaction failed and will be retried in #{delay_with_jitter}ms\n#{error}" }
32
+ sleep(delay_with_jitter)
33
33
  next_delay *= RETRY_DELAY_MULTIPLIER
34
34
  (errors ||= []) << error
35
- next
35
+ retry
36
36
  end
37
37
  end
38
38
  add_suppressed(error, errors)
@@ -16,6 +16,10 @@ module Neo4j
16
16
  [months_i, days_i, seconds_i, nonanoseconds.round]
17
17
  end
18
18
 
19
+ def milliseconds(duration)
20
+ duration.in_milliseconds.round
21
+ end
22
+
19
23
  private
20
24
 
21
25
  def divmod(number, factor)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Neo4j
4
4
  module Driver
5
- VERSION = '0.2.0'
5
+ VERSION = '0.2.1'
6
6
  end
7
7
  end
@@ -14,6 +14,7 @@ end
14
14
  # End workaround
15
15
 
16
16
  require 'active_support/core_ext/hash/indifferent_access'
17
+ require 'active_support/core_ext/numeric/time'
17
18
  require 'active_support/duration'
18
19
  require 'active_support/time'
19
20
  require 'neo4j/driver'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: neo4j-ruby-driver
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Heinrich Klobuczek
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-01-07 00:00:00.000000000 Z
11
+ date: 2020-01-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport