Class: Aerospike::BatchAttr

Inherits:
Object
  • Object
show all
Defined in:
lib/aerospike/batch_attr.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ops = nil, opt = {}) ⇒ BatchAttr

Returns a new instance of BatchAttr.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/aerospike/batch_attr.rb', line 24

def initialize(ops = nil, opt = {})
  rp = create_policy(opt, BatchPolicy, nil)
  wp = create_policy(opt, BatchWritePolicy, nil)

  read_all_bins = false
  read_header = false
  has_read = false
  has_write_op = false

  ops&.each do |op|
    case op.op_type
    when Operation::BIT_READ, Operation::EXP_READ, Operation::HLL_READ, Operation::CDT_READ, Operation::READ	# Read all bins if no bin is specified.
      read_all_bins = op.bin_name.nil?
      has_read = true

    when Operation::READ_HEADER
      read_header = true
      has_read = true

    else
      has_write_op = true
    end
  end

  if has_write_op
    set_batch_write(wp)

    if has_read
      @read_attr |= Aerospike::INFO1_READ

      if read_all_bins
        @read_attr |= Aerospike::INFO1_GET_ALL
      elsif read_header
        @read_attr |= Aerospike::INFO1_NOBINDATA
      end
    end
  else
    set_batch_read(rp)

    if read_all_bins
      @read_attr |= Aerospike::INFO1_GET_ALL
    elsif read_header
      @read_attr |= Aerospike::INFO1_NOBINDATA
    end
  end
end

Instance Attribute Details

#expirationObject (readonly)

Returns the value of attribute expiration.



22
23
24
# File 'lib/aerospike/batch_attr.rb', line 22

def expiration
  @expiration
end

#filter_expObject (readonly)

Returns the value of attribute filter_exp.



22
23
24
# File 'lib/aerospike/batch_attr.rb', line 22

def filter_exp
  @filter_exp
end

#generationObject (readonly)

Returns the value of attribute generation.



22
23
24
# File 'lib/aerospike/batch_attr.rb', line 22

def generation
  @generation
end

#has_writeObject (readonly)

Returns the value of attribute has_write.



22
23
24
# File 'lib/aerospike/batch_attr.rb', line 22

def has_write
  @has_write
end

#info_attrObject (readonly)

Returns the value of attribute info_attr.



22
23
24
# File 'lib/aerospike/batch_attr.rb', line 22

def info_attr
  @info_attr
end

#read_attrObject (readonly)

Returns the value of attribute read_attr.



22
23
24
# File 'lib/aerospike/batch_attr.rb', line 22

def read_attr
  @read_attr
end

#send_keyObject (readonly)

Returns the value of attribute send_key.



22
23
24
# File 'lib/aerospike/batch_attr.rb', line 22

def send_key
  @send_key
end

#write_attrObject (readonly)

Returns the value of attribute write_attr.



22
23
24
# File 'lib/aerospike/batch_attr.rb', line 22

def write_attr
  @write_attr
end

Instance Method Details

#adjust_read(ops) ⇒ Object



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/aerospike/batch_attr.rb', line 97

def adjust_read(ops)
    read_all_bins = false
    read_header = false

    ops.each do |op|
   case op.op_type
   when Operation::BIT_READ, Operation::EXP_READ, Operation::HLL_READ, Operation::CDT_READ, Operation::READ	# Read all bins if no bin is specified.
          read_all_bins = op.bin_name.nil?
   when Operation::READ_HEADER
        read_header = true
   end
    end

    if read_all_bins
      @read_attr |= Aerospike::INFO1_GET_ALL
    elsif read_header
      @read_attr |= Aerospike::INFO1_NOBINDATA
    end
end

#adjust_read_all_bins(read_all_bins) ⇒ Object



117
118
119
# File 'lib/aerospike/batch_attr.rb', line 117

def adjust_read_all_bins(read_all_bins)
  @read_attr |= read_all_bins ? Aerospike::INFO1_GET_ALL : Aerospike::INFO1_NOBINDATA
end

#adjust_write(ops) ⇒ Object



176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
# File 'lib/aerospike/batch_attr.rb', line 176

def adjust_write(ops)
  read_all_bins = false
  read_header = false
  has_read = false

  ops.each do |op|
    case op.op_type
    when Operation::BIT_READ, Operation::EXP_READ, Operation::HLL_READ, Operation::CDT_READ, Operation::READ	# Read all bins if no bin is specified.
      read_all_bins = op.bin_name.nil?
      has_read = true

    when Operation::READ_HEADER
      read_header = true
      has_read = true

    end
  end

  if has_read
    @read_attr |= Aerospike::INFO1_READ

    if read_all_bins
      @read_attr |= Aerospike::INFO1_GET_ALL
    elsif read_header
      @read_attr |= Aerospike::INFO1_NOBINDATA
    end
  end
end

#set_batch_delete(dp) ⇒ Object



246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
# File 'lib/aerospike/batch_attr.rb', line 246

