riak-client 2.4.1 → 2.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.document +5 -5
- data/.gitignore +3 -0
- data/Gemfile +17 -17
- data/Guardfile +20 -20
- data/LICENSE.md +16 -16
- data/RELNOTES.md +4 -0
- data/Rakefile +6 -1
- data/lib/riak/client/beefcake/crdt/counter_loader.rb +18 -18
- data/lib/riak/client/beefcake/crdt/hyper_log_log_loader.rb +18 -0
- data/lib/riak/client/beefcake/crdt/map_loader.rb +64 -64
- data/lib/riak/client/beefcake/crdt_loader.rb +4 -1
- data/lib/riak/client/beefcake/crdt_operator.rb +13 -0
- data/lib/riak/client/beefcake/footer +4 -4
- data/lib/riak/client/beefcake/header +6 -6
- data/lib/riak/client/beefcake/messages.rb +67 -10
- data/lib/riak/client/decaying.rb +36 -36
- data/lib/riak/client/feature_detection.rb +120 -120
- data/lib/riak/client/instrumentation.rb +19 -19
- data/lib/riak/client/node.rb +49 -49
- data/lib/riak/client/search.rb +27 -27
- data/lib/riak/conflict.rb +13 -13
- data/lib/riak/core_ext.rb +7 -7
- data/lib/riak/core_ext/blank.rb +53 -53
- data/lib/riak/core_ext/extract_options.rb +7 -7
- data/lib/riak/core_ext/json.rb +15 -15
- data/lib/riak/core_ext/slice.rb +18 -18
- data/lib/riak/core_ext/stringify_keys.rb +10 -10
- data/lib/riak/core_ext/symbolize_keys.rb +10 -10
- data/lib/riak/core_ext/to_param.rb +31 -31
- data/lib/riak/crdt.rb +23 -21
- data/lib/riak/crdt/base.rb +1 -1
- data/lib/riak/crdt/hyper_log_log.rb +97 -0
- data/lib/riak/crdt/operation.rb +19 -19
- data/lib/riak/encoding.rb +6 -6
- data/lib/riak/errors/backend_creation.rb +9 -9
- data/lib/riak/errors/connection_error.rb +50 -50
- data/lib/riak/errors/protobuffs_error.rb +11 -11
- data/lib/riak/i18n.rb +7 -7
- data/lib/riak/instrumentation.rb +6 -6
- data/lib/riak/json.rb +52 -52
- data/lib/riak/list_buckets.rb +28 -28
- data/lib/riak/locale/en.yml +1 -0
- data/lib/riak/locale/fr.yml +51 -51
- data/lib/riak/map_reduce/results.rb +49 -49
- data/lib/riak/map_reduce_error.rb +7 -7
- data/lib/riak/multiget.rb +122 -122
- data/lib/riak/robject.rb +17 -1
- data/lib/riak/search/result_document.rb +9 -0
- data/lib/riak/stamp.rb +77 -77
- data/lib/riak/tombstone.rb +13 -0
- data/lib/riak/util/tcp_socket_extensions.rb +58 -58
- data/lib/riak/version.rb +1 -1
- data/spec/failover/failover.rb +59 -59
- data/spec/fixtures/bitcask.txt +25 -25
- data/spec/fixtures/multipart-basic-conflict.txt +15 -15
- data/spec/fixtures/multipart-blank.txt +7 -7
- data/spec/fixtures/multipart-mapreduce.txt +10 -10
- data/spec/fixtures/multipart-with-body.txt +16 -16
- data/spec/fixtures/multipart-with-marked-tombstones.txt +17 -17
- data/spec/fixtures/multipart-with-unmarked-tombstone.txt +16 -16
- data/spec/fixtures/server.cert.crt +15 -15
- data/spec/fixtures/server.cert.key +15 -15
- data/spec/fixtures/test.pem +1 -1
- data/spec/integration/riak/bucket_types_spec.rb +38 -0
- data/spec/integration/riak/crdt/configuration_spec.rb +4 -3
- data/spec/integration/riak/crdt_spec.rb +70 -0
- data/spec/integration/riak/encodings/crdt_spec.rb +29 -3
- data/spec/integration/riak/encodings/yz_spec.rb +2 -1
- data/spec/integration/riak/preflist_spec.rb +15 -3
- data/spec/integration/riak/protobuffs/timeouts_spec.rb +1 -1
- data/spec/integration/riak/security_spec.rb +11 -6
- data/spec/integration/riak/threading_spec.rb +154 -150
- data/spec/integration/yokozuna/index_spec.rb +61 -61
- data/spec/integration/yokozuna/queries_spec.rb +1 -1
- data/spec/integration/yokozuna/schema_spec.rb +49 -49
- data/spec/riak/beefcake_protobuffs_backend/crdt_operator_spec.rb +22 -0
- data/spec/riak/core_ext/to_param_spec.rb +15 -15
- data/spec/riak/crdt/hyper_log_log_spec.rb +56 -0
- data/spec/riak/crdt/inner_counter_spec.rb +21 -21
- data/spec/riak/crdt/inner_set_spec.rb +33 -33
- data/spec/riak/crdt/set_spec.rb +61 -61
- data/spec/riak/crdt/shared_examples.rb +14 -0
- data/spec/riak/escape_spec.rb +72 -72
- data/spec/riak/feature_detection_spec.rb +77 -77
- data/spec/riak/index_collection_spec.rb +53 -53
- data/spec/riak/instrumentation_spec.rb +124 -124
- data/spec/riak/link_spec.rb +85 -85
- data/spec/riak/list_buckets_spec.rb +41 -41
- data/spec/riak/node_spec.rb +26 -26
- data/spec/riak/robject_spec.rb +45 -0
- data/spec/support/certs/README.md +12 -12
- data/spec/support/certs/ca.crt +21 -21
- data/spec/support/certs/client.crl +13 -13
- data/spec/support/certs/client.crt +94 -94
- data/spec/support/certs/client.csr +18 -18
- data/spec/support/certs/client.key +27 -27
- data/spec/support/certs/empty_ca.crt +21 -21
- data/spec/support/certs/server.crl +13 -13
- data/spec/support/certs/server.crt +94 -94
- data/spec/support/certs/server.key +27 -27
- data/spec/support/crdt_search_fixtures.rb +1 -1
- data/spec/support/integration_setup.rb +10 -10
- data/spec/support/test_client.rb +1 -1
- data/spec/support/test_client.yml.example +10 -10
- metadata +10 -3
data/lib/riak/client/decaying.rb
CHANGED
@@ -1,36 +1,36 @@
|
|
1
|
-
module Riak
|
2
|
-
class Client
|
3
|
-
# A float value which decays exponentially toward 0 over time.
|
4
|
-
# @private
|
5
|
-
class Decaying
|
6
|
-
attr_accessor :e
|
7
|
-
attr_accessor :p
|
8
|
-
|
9
|
-
# @param [Hash] opts options
|
10
|
-
# @option options [Float] :p (0.0) The initial value
|
11
|
-
# @option options [Float] :e (Math::E) Exponent base
|
12
|
-
# @option options [Float] :r (Math.log(0.5) / 10) Timescale
|
13
|
-
# factor - defaulting to decay 50% every 10 seconds
|
14
|
-
def initialize(opts = {})
|
15
|
-
@p = opts[:p] || 0.0
|
16
|
-
@e = opts[:e] || Math::E
|
17
|
-
@r = opts[:r] || Math.log(0.5) / 10
|
18
|
-
@t0 = Time.now
|
19
|
-
end
|
20
|
-
|
21
|
-
# Add to current value.
|
22
|
-
# @param [Float] d the value to add
|
23
|
-
def <<(d)
|
24
|
-
@p = value + d
|
25
|
-
end
|
26
|
-
|
27
|
-
# @return [Float] the current value (adjusted for the time decay)
|
28
|
-
def value
|
29
|
-
now = Time.now
|
30
|
-
dt = now - @t0
|
31
|
-
@t0 = now
|
32
|
-
@p = @p * (@e ** (@r * dt))
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
1
|
+
module Riak
|
2
|
+
class Client
|
3
|
+
# A float value which decays exponentially toward 0 over time.
|
4
|
+
# @private
|
5
|
+
class Decaying
|
6
|
+
attr_accessor :e
|
7
|
+
attr_accessor :p
|
8
|
+
|
9
|
+
# @param [Hash] opts options
|
10
|
+
# @option options [Float] :p (0.0) The initial value
|
11
|
+
# @option options [Float] :e (Math::E) Exponent base
|
12
|
+
# @option options [Float] :r (Math.log(0.5) / 10) Timescale
|
13
|
+
# factor - defaulting to decay 50% every 10 seconds
|
14
|
+
def initialize(opts = {})
|
15
|
+
@p = opts[:p] || 0.0
|
16
|
+
@e = opts[:e] || Math::E
|
17
|
+
@r = opts[:r] || Math.log(0.5) / 10
|
18
|
+
@t0 = Time.now
|
19
|
+
end
|
20
|
+
|
21
|
+
# Add to current value.
|
22
|
+
# @param [Float] d the value to add
|
23
|
+
def <<(d)
|
24
|
+
@p = value + d
|
25
|
+
end
|
26
|
+
|
27
|
+
# @return [Float] the current value (adjusted for the time decay)
|
28
|
+
def value
|
29
|
+
now = Time.now
|
30
|
+
dt = now - @t0
|
31
|
+
@t0 = now
|
32
|
+
@p = @p * (@e ** (@r * dt))
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -1,120 +1,120 @@
|
|
1
|
-
module Riak
|
2
|
-
class Client
|
3
|
-
# Methods that can be used to determine whether certain features
|
4
|
-
# are supported by the Riak node to which the client backend is
|
5
|
-
# connected.
|
6
|
-
#
|
7
|
-
# Backends must implement the "get_server_version" method,
|
8
|
-
# returning a string representing the Riak node's version. This is
|
9
|
-
# implemented on HTTP using the stats resource, and on Protocol
|
10
|
-
# Buffers using the RpbGetServerInfoReq message.
|
11
|
-
module FeatureDetection
|
12
|
-
# Constants representing Riak versions
|
13
|
-
VERSION = {
|
14
|
-
1 => Gem::Version.new("1.0.0"),
|
15
|
-
1.1 => Gem::Version.new("1.1.0"),
|
16
|
-
1.2 => Gem::Version.new("1.2.0"),
|
17
|
-
1.3 => Gem::Version.new("1.3.0"),
|
18
|
-
1.4 => Gem::Version.new("1.4.0")
|
19
|
-
}.freeze
|
20
|
-
|
21
|
-
# @return [String] the version of the Riak node
|
22
|
-
# @abstract
|
23
|
-
def get_server_version
|
24
|
-
raise NotImplementedError
|
25
|
-
end
|
26
|
-
|
27
|
-
# @return [Gem::Version] the version of the Riak node to which
|
28
|
-
# this backend is connected
|
29
|
-
def server_version
|
30
|
-
@server_version ||= Gem::Version.new(get_server_version.split("-").first)
|
31
|
-
end
|
32
|
-
|
33
|
-
# @return [true,false] whether MapReduce requests can be submitted without
|
34
|
-
# phases.
|
35
|
-
def mapred_phaseless?
|
36
|
-
at_least? VERSION[1.1]
|
37
|
-
end
|
38
|
-
|
39
|
-
# @return [true,false] whether secondary index queries are
|
40
|
-
# supported over Protocol Buffers
|
41
|
-
def pb_indexes?
|
42
|
-
at_least? VERSION[1.2]
|
43
|
-
end
|
44
|
-
|
45
|
-
# @return [true,false] whether search queries are supported over
|
46
|
-
# Protocol Buffers
|
47
|
-
def pb_search?
|
48
|
-
at_least? VERSION[1.2]
|
49
|
-
end
|
50
|
-
|
51
|
-
# @return [true,false] whether conditional fetch/store semantics
|
52
|
-
# are supported over Protocol Buffers
|
53
|
-
def pb_conditionals?
|
54
|
-
at_least? VERSION[1]
|
55
|
-
end
|
56
|
-
|
57
|
-
# @return [true,false] whether additional quorums and FSM
|
58
|
-
# controls are available, e.g. primary quorums, basic_quorum,
|
59
|
-
# notfound_ok
|
60
|
-
def quorum_controls?
|
61
|
-
at_least? VERSION[1]
|
62
|
-
end
|
63
|
-
|
64
|
-
# @return [true,false] whether "not found" responses might
|
65
|
-
# include vclocks
|
66
|
-
def tombstone_vclocks?
|
67
|
-
at_least? VERSION[1]
|
68
|
-
end
|
69
|
-
|
70
|
-
# @return [true,false] whether partial-fetches (vclock and
|
71
|
-
# metadata only) are supported over Protocol Buffers
|
72
|
-
def pb_head?
|
73
|
-
at_least? VERSION[1]
|
74
|
-
end
|
75
|
-
|
76
|
-
# @return [true,false] whether bucket properties can be cleared
|
77
|
-
# (reset to defaults) over HTTP
|
78
|
-
def http_props_clearable?
|
79
|
-
at_least? VERSION[1.3]
|
80
|
-
end
|
81
|
-
|
82
|
-
# @return [true,false] whether secondary indexes support
|
83
|
-
# pagination
|
84
|
-
def index_pagination?
|
85
|
-
at_least? VERSION[1.4]
|
86
|
-
end
|
87
|
-
|
88
|
-
# @return [true,false] whether secondary indexes support
|
89
|
-
# return_terms
|
90
|
-
def index_return_terms?
|
91
|
-
at_least? VERSION[1.4]
|
92
|
-
end
|
93
|
-
|
94
|
-
# @return [true,false] whether secondary indexes support
|
95
|
-
# streaming
|
96
|
-
def index_streaming?
|
97
|
-
at_least? VERSION[1.4]
|
98
|
-
end
|
99
|
-
|
100
|
-
# @return [true,false] whether timeouts are accepted for
|
101
|
-
# object CRUD, key listing, and bucket listing
|
102
|
-
def key_object_bucket_timeouts?
|
103
|
-
at_least? VERSION[1.4]
|
104
|
-
end
|
105
|
-
|
106
|
-
protected
|
107
|
-
# @return [true,false] whether the server version is the same or
|
108
|
-
# newer than the requested version
|
109
|
-
def at_least?(version)
|
110
|
-
server_version >= version
|
111
|
-
end
|
112
|
-
|
113
|
-
# Backends should call this when their connection is interrupted
|
114
|
-
# or reset so as to facilitate rolling upgrades
|
115
|
-
def reset_server_version
|
116
|
-
@server_version = nil
|
117
|
-
end
|
118
|
-
end
|
119
|
-
end
|
120
|
-
end
|
1
|
+
module Riak
|
2
|
+
class Client
|
3
|
+
# Methods that can be used to determine whether certain features
|
4
|
+
# are supported by the Riak node to which the client backend is
|
5
|
+
# connected.
|
6
|
+
#
|
7
|
+
# Backends must implement the "get_server_version" method,
|
8
|
+
# returning a string representing the Riak node's version. This is
|
9
|
+
# implemented on HTTP using the stats resource, and on Protocol
|
10
|
+
# Buffers using the RpbGetServerInfoReq message.
|
11
|
+
module FeatureDetection
|
12
|
+
# Constants representing Riak versions
|
13
|
+
VERSION = {
|
14
|
+
1 => Gem::Version.new("1.0.0"),
|
15
|
+
1.1 => Gem::Version.new("1.1.0"),
|
16
|
+
1.2 => Gem::Version.new("1.2.0"),
|
17
|
+
1.3 => Gem::Version.new("1.3.0"),
|
18
|
+
1.4 => Gem::Version.new("1.4.0")
|
19
|
+
}.freeze
|
20
|
+
|
21
|
+
# @return [String] the version of the Riak node
|
22
|
+
# @abstract
|
23
|
+
def get_server_version
|
24
|
+
raise NotImplementedError
|
25
|
+
end
|
26
|
+
|
27
|
+
# @return [Gem::Version] the version of the Riak node to which
|
28
|
+
# this backend is connected
|
29
|
+
def server_version
|
30
|
+
@server_version ||= Gem::Version.new(get_server_version.split("-").first)
|
31
|
+
end
|
32
|
+
|
33
|
+
# @return [true,false] whether MapReduce requests can be submitted without
|
34
|
+
# phases.
|
35
|
+
def mapred_phaseless?
|
36
|
+
at_least? VERSION[1.1]
|
37
|
+
end
|
38
|
+
|
39
|
+
# @return [true,false] whether secondary index queries are
|
40
|
+
# supported over Protocol Buffers
|
41
|
+
def pb_indexes?
|
42
|
+
at_least? VERSION[1.2]
|
43
|
+
end
|
44
|
+
|
45
|
+
# @return [true,false] whether search queries are supported over
|
46
|
+
# Protocol Buffers
|
47
|
+
def pb_search?
|
48
|
+
at_least? VERSION[1.2]
|
49
|
+
end
|
50
|
+
|
51
|
+
# @return [true,false] whether conditional fetch/store semantics
|
52
|
+
# are supported over Protocol Buffers
|
53
|
+
def pb_conditionals?
|
54
|
+
at_least? VERSION[1]
|
55
|
+
end
|
56
|
+
|
57
|
+
# @return [true,false] whether additional quorums and FSM
|
58
|
+
# controls are available, e.g. primary quorums, basic_quorum,
|
59
|
+
# notfound_ok
|
60
|
+
def quorum_controls?
|
61
|
+
at_least? VERSION[1]
|
62
|
+
end
|
63
|
+
|
64
|
+
# @return [true,false] whether "not found" responses might
|
65
|
+
# include vclocks
|
66
|
+
def tombstone_vclocks?
|
67
|
+
at_least? VERSION[1]
|
68
|
+
end
|
69
|
+
|
70
|
+
# @return [true,false] whether partial-fetches (vclock and
|
71
|
+
# metadata only) are supported over Protocol Buffers
|
72
|
+
def pb_head?
|
73
|
+
at_least? VERSION[1]
|
74
|
+
end
|
75
|
+
|
76
|
+
# @return [true,false] whether bucket properties can be cleared
|
77
|
+
# (reset to defaults) over HTTP
|
78
|
+
def http_props_clearable?
|
79
|
+
at_least? VERSION[1.3]
|
80
|
+
end
|
81
|
+
|
82
|
+
# @return [true,false] whether secondary indexes support
|
83
|
+
# pagination
|
84
|
+
def index_pagination?
|
85
|
+
at_least? VERSION[1.4]
|
86
|
+
end
|
87
|
+
|
88
|
+
# @return [true,false] whether secondary indexes support
|
89
|
+
# return_terms
|
90
|
+
def index_return_terms?
|
91
|
+
at_least? VERSION[1.4]
|
92
|
+
end
|
93
|
+
|
94
|
+
# @return [true,false] whether secondary indexes support
|
95
|
+
# streaming
|
96
|
+
def index_streaming?
|
97
|
+
at_least? VERSION[1.4]
|
98
|
+
end
|
99
|
+
|
100
|
+
# @return [true,false] whether timeouts are accepted for
|
101
|
+
# object CRUD, key listing, and bucket listing
|
102
|
+
def key_object_bucket_timeouts?
|
103
|
+
at_least? VERSION[1.4]
|
104
|
+
end
|
105
|
+
|
106
|
+
protected
|
107
|
+
# @return [true,false] whether the server version is the same or
|
108
|
+
# newer than the requested version
|
109
|
+
def at_least?(version)
|
110
|
+
server_version >= version
|
111
|
+
end
|
112
|
+
|
113
|
+
# Backends should call this when their connection is interrupted
|
114
|
+
# or reset so as to facilitate rolling upgrades
|
115
|
+
def reset_server_version
|
116
|
+
@server_version = nil
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
@@ -1,19 +1,19 @@
|
|
1
|
-
class Riak::Client
|
2
|
-
include Instrumentable
|
3
|
-
|
4
|
-
client_payload = {client_id: :client_id}
|
5
|
-
|
6
|
-
instrument_method :buckets, 'riak.list_buckets', client_payload
|
7
|
-
instrument_method :list_buckets, 'riak.list_buckets', client_payload
|
8
|
-
instrument_method :list_keys, 'riak.list_keys', client_payload
|
9
|
-
instrument_method :set_bucket_props, 'riak.set_bucket_props', client_payload
|
10
|
-
instrument_method :get_bucket_props, 'riak.get_bucket_props', client_payload
|
11
|
-
instrument_method :clear_bucket_props, 'riak.clear_bucket_props', client_payload
|
12
|
-
instrument_method :get_index, 'riak.get_index', client_payload
|
13
|
-
instrument_method :store_object, 'riak.store_object', client_payload
|
14
|
-
instrument_method :get_object, 'riak.get_object', client_payload
|
15
|
-
instrument_method :reload_object, 'riak.reload_object', client_payload
|
16
|
-
instrument_method :delete_object, 'riak.delete_object', client_payload
|
17
|
-
instrument_method :mapred, 'riak.map_reduce', client_payload
|
18
|
-
instrument_method :ping, 'riak.ping', client_payload
|
19
|
-
end
|
1
|
+
class Riak::Client
|
2
|
+
include Instrumentable
|
3
|
+
|
4
|
+
client_payload = {client_id: :client_id}
|
5
|
+
|
6
|
+
instrument_method :buckets, 'riak.list_buckets', client_payload
|
7
|
+
instrument_method :list_buckets, 'riak.list_buckets', client_payload
|
8
|
+
instrument_method :list_keys, 'riak.list_keys', client_payload
|
9
|
+
instrument_method :set_bucket_props, 'riak.set_bucket_props', client_payload
|
10
|
+
instrument_method :get_bucket_props, 'riak.get_bucket_props', client_payload
|
11
|
+
instrument_method :clear_bucket_props, 'riak.clear_bucket_props', client_payload
|
12
|
+
instrument_method :get_index, 'riak.get_index', client_payload
|
13
|
+
instrument_method :store_object, 'riak.store_object', client_payload
|
14
|
+
instrument_method :get_object, 'riak.get_object', client_payload
|
15
|
+
instrument_method :reload_object, 'riak.reload_object', client_payload
|
16
|
+
instrument_method :delete_object, 'riak.delete_object', client_payload
|
17
|
+
instrument_method :mapred, 'riak.map_reduce', client_payload
|
18
|
+
instrument_method :ping, 'riak.ping', client_payload
|
19
|
+
end
|
data/lib/riak/client/node.rb
CHANGED
@@ -1,49 +1,49 @@
|
|
1
|
-
module Riak
|
2
|
-
class Client
|
3
|
-
class Node
|
4
|
-
# Represents a single riak node in a cluster.
|
5
|
-
|
6
|
-
include Util::Translation
|
7
|
-
include Util::Escape
|
8
|
-
|
9
|
-
VALID_OPTIONS = [:host, :pb_port]
|
10
|
-
|
11
|
-
# For a score which halves in 10 seconds, choose
|
12
|
-
# ln(1/2)/10
|
13
|
-
ERRORS_DECAY_RATE = Math.log(0.5)/10
|
14
|
-
|
15
|
-
# What IP address or hostname does this node listen on?
|
16
|
-
attr_accessor :host
|
17
|
-
|
18
|
-
# Which port does the protocol buffers interface listen on?
|
19
|
-
attr_accessor :pb_port
|
20
|
-
|
21
|
-
# A Decaying rate of errors.
|
22
|
-
attr_reader :error_rate
|
23
|
-
|
24
|
-
def initialize(client, opts = {})
|
25
|
-
@client = client
|
26
|
-
@host = opts[:host] || "127.0.0.1"
|
27
|
-
@pb_port = opts[:pb_port] || 8087
|
28
|
-
|
29
|
-
@error_rate = Decaying.new
|
30
|
-
end
|
31
|
-
|
32
|
-
def ==(o)
|
33
|
-
o.kind_of? Node and
|
34
|
-
@host == o.host and
|
35
|
-
@pb_port == o.pb_port
|
36
|
-
end
|
37
|
-
|
38
|
-
# Can this node be used for protocol buffers requests?
|
39
|
-
def protobuffs?
|
40
|
-
# TODO: Need to sort out capabilities
|
41
|
-
true
|
42
|
-
end
|
43
|
-
|
44
|
-
def inspect
|
45
|
-
"#<Node #{@host}:#{@pb_port}>"
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
1
|
+
module Riak
|
2
|
+
class Client
|
3
|
+
class Node
|
4
|
+
# Represents a single riak node in a cluster.
|
5
|
+
|
6
|
+
include Util::Translation
|
7
|
+
include Util::Escape
|
8
|
+
|
9
|
+
VALID_OPTIONS = [:host, :pb_port]
|
10
|
+
|
11
|
+
# For a score which halves in 10 seconds, choose
|
12
|
+
# ln(1/2)/10
|
13
|
+
ERRORS_DECAY_RATE = Math.log(0.5)/10
|
14
|
+
|
15
|
+
# What IP address or hostname does this node listen on?
|
16
|
+
attr_accessor :host
|
17
|
+
|
18
|
+
# Which port does the protocol buffers interface listen on?
|
19
|
+
attr_accessor :pb_port
|
20
|
+
|
21
|
+
# A Decaying rate of errors.
|
22
|
+
attr_reader :error_rate
|
23
|
+
|
24
|
+
def initialize(client, opts = {})
|
25
|
+
@client = client
|
26
|
+
@host = opts[:host] || "127.0.0.1"
|
27
|
+
@pb_port = opts[:pb_port] || 8087
|
28
|
+
|
29
|
+
@error_rate = Decaying.new
|
30
|
+
end
|
31
|
+
|
32
|
+
def ==(o)
|
33
|
+
o.kind_of? Node and
|
34
|
+
@host == o.host and
|
35
|
+
@pb_port == o.pb_port
|
36
|
+
end
|
37
|
+
|
38
|
+
# Can this node be used for protocol buffers requests?
|
39
|
+
def protobuffs?
|
40
|
+
# TODO: Need to sort out capabilities
|
41
|
+
true
|
42
|
+
end
|
43
|
+
|
44
|
+
def inspect
|
45
|
+
"#<Node #{@host}:#{@pb_port}>"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|