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 +4 -4
- data/ffi/bolt/status.rb +10 -0
- data/ffi/neo4j/driver/internal/driver_factory.rb +5 -3
- data/ffi/neo4j/driver/internal/error_handling.rb +32 -12
- data/ffi/neo4j/driver/internal/explicit_transaction.rb +1 -0
- data/ffi/neo4j/driver/internal/retry/exponential_backoff_retry_logic.rb +7 -7
- data/lib/neo4j/driver/internal/duration_normalizer.rb +4 -0
- data/lib/neo4j/driver/version.rb +1 -1
- data/lib/neo4j_ruby_driver.rb +1 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d120aee905184fbdec88e8492508aaf5ca5ab442e584d80d7047370b8d9b38f8
|
4
|
+
data.tar.gz: f029e5705dbdc89b2ed0f27e224f4711a6ddbdf5c9968925a0a7fe0e8cd164e1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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,
|
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,
|
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
|
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]
|
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(
|
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
|
39
|
+
unqualified_error(error_code, status)
|
37
40
|
else
|
38
|
-
unqualified_error(error_code, status
|
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
|
78
|
-
|
79
|
-
throw
|
80
|
-
|
81
|
-
|
82
|
-
|
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
|
@@ -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
|
-
|
23
|
-
|
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
|
32
|
-
sleep(delay_with_jitter)
|
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
|
-
|
35
|
+
retry
|
36
36
|
end
|
37
37
|
end
|
38
38
|
add_suppressed(error, errors)
|
data/lib/neo4j/driver/version.rb
CHANGED
data/lib/neo4j_ruby_driver.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2020-01-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|