neo4j-ruby-driver 0.1.11 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ac7628f26dea26f54328c47736001a148b7b864771b50036b659f7f4d92ffa50
|
4
|
+
data.tar.gz: 318537bb1949cb5f917b0f34183edbffc9ff1927239d7a3d8180ea07fdb97924
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 03a0ed4e03c81c7ba6d3804adf329c8a44cf3a1a13437b2f147ca398789300b4736cfca683d1b928fb709351464e4d1cd930d89acf439efab8ac19d750dd75b0
|
7
|
+
data.tar.gz: acff913f890a863009fe45ac24ca63ed56fd89414ba81183e5740fcbc77e2e3b10f9b0f444113f8f38ea615f43ecde81eb7813ebfc67aa6ce080a6d5fe3d6407
|
data/ffi/bolt/config.rb
CHANGED
@@ -3,6 +3,9 @@
|
|
3
3
|
module Neo4j
|
4
4
|
module Driver
|
5
5
|
class GraphDatabase
|
6
|
+
VALID_ROUTING_SCHEMES =
|
7
|
+
[Internal::DriverFactory::BOLT_ROUTING_URI_SCHEME, Internal::DriverFactory::NEO4J_URI_SCHEME].freeze
|
8
|
+
|
6
9
|
Bolt::Lifecycle.startup
|
7
10
|
|
8
11
|
at_exit do
|
@@ -12,17 +15,36 @@ module Neo4j
|
|
12
15
|
class << self
|
13
16
|
extend AutoClosable
|
14
17
|
|
15
|
-
auto_closable :driver
|
18
|
+
auto_closable :driver, :routing_driver
|
16
19
|
|
17
20
|
def driver(uri, auth_token = Neo4j::Driver::AuthTokens.none, config = nil)
|
18
|
-
|
21
|
+
unless auth_token.is_a? FFI::Pointer
|
22
|
+
raise Exceptions::AuthenticationException, 'Unsupported authentication token'
|
23
|
+
end
|
19
24
|
config ||= Config.default_config
|
20
|
-
# routing_settings = config.routing_settings
|
21
|
-
# retry_settings = config.retry_settings
|
22
|
-
routing_settings = nil
|
23
|
-
retry_settings = nil
|
24
25
|
|
25
|
-
Internal::DriverFactory.new.new_instance(uri, auth_token,
|
26
|
+
Internal::DriverFactory.new.new_instance(uri, auth_token, config)
|
27
|
+
end
|
28
|
+
|
29
|
+
def routing_driver(routing_uris, auth_toke, config)
|
30
|
+
assert_routing_uris(routing_uris)
|
31
|
+
|
32
|
+
routing_uris.each do |uri|
|
33
|
+
return driver(uri, auth_toke, config)
|
34
|
+
rescue Exceptions::ServiceUnavailableException => e
|
35
|
+
# log.warn("Unable to create routing driver for URI: #{uri}", e)
|
36
|
+
end
|
37
|
+
|
38
|
+
raise Exceptions::ServiceUnavailableException, 'Failed to discover an available server'
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def assert_routing_uris(uris)
|
44
|
+
scheme = (uris.map(&method(:URI)).map(&:scheme) - VALID_ROUTING_SCHEMES).first
|
45
|
+
return unless scheme
|
46
|
+
raise ArgumentError,
|
47
|
+
"Illegal URI scheme, expected URI scheme '#{scheme}' to be among [#{VALID_ROUTING_SCHEMES.join ', '}]"
|
26
48
|
end
|
27
49
|
end
|
28
50
|
end
|
@@ -10,20 +10,23 @@ module Neo4j
|
|
10
10
|
NEO4J_URI_SCHEME = 'neo4j'
|
11
11
|
DEFAULT_PORT = 7687
|
12
12
|
|
13
|
-
def new_instance(uri, auth_token,
|
13
|
+
def new_instance(uri, auth_token, config)
|
14
14
|
uri = URI(uri)
|
15
|
-
|
15
|
+
routing_context = routing_context(uri)
|
16
|
+
connector, logger = create_connector(uri, auth_token, routing_context, config)
|
16
17
|
retry_logic = Retry::ExponentialBackoffRetryLogic.new(config[:max_transaction_retry_time], config[:logger])
|
17
|
-
create_driver(
|
18
|
+
create_driver(connector, logger, retry_logic, config).tap(&:verify_connectivity)
|
18
19
|
end
|
19
20
|
|
20
21
|
private
|
21
22
|
|
22
|
-
def create_connector(uri, auth_token, config)
|
23
|
+
def create_connector(uri, auth_token, routing_context, config)
|
23
24
|
address = Bolt::Address.create(host(uri).gsub(/^\[(.*)\]$/, '\\1'), port(uri).to_s)
|
24
25
|
bolt_config = bolt_config(config)
|
25
26
|
logger = InternalLogger.register(bolt_config, config[:logger])
|
26
27
|
set_socket_options(bolt_config, config)
|
28
|
+
set_routing_context(bolt_config, routing_context)
|
29
|
+
set_scheme(bolt_config, uri, routing_context)
|
27
30
|
[Bolt::Connector.create(address, auth_token, bolt_config), logger]
|
28
31
|
end
|
29
32
|
|
@@ -54,6 +57,17 @@ module Neo4j
|
|
54
57
|
check_error Bolt::Config.set_socket_options(bolt_config, socket_options) if socket_options
|
55
58
|
end
|
56
59
|
|
60
|
+
def routing_context(uri)
|
61
|
+
query = uri.query
|
62
|
+
return if query.blank?
|
63
|
+
URI.decode_www_form(query).to_h
|
64
|
+
end
|
65
|
+
|
66
|
+
def set_routing_context(bolt_config, routing_context)
|
67
|
+
value = Bolt::Value.create
|
68
|
+
check_error Bolt::Config.set_routing_context(bolt_config, Value::ValueAdapter.to_neo(value, routing_context))
|
69
|
+
end
|
70
|
+
|
57
71
|
def host(uri)
|
58
72
|
uri.host.tap { |host| raise ArgumentError, "Invalid address format `#{uri}`" unless host }
|
59
73
|
end
|
@@ -63,20 +77,30 @@ module Neo4j
|
|
63
77
|
DEFAULT_PORT
|
64
78
|
end
|
65
79
|
|
66
|
-
def
|
80
|
+
def set_scheme(bolt_config, uri, routing_context)
|
81
|
+
check_error Bolt::Config.set_scheme(bolt_config, scheme(uri, routing_context))
|
82
|
+
end
|
83
|
+
|
84
|
+
def scheme(uri, routing_context)
|
85
|
+
scheme = uri.scheme
|
67
86
|
case scheme
|
68
87
|
when BOLT_URI_SCHEME
|
69
|
-
|
70
|
-
|
71
|
-
create_direct_driver(connector, logger, retry_logic, config)
|
88
|
+
assert_no_routing_context(uri, routing_context)
|
89
|
+
Bolt::Config::BOLT_SCHEME_DIRECT
|
72
90
|
when BOLT_ROUTING_URI_SCHEME, NEO4J_URI_SCHEME
|
73
|
-
|
91
|
+
Bolt::Config::BOLT_SCHEME_NEO4J
|
74
92
|
else
|
75
93
|
raise Exceptions::ClientException, "Unsupported URI scheme: #{scheme}"
|
76
94
|
end
|
77
95
|
end
|
78
96
|
|
79
|
-
def
|
97
|
+
def assert_no_routing_context(uri, routing_context)
|
98
|
+
if routing_context
|
99
|
+
raise ArgumentError, "Routing parameters are not supported with scheme 'bolt'. Given URI: '#{uri}'"
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
def create_driver(connector, logger, retry_logic, config)
|
80
104
|
connection_provider = DirectConnectionProvider.new(connector, config)
|
81
105
|
session_factory = create_session_factory(connection_provider, retry_logic, config)
|
82
106
|
InternalDriver.new(session_factory, logger)
|
@@ -9,21 +9,29 @@ module Neo4j
|
|
9
9
|
# Identifies a successful operation which is defined as 0
|
10
10
|
when Bolt::Error::BOLT_SUCCESS # 0
|
11
11
|
nil
|
12
|
+
|
12
13
|
# Permission denied
|
13
14
|
when Bolt::Error::BOLT_PERMISSION_DENIED # 7
|
14
15
|
throw Exceptions::AuthenticationException.new(error_code, 'Permission denied')
|
16
|
+
|
15
17
|
# Connection refused
|
16
|
-
when Bolt::Error::BOLT_CONNECTION_REFUSED
|
18
|
+
when Bolt::Error::BOLT_CONNECTION_REFUSED # 11
|
17
19
|
throw Exceptions::ServiceUnavailableException.new(error_code, 'unable to acquire connection')
|
20
|
+
|
18
21
|
# Connection pool is full
|
19
|
-
when Bolt::Error::BOLT_POOL_FULL
|
22
|
+
when Bolt::Error::BOLT_POOL_FULL # 0x600
|
20
23
|
throw Exceptions::ClientException.new(
|
21
24
|
error_code,
|
22
25
|
'Unable to acquire connection from the pool within configured maximum time of ' \
|
23
26
|
"#{@config[:connection_acquisition_timeout] * 1000}ms"
|
24
27
|
)
|
28
|
+
|
29
|
+
# Routing table retrieval failed
|
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))
|
32
|
+
|
25
33
|
# Error set in connection
|
26
|
-
when Bolt::Error::BOLT_CONNECTION_HAS_MORE_INFO, Bolt::Error::BOLT_STATUS_SET
|
34
|
+
when Bolt::Error::BOLT_CONNECTION_HAS_MORE_INFO, Bolt::Error::BOLT_STATUS_SET # 0xFFE, 0xFFF
|
27
35
|
status = Bolt::Connection.status(bolt_connection)
|
28
36
|
unqualified_error(error_code, status, error_text)
|
29
37
|
else
|
@@ -71,7 +79,7 @@ module Neo4j
|
|
71
79
|
throw Exceptions::Neo4jException.new(
|
72
80
|
error_code,
|
73
81
|
"#{error_text || 'Unknown Bolt failure'} (code: #{error_code.to_s(16)}, " \
|
74
|
-
|
82
|
+
"text: #{Bolt::Error.get_string(error_code)}, context: #{error_ctx})"
|
75
83
|
)
|
76
84
|
end
|
77
85
|
end
|
data/lib/neo4j/driver/version.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.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Heinrich Klobuczek
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-01-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|