def set_batch_delete(dp)
  @filter_exp = dp.filter_exp
  @read_attr = 0
  @write_attr = Aerospike::INFO2_WRITE | Aerospike::INFO2_RESPOND_ALL_OPS | Aerospike::INFO2_DELETE
  @info_attr = 0
  @expiration = 0
  @has_write = true
  @send_key = dp.send_key

  case dp.generation_policy
  when GenerationPolicy::NONE
    @generation = 0
  when GenerationPolicy::EXPECT_GEN_EQUAL
    @generation = dp.generation
    @write_attr |= Aerospike::INFO2_GENERATION
  when GenerationPolicy::EXPECT_GEN_GT
    @generation = dp.generation
    @write_attr |= Aerospike::INFO2_GENERATION_GT
  else
   @generation = 0
  end

  if dp.durable_delete
    @write_attr |= Aerospike::INFO2_DURABLE_DELETE
  end

  if dp.commit_level == CommitLevel::COMMIT_MASTER
    @info_attr |= Aerospike::INFO3_COMMIT_MASTER
  end
end

#set_batch_read(rp) ⇒ Object



84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/aerospike/batch_attr.rb', line 84

def set_batch_read(rp)
  @filter_exp = rp.filter_exp
  @read_attr = Aerospike::INFO1_READ

  @write_attr = 0
  @info_attr = 0

  @expiration = rp.read_touch_ttl_percent
  @generation = 0
  @has_write = false
  @send_key = false
end

#set_batch_udf(up) ⇒ Object



216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
# File 'lib/aerospike/batch_attr.rb', line 216

def set_batch_udf(up)
  @filter_exp = up.filter_exp
  @read_attr = 0
  @write_attr = Aerospike::INFO2_WRITE
  @info_attr = 0
  @expiration = up.expiration
  @generation = 0
  @has_write = true
  @send_key = up.send_key

  if up.durable_delete
    @write_attr |= Aerospike::INFO2_DURABLE_DELETE
  end

  if up.commit_level == CommitLevel::COMMIT_MASTER
    @info_attr |= Aerospike::INFO3_COMMIT_MASTER
  end
end

#set_batch_write(wp) ⇒ Object



132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# File 'lib/aerospike/batch_attr.rb', line 132

def set_batch_write(wp)
  @filter_exp = wp.filter_exp
  @read_attr = 0
  @write_attr = Aerospike::INFO2_WRITE | Aerospike::INFO2_RESPOND_ALL_OPS
  @info_attr = 0
  @expiration = wp.expiration
  @has_write = true
  @send_key = wp.send_key

  case wp.generation_policy
  when GenerationPolicy::NONE
    @generation = 0
  when GenerationPolicy::EXPECT_GEN_EQUAL
    @generation = wp.generation
    @write_attr |= Aerospike::INFO2_GENERATION
  when GenerationPolicy::EXPECT_GEN_GT
    @generation = wp.generation
    @write_attr |= Aerospike::INFO2_GENERATION_GT
  else
    @generation = 0
  end

  case wp.record_exists_action
  when RecordExistsAction::UPDATE
  # NOOP
  when RecordExistsAction::UPDATE_ONLY
    @info_attr |= Aerospike::INFO3_UPDATE_ONLY
  when RecordExistsAction::REPLACE
    @info_attr |= Aerospike::INFO3_CREATE_OR_REPLACE
  when RecordExistsAction::REPLACE_ONLY
    @info_attr |= Aerospike::INFO3_REPLACE_ONLY
  when RecordExistsAction::CREATE_ONLY
    @write_attr |= Aerospike::INFO2_CREATE_ONLY
  end

  if wp.durable_delete
    @write_attr |= Aerospike::INFO2_DURABLE_DELETE
  end

  if wp.commit_level == CommitLevel::COMMIT_MASTER
    @info_attr |= Aerospike::INFO3_COMMIT_MASTER
  end
end

#set_delete(dp) ⇒ Object



235
236
237
238
239
240
241
242
243
244
# File 'lib/aerospike/batch_attr.rb', line 235

def set_delete(dp)
  @filter_exp = nil
  @read_attr = 0
  @write_attr = Aerospike::INFO2_WRITE | Aerospike::INFO2_RESPOND_ALL_OPS | Aerospike::INFO2_DELETE
  @info_attr = 0
  @expiration = 0
  @generation = 0
  @has_write = true
  @send_key = dp.send_key
end

#set_read(rp) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/aerospike/batch_attr.rb', line 71

def set_read(rp)
  @filter_exp = nil
  @read_attr = Aerospike::INFO1_READ

  @write_attr = 0
  @info_attr = 0

  @expiration = rp.read_touch_ttl_percent
  @generation = 0
  @has_write = false
  @send_key = false
end

#set_udf(up) ⇒ Object



205
206
207
208
209
210
211
212
213
214
# File 'lib/aerospike/batch_attr.rb', line 205

def set_udf(up)
  @filter_exp = nil
  @read_attr = 0
  @write_attr = Aerospike::INFO2_WRITE
  @info_attr = 0
  @expiration = 0
  @generation = 0
  @has_write = true
  @send_key = up.send_key
end

#set_write(wp) ⇒ Object



121
122
123
124
125
126
127
128
129
130
# File 'lib/aerospike/batch_attr.rb', line 121

def set_write(wp)
  @filter_exp = nil
  @read_attr = 0
  @write_attr = Aerospike::INFO2_WRITE | Aerospike::INFO2_RESPOND_ALL_OPS
  @info_attr = 0
  @expiration = 0
  @generation = 0
  @has_write = true
  @send_key = wp.send_key
end