aerospike 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +0 -0
- data/LICENSE +203 -0
- data/README.md +123 -0
- data/lib/aerospike.rb +69 -0
- data/lib/aerospike/aerospike_exception.rb +111 -0
- data/lib/aerospike/bin.rb +46 -0
- data/lib/aerospike/client.rb +649 -0
- data/lib/aerospike/cluster/cluster.rb +537 -0
- data/lib/aerospike/cluster/connection.rb +113 -0
- data/lib/aerospike/cluster/node.rb +248 -0
- data/lib/aerospike/cluster/node_validator.rb +85 -0
- data/lib/aerospike/cluster/partition.rb +54 -0
- data/lib/aerospike/cluster/partition_tokenizer_new.rb +128 -0
- data/lib/aerospike/cluster/partition_tokenizer_old.rb +135 -0
- data/lib/aerospike/command/batch_command.rb +120 -0
- data/lib/aerospike/command/batch_command_exists.rb +93 -0
- data/lib/aerospike/command/batch_command_get.rb +150 -0
- data/lib/aerospike/command/batch_item.rb +69 -0
- data/lib/aerospike/command/batch_node.rb +82 -0
- data/lib/aerospike/command/command.rb +680 -0
- data/lib/aerospike/command/delete_command.rb +57 -0
- data/lib/aerospike/command/execute_command.rb +42 -0
- data/lib/aerospike/command/exists_command.rb +57 -0
- data/lib/aerospike/command/field_type.rb +44 -0
- data/lib/aerospike/command/operate_command.rb +37 -0
- data/lib/aerospike/command/read_command.rb +174 -0
- data/lib/aerospike/command/read_header_command.rb +63 -0
- data/lib/aerospike/command/single_command.rb +60 -0
- data/lib/aerospike/command/touch_command.rb +50 -0
- data/lib/aerospike/command/write_command.rb +60 -0
- data/lib/aerospike/host.rb +43 -0
- data/lib/aerospike/info.rb +96 -0
- data/lib/aerospike/key.rb +99 -0
- data/lib/aerospike/language.rb +25 -0
- data/lib/aerospike/ldt/large.rb +69 -0
- data/lib/aerospike/ldt/large_list.rb +100 -0
- data/lib/aerospike/ldt/large_map.rb +82 -0
- data/lib/aerospike/ldt/large_set.rb +78 -0
- data/lib/aerospike/ldt/large_stack.rb +72 -0
- data/lib/aerospike/loggable.rb +55 -0
- data/lib/aerospike/operation.rb +70 -0
- data/lib/aerospike/policy/client_policy.rb +37 -0
- data/lib/aerospike/policy/generation_policy.rb +37 -0
- data/lib/aerospike/policy/policy.rb +54 -0
- data/lib/aerospike/policy/priority.rb +34 -0
- data/lib/aerospike/policy/record_exists_action.rb +45 -0
- data/lib/aerospike/policy/write_policy.rb +61 -0
- data/lib/aerospike/record.rb +42 -0
- data/lib/aerospike/result_code.rb +353 -0
- data/lib/aerospike/task/index_task.rb +59 -0
- data/lib/aerospike/task/task.rb +71 -0
- data/lib/aerospike/task/udf_register_task.rb +55 -0
- data/lib/aerospike/task/udf_remove_task.rb +55 -0
- data/lib/aerospike/udf.rb +24 -0
- data/lib/aerospike/utils/buffer.rb +139 -0
- data/lib/aerospike/utils/epoc.rb +28 -0
- data/lib/aerospike/utils/pool.rb +65 -0
- data/lib/aerospike/value/particle_type.rb +45 -0
- data/lib/aerospike/value/value.rb +380 -0
- data/lib/aerospike/version.rb +4 -0
- metadata +132 -0
@@ -0,0 +1,59 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# Copyright 2014 Aerospike, Inc.
|
3
|
+
#
|
4
|
+
# Portions may be licensed to Aerospike, Inc. under one or more contributor
|
5
|
+
# license agreements.
|
6
|
+
#
|
7
|
+
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
8
|
+
# use this file except in compliance with the License. You may obtain a copy of
|
9
|
+
# the License at http:#www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
13
|
+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
14
|
+
# License for the specific language governing permissions and limitations under
|
15
|
+
# the License.
|
16
|
+
|
17
|
+
require 'thread'
|
18
|
+
require 'time'
|
19
|
+
|
20
|
+
require 'aerospike/task/task'
|
21
|
+
|
22
|
+
module Aerospike
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
class IndexTask < Task
|
27
|
+
|
28
|
+
MATCHER = /.*load_pct=(?<load_pct>\d+(\.\d+)?).*/
|
29
|
+
|
30
|
+
def initialize(cluster, namespace, index_name, done=false)
|
31
|
+
super(cluster, done)
|
32
|
+
@namespace = namespace
|
33
|
+
@index_name = index_name
|
34
|
+
|
35
|
+
self
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def all_nodes_done?
|
41
|
+
command = "sindex/#{@namespace}/#{@index_name}"
|
42
|
+
nodes = @cluster.nodes
|
43
|
+
|
44
|
+
nodes.each do |node|
|
45
|
+
conn = node.get_connection(1)
|
46
|
+
response_map = Info.request(conn, command)
|
47
|
+
_, response = response_map.first
|
48
|
+
match = response.to_s.match(MATCHER)
|
49
|
+
load = match.nil? ? nil : match[:load_pct]
|
50
|
+
|
51
|
+
return false if load && (0...100).include?(load.to_f)
|
52
|
+
end
|
53
|
+
|
54
|
+
return true
|
55
|
+
end
|
56
|
+
|
57
|
+
end # class
|
58
|
+
|
59
|
+
end # module
|
@@ -0,0 +1,71 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# Copyright 2014 Aerospike, Inc.
|
3
|
+
#
|
4
|
+
# Portions may be licensed to Aerospike, Inc. under one or more contributor
|
5
|
+
# license agreements.
|
6
|
+
#
|
7
|
+
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
8
|
+
# use this file except in compliance with the License. You may obtain a copy of
|
9
|
+
# the License at http:#www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
13
|
+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
14
|
+
# License for the specific language governing permissions and limitations under
|
15
|
+
# the License.
|
16
|
+
|
17
|
+
require 'thread'
|
18
|
+
require 'time'
|
19
|
+
require 'atomic'
|
20
|
+
|
21
|
+
module Aerospike
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
class Task
|
26
|
+
|
27
|
+
def initialize(cluster, done)
|
28
|
+
@cluster = cluster
|
29
|
+
@done = Atomic.new(done)
|
30
|
+
@done_thread = Atomic.new(nil)
|
31
|
+
|
32
|
+
self
|
33
|
+
end
|
34
|
+
|
35
|
+
def wait_till_completed(poll_interval = 0.1, allowed_failures = 3)
|
36
|
+
return true if @done.value
|
37
|
+
|
38
|
+
# make sure there will be only ONE thread polling for completetion status
|
39
|
+
@done_thread.update do |dt|
|
40
|
+
dt ? dt : Thread.new do
|
41
|
+
abort_on_exception=true
|
42
|
+
failures = 0
|
43
|
+
while true
|
44
|
+
begin
|
45
|
+
break if completed?
|
46
|
+
sleep(poll_interval.to_f)
|
47
|
+
rescue => e
|
48
|
+
break if failures > allowed_failures
|
49
|
+
failures += 1
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
# wait for the poll thread to finish
|
56
|
+
@done_thread.value.join
|
57
|
+
# in case of errors and exceptions, the @done value might be false
|
58
|
+
@done.value
|
59
|
+
end
|
60
|
+
|
61
|
+
def completed?
|
62
|
+
if @done.value == true
|
63
|
+
true
|
64
|
+
else
|
65
|
+
@done.value = all_nodes_done?
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
end # class
|
70
|
+
|
71
|
+
end # module
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# Copyright 2014 Aerospike, Inc.
|
3
|
+
#
|
4
|
+
# Portions may be licensed to Aerospike, Inc. under one or more contributor
|
5
|
+
# license agreements.
|
6
|
+
#
|
7
|
+
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
8
|
+
# use this file except in compliance with the License. You may obtain a copy of
|
9
|
+
# the License at http:#www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
13
|
+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
14
|
+
# License for the specific language governing permissions and limitations under
|
15
|
+
# the License.
|
16
|
+
|
17
|
+
require 'thread'
|
18
|
+
require 'time'
|
19
|
+
|
20
|
+
require 'aerospike/task/task'
|
21
|
+
|
22
|
+
module Aerospike
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
class UdfRegisterTask < Task
|
27
|
+
|
28
|
+
def initialize(cluster, package_name)
|
29
|
+
super(cluster, false)
|
30
|
+
@package_name = package_name
|
31
|
+
|
32
|
+
self
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def all_nodes_done?
|
38
|
+
command = 'udf-list'
|
39
|
+
nodes = @cluster.nodes
|
40
|
+
|
41
|
+
nodes.each do |node|
|
42
|
+
conn = node.get_connection(1)
|
43
|
+
response_map = Info.request(conn, command)
|
44
|
+
_, response = response_map.first
|
45
|
+
index = response.to_s.index("filename=#{@package_name}")
|
46
|
+
|
47
|
+
return false if index.nil?
|
48
|
+
end
|
49
|
+
|
50
|
+
return true
|
51
|
+
end
|
52
|
+
|
53
|
+
end # class
|
54
|
+
|
55
|
+
end # module
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# Copyright 2014 Aerospike, Inc.
|
3
|
+
#
|
4
|
+
# Portions may be licensed to Aerospike, Inc. under one or more contributor
|
5
|
+
# license agreements.
|
6
|
+
#
|
7
|
+
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
8
|
+
# use this file except in compliance with the License. You may obtain a copy of
|
9
|
+
# the License at http:#www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
13
|
+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
14
|
+
# License for the specific language governing permissions and limitations under
|
15
|
+
# the License.
|
16
|
+
|
17
|
+
require 'thread'
|
18
|
+
require 'time'
|
19
|
+
|
20
|
+
require 'aerospike/task/task'
|
21
|
+
|
22
|
+
module Aerospike
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
class UdfRemoveTask < Task
|
27
|
+
|
28
|
+
def initialize(cluster, package_name)
|
29
|
+
super(cluster, false)
|
30
|
+
@package_name = package_name
|
31
|
+
|
32
|
+
self
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def all_nodes_done?
|
38
|
+
command = 'udf-list'
|
39
|
+
nodes = @cluster.nodes
|
40
|
+
|
41
|
+
nodes.each do |node|
|
42
|
+
conn = node.get_connection(1)
|
43
|
+
response_map = Info.request(conn, command)
|
44
|
+
_, response = response_map.first
|
45
|
+
index = response.to_s.index("filename=#{@package_name}")
|
46
|
+
|
47
|
+
return false if index
|
48
|
+
end
|
49
|
+
|
50
|
+
return true
|
51
|
+
end
|
52
|
+
|
53
|
+
end # class
|
54
|
+
|
55
|
+
end # module
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# Copyright 2014 Aerospike, Inc.
|
3
|
+
#
|
4
|
+
# Portions may be licensed to Aerospike, Inc. under one or more contributor
|
5
|
+
# license agreements.
|
6
|
+
#
|
7
|
+
# Licensed under the Apache License, Version 2.0 (the "License") you may not
|
8
|
+
# use this file except in compliance with the License. You may obtain a copy of
|
9
|
+
# the License at http:#www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
13
|
+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
14
|
+
# License for the specific language governing permissions and limitations under
|
15
|
+
# the License.
|
16
|
+
|
17
|
+
module Aerospike
|
18
|
+
|
19
|
+
# Polymorphic value classes used to efficiently serialize objects into the wire protocol.
|
20
|
+
class UDF
|
21
|
+
attr_accessor :filename, :hash, :language
|
22
|
+
end # class
|
23
|
+
|
24
|
+
end
|
@@ -0,0 +1,139 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# Copyright 2014 Aerospike, Inc.
|
3
|
+
#
|
4
|
+
# Portions may be licensed to Aerospike, Inc. under one or more contributor
|
5
|
+
# license agreements.
|
6
|
+
#
|
7
|
+
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
8
|
+
# use this file except in compliance with the License. You may obtain a copy of
|
9
|
+
# the License at http:#www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
13
|
+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
14
|
+
# License for the specific language governing permissions and limitations under
|
15
|
+
# the License.
|
16
|
+
|
17
|
+
require 'aerospike/utils/pool'
|
18
|
+
|
19
|
+
module Aerospike
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
# Buffer class to ease the work around
|
24
|
+
class Buffer
|
25
|
+
|
26
|
+
@@buf_pool = Pool.new
|
27
|
+
@@buf_pool.create_block = Proc.new { Buffer.new }
|
28
|
+
|
29
|
+
attr_accessor :buf
|
30
|
+
|
31
|
+
INT16 = 's>'
|
32
|
+
INT32 = 'l>'
|
33
|
+
INT64 = 'q>'
|
34
|
+
|
35
|
+
DEFAULT_BUFFER_SIZE = 16 * 1024
|
36
|
+
MAX_BUFFER_SIZE = 10 * 1024 * 1024
|
37
|
+
|
38
|
+
def initialize(size=DEFAULT_BUFFER_SIZE)
|
39
|
+
@buf = "%0#{size}d" % 0
|
40
|
+
|
41
|
+
@slice_end = @buf.bytesize
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.get
|
45
|
+
@@buf_pool.poll
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.put(buffer)
|
49
|
+
@@buf_pool.offer(buffer)
|
50
|
+
end
|
51
|
+
|
52
|
+
def size
|
53
|
+
@buf.bytesize
|
54
|
+
end
|
55
|
+
alias_method :length, :size
|
56
|
+
|
57
|
+
def resize(length)
|
58
|
+
if @buf.bytesize < length
|
59
|
+
@buf.concat("%0#{length - @buf.bytesize}d" % 0)
|
60
|
+
end
|
61
|
+
@slice_end = length
|
62
|
+
end
|
63
|
+
|
64
|
+
def write_byte(byte, offset)
|
65
|
+
@buf.setbyte(offset, byte.ord)
|
66
|
+
1
|
67
|
+
end
|
68
|
+
|
69
|
+
def write_binary(data, offset)
|
70
|
+
@buf[offset, data.bytesize] = data
|
71
|
+
data.bytesize
|
72
|
+
end
|
73
|
+
|
74
|
+
def write_int16(i, offset)
|
75
|
+
@buf[offset, 2] = [i].pack(INT16)
|
76
|
+
2
|
77
|
+
end
|
78
|
+
|
79
|
+
def write_int32(i, offset)
|
80
|
+
@buf[offset, 4] = [i].pack(INT32)
|
81
|
+
4
|
82
|
+
end
|
83
|
+
|
84
|
+
def write_int64(i, offset)
|
85
|
+
@buf[offset, 8] = [i].pack(INT64)
|
86
|
+
8
|
87
|
+
end
|
88
|
+
|
89
|
+
def read(offset, len=1)
|
90
|
+
start = offset
|
91
|
+
|
92
|
+
if len == 1
|
93
|
+
@buf.getbyte(start)
|
94
|
+
else
|
95
|
+
@buf[start, len]
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def read_int16(offset)
|
100
|
+
vals = @buf[offset..offset+1]
|
101
|
+
vals.unpack(INT16)[0]
|
102
|
+
end
|
103
|
+
|
104
|
+
def read_int32(offset)
|
105
|
+
vals = @buf[offset..offset+3]
|
106
|
+
vals.unpack(INT32)[0]
|
107
|
+
end
|
108
|
+
|
109
|
+
def read_int64(offset)
|
110
|
+
vals = @buf[offset..offset+7]
|
111
|
+
vals.unpack(INT64)[0]
|
112
|
+
end
|
113
|
+
|
114
|
+
def read_var_int64(offset, len)
|
115
|
+
val = 0
|
116
|
+
for i in 0...len
|
117
|
+
val <<= 8
|
118
|
+
val |= @buf[offset+i].ord & 0xFF
|
119
|
+
end
|
120
|
+
val
|
121
|
+
end
|
122
|
+
|
123
|
+
def to_s
|
124
|
+
@buf[0..@slice_end-1]
|
125
|
+
end
|
126
|
+
|
127
|
+
def dump(from=nil, to=nil)
|
128
|
+
from ||= 0
|
129
|
+
to ||= @slice_end - 1
|
130
|
+
|
131
|
+
@buf.bytes[from...to].each do |c|
|
132
|
+
print c.ord.to_s(16)
|
133
|
+
putc ' '
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
end # buffer
|
138
|
+
|
139
|
+
end # module
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# Copyright 2014 Aerospike, Inc.
|
3
|
+
#
|
4
|
+
# Portions may be licensed to Aerospike, Inc. under one or more contributor
|
5
|
+
# license agreements.
|
6
|
+
#
|
7
|
+
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
8
|
+
# use this file except in compliance with the License. You may obtain a copy of
|
9
|
+
# the License at http:#www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
13
|
+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
14
|
+
# License for the specific language governing permissions and limitations under
|
15
|
+
# the License.
|
16
|
+
|
17
|
+
require 'time'
|
18
|
+
|
19
|
+
module Aerospike
|
20
|
+
|
21
|
+
CITRUSLEAF_EPOCH = 1262304000
|
22
|
+
|
23
|
+
# Converts an Expiration time to TTL in seconds
|
24
|
+
def self.TTL(secs_from_citrus_leaf_epoc)
|
25
|
+
CITRUSLEAF_EPOCH+secs_from_citrus_leaf_epoc - Time.now.to_i
|
26
|
+
end
|
27
|
+
|
28
|
+
end # module
|
@@ -0,0 +1,65 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# Copyright 2014 Aerospike, Inc.
|
3
|
+
#
|
4
|
+
# Portions may be licensed to Aerospike, Inc. under one or more contributor
|
5
|
+
# license agreements.
|
6
|
+
#
|
7
|
+
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
8
|
+
# use this file except in compliance with the License. You may obtain a copy of
|
9
|
+
# the License at http:#www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
13
|
+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
14
|
+
# License for the specific language governing permissions and limitations under
|
15
|
+
# the License.
|
16
|
+
|
17
|
+
require 'thread'
|
18
|
+
require 'timeout'
|
19
|
+
|
20
|
+
module Aerospike
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
class Pool
|
25
|
+
|
26
|
+
attr_accessor :create_block, :cleanup_block
|
27
|
+
|
28
|
+
def initialize(max_size = 256, &block)
|
29
|
+
@create_block = block
|
30
|
+
@cleanup_block = nil
|
31
|
+
|
32
|
+
@pool = Queue.new
|
33
|
+
@max_size = max_size
|
34
|
+
end
|
35
|
+
|
36
|
+
def offer(obj)
|
37
|
+
if @pool.length < @max_size
|
38
|
+
@pool << obj
|
39
|
+
elsif @cleanup_block
|
40
|
+
@cleanup_block.call(obj)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
alias_method :<<, :offer
|
44
|
+
|
45
|
+
def poll(create_new=true)
|
46
|
+
res = nil
|
47
|
+
begin
|
48
|
+
res = @pool.pop(true) # non_blocking
|
49
|
+
return res
|
50
|
+
rescue
|
51
|
+
return @create_block.call if @create_block && create_new
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def empty?
|
56
|
+
@pool.length == 0
|
57
|
+
end
|
58
|
+
|
59
|
+
def length
|
60
|
+
@pool.length
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|