aerospike 3.0.0 → 4.1.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 +4 -4
- data/CHANGELOG.md +35 -0
- data/README.md +13 -9
- data/lib/aerospike/batch_attr.rb +292 -0
- data/lib/aerospike/batch_delete.rb +48 -0
- data/lib/aerospike/batch_read.rb +97 -0
- data/lib/aerospike/batch_record.rb +83 -0
- data/lib/aerospike/batch_results.rb +38 -0
- data/lib/aerospike/batch_udf.rb +76 -0
- data/lib/aerospike/batch_write.rb +79 -0
- data/lib/aerospike/cdt/bit_operation.rb +4 -5
- data/lib/aerospike/cdt/map_return_type.rb +8 -0
- data/lib/aerospike/client.rb +37 -51
- data/lib/aerospike/cluster.rb +50 -46
- data/lib/aerospike/command/batch_index_command.rb +7 -11
- data/lib/aerospike/command/batch_index_node.rb +3 -4
- data/lib/aerospike/command/batch_operate_command.rb +151 -0
- data/lib/aerospike/command/batch_operate_node.rb +51 -0
- data/lib/aerospike/command/command.rb +125 -98
- data/lib/aerospike/command/single_command.rb +1 -1
- data/lib/aerospike/exp/exp.rb +39 -41
- data/lib/aerospike/exp/exp_bit.rb +24 -24
- data/lib/aerospike/exp/exp_hll.rb +12 -12
- data/lib/aerospike/exp/exp_list.rb +101 -92
- data/lib/aerospike/exp/exp_map.rb +116 -119
- data/lib/aerospike/exp/operation.rb +2 -2
- data/lib/aerospike/info.rb +2 -4
- data/lib/aerospike/node.rb +7 -3
- data/lib/aerospike/operation.rb +38 -0
- data/lib/aerospike/policy/batch_delete_policy.rb +71 -0
- data/lib/aerospike/policy/batch_policy.rb +53 -4
- data/lib/aerospike/policy/batch_read_policy.rb +55 -0
- data/lib/aerospike/policy/batch_udf_policy.rb +75 -0
- data/lib/aerospike/policy/batch_write_policy.rb +105 -0
- data/lib/aerospike/policy/policy.rb +20 -40
- data/lib/aerospike/policy/query_duration.rb +48 -0
- data/lib/aerospike/policy/query_policy.rb +13 -8
- data/lib/aerospike/query/server_command.rb +1 -0
- data/lib/aerospike/query/statement.rb +5 -21
- data/lib/aerospike/result_code.rb +7 -1
- data/lib/aerospike/utils/buffer.rb +15 -15
- data/lib/aerospike/version.rb +1 -1
- data/lib/aerospike.rb +14 -12
- metadata +17 -14
- data/lib/aerospike/command/batch_direct_command.rb +0 -105
- data/lib/aerospike/command/batch_direct_exists_command.rb +0 -51
- data/lib/aerospike/command/batch_direct_node.rb +0 -40
- data/lib/aerospike/query/pred_exp/and_or.rb +0 -32
- data/lib/aerospike/query/pred_exp/geo_json_value.rb +0 -41
- data/lib/aerospike/query/pred_exp/integer_value.rb +0 -32
- data/lib/aerospike/query/pred_exp/op.rb +0 -27
- data/lib/aerospike/query/pred_exp/regex.rb +0 -32
- data/lib/aerospike/query/pred_exp/regex_flags.rb +0 -23
- data/lib/aerospike/query/pred_exp/string_value.rb +0 -29
- data/lib/aerospike/query/pred_exp.rb +0 -192
@@ -0,0 +1,151 @@
|
|
1
|
+
# Copyright 2018 Aerospike, Inc.
|
2
|
+
#
|
3
|
+
# Portions may be licensed to Aerospike, Inc. under one or more contributor
|
4
|
+
# license agreements.
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
7
|
+
# use this file except in compliance with the License. You may obtain a copy of
|
8
|
+
# the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
14
|
+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
15
|
+
# License for the specific language governing permissions and limitations under
|
16
|
+
# the License.
|
17
|
+
|
18
|
+
require 'aerospike/command/multi_command'
|
19
|
+
|
20
|
+
module Aerospike
|
21
|
+
|
22
|
+
class BatchOperateCommand < MultiCommand #:nodoc:
|
23
|
+
|
24
|
+
attr_accessor :batch, :policy, :attr, :records
|
25
|
+
|
26
|
+
def initialize(node, batch, policy, records)
|
27
|
+
super(node)
|
28
|
+
@batch = batch
|
29
|
+
@policy = policy
|
30
|
+
@records = records
|
31
|
+
end
|
32
|
+
|
33
|
+
def batch_flags
|
34
|
+
flags = 0
|
35
|
+
# flags |= 0x1 if @policy.allow_inline
|
36
|
+
flags |= 0x2 if @policy.allow_inline_ssd
|
37
|
+
flags |= 0x4 if @policy.respond_all_keys
|
38
|
+
flags
|
39
|
+
end
|
40
|
+
|
41
|
+
def write_buffer
|
42
|
+
field_count = 1
|
43
|
+
|
44
|
+
exp_size = estimate_expression_size(@policy.filter_exp)
|
45
|
+
@data_offset += exp_size
|
46
|
+
field_count += 1 if exp_size > 0
|
47
|
+
|
48
|
+
@data_buffer.reset
|
49
|
+
begin_cmd
|
50
|
+
@data_offset += FIELD_HEADER_SIZE + 4 + 1 # batch.keys.length + flags
|
51
|
+
|
52
|
+
prev = nil
|
53
|
+
@records.each do |record|
|
54
|
+
key = record.key
|
55
|
+
@data_offset += key.digest.length + 4 # 4 byte batch offset
|
56
|
+
|
57
|
+
if !@policy.send_key && !prev.nil? && prev.key.namespace == key.namespace && prev.key.set_name == key.set_name && record == prev
|
58
|
+
@data_offset += 1
|
59
|
+
else
|
60
|
+
@data_offset += 12
|
61
|
+
@data_offset += key.namespace.bytesize + FIELD_HEADER_SIZE
|
62
|
+
@data_offset += key.set_name.bytesize + FIELD_HEADER_SIZE
|
63
|
+
@data_offset += record.size
|
64
|
+
end
|
65
|
+
|
66
|
+
prev = record
|
67
|
+
end
|
68
|
+
size_buffer
|
69
|
+
write_batch_header(policy, field_count)
|
70
|
+
|
71
|
+
write_filter_exp(@policy.filter_exp, exp_size)
|
72
|
+
|
73
|
+
field_size_offset = @data_offset
|
74
|
+
|
75
|
+
write_field_header(0, Aerospike::FieldType::BATCH_INDEX)
|
76
|
+
@data_offset += @data_buffer.write_int32(batch.records.length, @data_offset)
|
77
|
+
@data_offset += @data_buffer.write_byte(batch_flags, @data_offset)
|
78
|
+
|
79
|
+
prev = nil
|
80
|
+
attr = BatchAttr.new
|
81
|
+
batch.records.each_with_index do |record, index|
|
82
|
+
@data_offset += @data_buffer.write_int32(index, @data_offset)
|
83
|
+
key = record.key
|
84
|
+
@data_offset += @data_buffer.write_binary(key.digest, @data_offset)
|
85
|
+
|
86
|
+
if !@policy.send_key && !prev.nil? && prev.key.namespace == key.namespace && prev.key.set_name == key.set_name && record == prev
|
87
|
+
@data_offset += @data_buffer.write_byte(BATCH_MSG_REPEAT, @data_offset)
|
88
|
+
else
|
89
|
+
case record
|
90
|
+
when BatchRead
|
91
|
+
attr.set_batch_read(record.policy)
|
92
|
+
if record.bin_names&.length&.> 0
|
93
|
+
write_batch_bin_names(key, record.bin_names, attr, attr.filter_exp)
|
94
|
+
elsif record.ops&.length&.> 0
|
95
|
+
attr.adjust_read(record.ops)
|
96
|
+
write_batch_operations(key, record.ops, attr, attr.filter_exp)
|
97
|
+
else
|
98
|
+
attr.adjust_read_all_bins(record.read_all_bins)
|
99
|
+
write_batch_read(key, attr, attr.filter_exp, 0)
|
100
|
+
end
|
101
|
+
|
102
|
+
when BatchWrite
|
103
|
+
attr.set_batch_write(record.policy)
|
104
|
+
attr.adjust_write(record.ops)
|
105
|
+
write_batch_operations(key, record.ops, attr, attr.filter_exp)
|
106
|
+
|
107
|
+
when BatchUDF
|
108
|
+
attr.set_batch_udf(record.policy)
|
109
|
+
write_batch_write(key, attr, attr.filter_exp, 3, 0)
|
110
|
+
write_field_string(record.package_name, Aerospike::FieldType::UDF_PACKAGE_NAME)
|
111
|
+
write_field_string(record.function_name, Aerospike::FieldType::UDF_FUNCTION)
|
112
|
+
write_field_bytes(record.arg_bytes, Aerospike::FieldType::UDF_ARGLIST)
|
113
|
+
|
114
|
+
when BatchDelete
|
115
|
+
attr.set_batch_delete(record.policy)
|
116
|
+
write_batch_write(key, attr, attr.filter_exp, 0, 0)
|
117
|
+
end
|
118
|
+
|
119
|
+
prev = record
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
@data_buffer.write_uint32(@data_offset-MSG_TOTAL_HEADER_SIZE-4, field_size_offset)
|
124
|
+
|
125
|
+
end_cmd
|
126
|
+
mark_compressed(@policy)
|
127
|
+
end
|
128
|
+
|
129
|
+
# Parse all results in the batch. Add records to shared list.
|
130
|
+
# If the record was not found, the bins will be nil.
|
131
|
+
def parse_row(result_code)
|
132
|
+
generation = @data_buffer.read_int32(6)
|
133
|
+
expiration = @data_buffer.read_int32(10)
|
134
|
+
batch_index = @data_buffer.read_int32(14)
|
135
|
+
field_count = @data_buffer.read_int16(18)
|
136
|
+
op_count = @data_buffer.read_int16(20)
|
137
|
+
|
138
|
+
skip_key(field_count)
|
139
|
+
req_key = records[batch_index].key
|
140
|
+
|
141
|
+
records[batch_index].result_code = result_code
|
142
|
+
case result_code
|
143
|
+
when 0, ResultCode::UDF_BAD_RESPONSE
|
144
|
+
record = parse_record(req_key, op_count, generation, expiration)
|
145
|
+
records[batch_index].record = record
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
end # class
|
150
|
+
|
151
|
+
end # module
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# Copyright 2018 Aerospike, Inc.
|
2
|
+
#
|
3
|
+
# Portions may be licensed to Aerospike, Inc. under one or more contributor
|
4
|
+
# license agreements.
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
7
|
+
# use this file except in compliance with the License. You may obtain a copy of
|
8
|
+
# the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
14
|
+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
15
|
+
# License for the specific language governing permissions and limitations under
|
16
|
+
# the License.
|
17
|
+
|
18
|
+
module Aerospike
|
19
|
+
|
20
|
+
class BatchOperateNode #:nodoc:
|
21
|
+
|
22
|
+
attr_accessor :node, :records_by_idx
|
23
|
+
|
24
|
+
def self.generate_list(cluster, replica_policy, records)
|
25
|
+
records.each_with_index
|
26
|
+
.group_by { |record, _| cluster.get_node_for_key(replica_policy, record.key, is_write: record.has_write) }
|
27
|
+
.map { |node, records_with_idx| BatchOperateNode.new(node, records_with_idx) }
|
28
|
+
end
|
29
|
+
|
30
|
+
def initialize(node, records_with_idx)
|
31
|
+
@node = node
|
32
|
+
@records_by_idx = records_with_idx.map(&:reverse).to_h
|
33
|
+
end
|
34
|
+
|
35
|
+
def records
|
36
|
+
records_by_idx.values
|
37
|
+
end
|
38
|
+
|
39
|
+
def each_record_with_index
|
40
|
+
records_by_idx.each do |idx, rec|
|
41
|
+
yield rec, idx
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def record_for_index(idx)
|
46
|
+
@records_by_idx[idx]
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|