whi-cassie 1.0.7 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/HISTORY.md +41 -0
- data/README.md +11 -1
- data/VERSION +1 -1
- data/lib/cassie/model.rb +35 -13
- data/lib/cassie.rb +31 -12
- data/spec/cassie/model_spec.rb +60 -2
- data/spec/cassie_spec.rb +43 -4
- data/spec/models/thing.rb +2 -0
- data/spec/spec_helper.rb +7 -1
- data/whi-cassie.gemspec +1 -1
- metadata +6 -6
- data/HISTORY.txt +0 -33
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ed90a287c5693223a52bedf3d65cf4cdccf8d9c5
|
4
|
+
data.tar.gz: 53f2742d6789dcbabaff098831214b1535367f8d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 41a9270e5b4a88ba2ae253d0fc2e4662424ba0a7b899d0869922f8d7b4c8bbd54ba32df2a35bcaaf5e8ffa3fb36d6378df6794cd8a08d613f65508df3dff1df3
|
7
|
+
data.tar.gz: 6e83ad281fad4ea6a41925339e4c531e91d93314402ef6ff4aa87ea0c0df6929e304384a39b7f374642983012f7b8aee76e3e31f8ffbcfe9e44560f25ed3eb31
|
data/HISTORY.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
## 1.1.0
|
2
|
+
|
3
|
+
* Bump supported version of cassandra-driver to 3.x.
|
4
|
+
|
5
|
+
* Add more control over consistency settings.
|
6
|
+
|
7
|
+
* Add read and write consistency on model definitions.
|
8
|
+
|
9
|
+
## 1.0.7
|
10
|
+
|
11
|
+
* Add find_subscribers to Cassie::Model for instrumenting model find calls.
|
12
|
+
|
13
|
+
## 1.0.6
|
14
|
+
|
15
|
+
* Wrap raw CQL in a Simple statement for code consistency in subscribers.
|
16
|
+
|
17
|
+
## 1.0.5
|
18
|
+
|
19
|
+
* Add subscribers for instumenting code.
|
20
|
+
|
21
|
+
* Remove hardcoded log warnings for long running statements since this can now be better handled with instrumentation.
|
22
|
+
|
23
|
+
## 1.0.4
|
24
|
+
|
25
|
+
* Set less cryptic error message for invalid records exceptions.
|
26
|
+
|
27
|
+
## 1.0.3
|
28
|
+
|
29
|
+
* Fix bugs preventing counter and set data types from working on models.
|
30
|
+
|
31
|
+
## 1.0.2
|
32
|
+
|
33
|
+
* Set cluster logger on the Cassandra cluster if not already set.
|
34
|
+
|
35
|
+
## 1.0.1
|
36
|
+
|
37
|
+
* Allow finding the offset to the row from a range.
|
38
|
+
|
39
|
+
## 1.0.0
|
40
|
+
|
41
|
+
* Initial Release
|
data/README.md
CHANGED
@@ -83,7 +83,17 @@ You can use all the standard ActiveModel validation methods on your models. You
|
|
83
83
|
Note that one difference between Cassandra and other data stores is that data is only eventually consistent. Some subtle results of this:
|
84
84
|
|
85
85
|
1. You won't get an error if you try to create a record with the same primary key twice. Cassandra will simple use the second insert as an update statement.
|
86
|
-
2. If you perform any queries in your validation logic (e.g. to ensure a value is unique), you really need to use a high consistency level like quorum. If you use a low consistency level, there is a chance that your query can hit a node in the cluster that hasn't been replicated to and your validation could make decisions based on the wrong data.
|
86
|
+
2. If you perform any queries in your validation logic (e.g. to ensure a value is unique), you really need to use a high consistency level like quorum. If you use a low consistency level, there is a chance that your query can hit a node in the cluster that hasn't been replicated to and your validation could make decisions based on the wrong data.
|
87
|
+
|
88
|
+
### Consistency
|
89
|
+
|
90
|
+
You can specify the consistency for the connection when it is created in the options. This will default to `:local_one`. You can override the global consistency at runtime by setting a new consistency on the instance `Cassie.instance.consistency = :local_quorum`. This will be the default consistency used if nothing else specifies a consistency.
|
91
|
+
|
92
|
+
You can override the default consistency within a block by using the `Cassie.consistency` method. This method will set the default consistency within a block and can be used in instances where you want to force a specific consistency on all queries within a specific scope.
|
93
|
+
|
94
|
+
Finally, you can force a specific consistency by specifying `:consistency` in the options to any of the statements that execute a query. This consistency will override any default consistency you've specified. However, if the statement is a write statement and is wrapped in a batch block, the consistency option will have no effect. You can, though, specify the `:consistency` option in the `batch` call to apply a consistency to all statements in the batch.
|
95
|
+
|
96
|
+
In `Cassie::Model` classes, you can specify `read_consistency` and `write_consistency` that will be applied to all statements generated by the model. You could use this, for instance, to force all write operations to use `:quorum` while letting all read operations user `:one`. These consistency levels will override any default levels if they are set.
|
87
97
|
|
88
98
|
### Prepared statements
|
89
99
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0
|
1
|
+
1.1.0
|
data/lib/cassie/model.rb
CHANGED
@@ -48,6 +48,8 @@ module Cassie::Model
|
|
48
48
|
class_attribute :_ordering_keys, :instance_reader => false, :instance_writer => false
|
49
49
|
class_attribute :_counter_table, :instance_reader => false, :instance_writer => false
|
50
50
|
class_attribute :find_subscribers, :instance_reader => false, :instance_writer => false
|
51
|
+
class_attribute :read_consistency, :instance_reader => false, :instance_writer => false
|
52
|
+
class_attribute :write_consistency
|
51
53
|
define_model_callbacks :create, :update, :save, :destroy
|
52
54
|
self._columns = {}
|
53
55
|
self._column_aliases = HashWithIndifferentAccess.new
|
@@ -98,8 +100,11 @@ module Cassie::Model
|
|
98
100
|
def column(name, type, as: nil)
|
99
101
|
name = name.to_sym
|
100
102
|
type_class = nil
|
103
|
+
type_name = type.to_s.downcase.classify
|
104
|
+
# Backward compatibility with older driver versions.
|
105
|
+
type_name = "Text" if type_name == "Varchar"
|
101
106
|
begin
|
102
|
-
type_class = "Cassandra::Types::#{
|
107
|
+
type_class = "Cassandra::Types::#{type_name}".constantize
|
103
108
|
rescue NameError
|
104
109
|
raise ArgumentError.new("#{type.inspect} is not an allowed Cassandra type")
|
105
110
|
end
|
@@ -231,7 +236,7 @@ module Cassie::Model
|
|
231
236
|
values << Integer(limit)
|
232
237
|
end
|
233
238
|
|
234
|
-
results = connection.find(cql, values, options)
|
239
|
+
results = connection.find(cql, values, consistency_options(read_consistency, options))
|
235
240
|
records = [] unless block_given?
|
236
241
|
row_count = 0
|
237
242
|
loop do
|
@@ -294,7 +299,7 @@ module Cassie::Model
|
|
294
299
|
where = connection.prepare(cql)
|
295
300
|
end
|
296
301
|
|
297
|
-
results = connection.find(cql, values, options)
|
302
|
+
results = connection.find(cql, values, consistency_options(read_consistency, options))
|
298
303
|
results.rows.first["count"]
|
299
304
|
end
|
300
305
|
|
@@ -321,13 +326,15 @@ module Cassie::Model
|
|
321
326
|
key_hash.each do |name, value|
|
322
327
|
cleanup_up_hash[column_name(name)] = value
|
323
328
|
end
|
324
|
-
connection.delete(full_table_name, cleanup_up_hash)
|
329
|
+
connection.delete(full_table_name, cleanup_up_hash, :consistency => write_consistency)
|
325
330
|
end
|
326
331
|
|
327
332
|
# All insert, update, and delete calls within the block will be sent as a single
|
328
|
-
# batch to Cassandra.
|
329
|
-
|
330
|
-
|
333
|
+
# batch to Cassandra. The consistency level will default to the write consistency
|
334
|
+
# level if it's been set.
|
335
|
+
def batch(options = nil)
|
336
|
+
options = consistency_options(write_consistency, options)
|
337
|
+
connection.batch(options) do
|
331
338
|
yield
|
332
339
|
end
|
333
340
|
end
|
@@ -448,6 +455,19 @@ module Cassie::Model
|
|
448
455
|
type_class.new(value)
|
449
456
|
end
|
450
457
|
end
|
458
|
+
|
459
|
+
def consistency_options(consistency, options)
|
460
|
+
if consistency
|
461
|
+
if options
|
462
|
+
options = options.merge(:consistency => consistency) if options[:consistency].nil?
|
463
|
+
options
|
464
|
+
else
|
465
|
+
{:consistency => consistency}
|
466
|
+
end
|
467
|
+
else
|
468
|
+
options
|
469
|
+
end
|
470
|
+
end
|
451
471
|
end
|
452
472
|
|
453
473
|
def initialize(attributes = {})
|
@@ -473,13 +493,14 @@ module Cassie::Model
|
|
473
493
|
valid_record = (validate ? valid? : true)
|
474
494
|
if valid_record
|
475
495
|
run_callbacks(:save) do
|
496
|
+
options = {:consistency => write_consistency, :ttl => (ttl || persistence_ttl)}
|
476
497
|
if persisted?
|
477
498
|
run_callbacks(:update) do
|
478
|
-
self.class.connection.update(self.class.full_table_name, values_hash, key_hash,
|
499
|
+
self.class.connection.update(self.class.full_table_name, values_hash, key_hash, options)
|
479
500
|
end
|
480
501
|
else
|
481
502
|
run_callbacks(:create) do
|
482
|
-
self.class.connection.insert(self.class.full_table_name, attributes,
|
503
|
+
self.class.connection.insert(self.class.full_table_name, attributes, options)
|
483
504
|
@persisted = true
|
484
505
|
end
|
485
506
|
end
|
@@ -492,8 +513,8 @@ module Cassie::Model
|
|
492
513
|
|
493
514
|
# Save a record. Returns true if the record was saved and raises an ActiveRecord::RecordInvalid
|
494
515
|
# error if the record is invalid.
|
495
|
-
def save!
|
496
|
-
if save
|
516
|
+
def save!(ttl: nil)
|
517
|
+
if save(ttl: ttl)
|
497
518
|
true
|
498
519
|
else
|
499
520
|
raise Cassie::RecordInvalid.new(self)
|
@@ -503,7 +524,7 @@ module Cassie::Model
|
|
503
524
|
# Delete a record and call the destroy callbacks.
|
504
525
|
def destroy
|
505
526
|
run_callbacks(:destroy) do
|
506
|
-
self.class.connection.delete(self.class.full_table_name, key_hash)
|
527
|
+
self.class.connection.delete(self.class.full_table_name, key_hash, :consistency => write_consistency)
|
507
528
|
@persisted = false
|
508
529
|
true
|
509
530
|
end
|
@@ -548,7 +569,8 @@ module Cassie::Model
|
|
548
569
|
if amount != 0
|
549
570
|
run_callbacks(:update) do
|
550
571
|
adjustment = (amount < 0 ? "#{name} = #{name} - #{amount.abs}" : "#{name} = #{name} + #{amount}")
|
551
|
-
|
572
|
+
options = {:consistency => write_consistency, :ttl => (ttl || persistence_ttl)}
|
573
|
+
self.class.connection.update(self.class.full_table_name, adjustment, key_hash, options)
|
552
574
|
end
|
553
575
|
end
|
554
576
|
record = self.class.find(key_hash)
|
data/lib/cassie.rb
CHANGED
@@ -36,6 +36,7 @@ class Cassie
|
|
36
36
|
end
|
37
37
|
|
38
38
|
attr_reader :config, :subscribers
|
39
|
+
attr_accessor :consistency
|
39
40
|
|
40
41
|
class << self
|
41
42
|
# A singleton instance that can be shared to communicate with a Cassandra cluster.
|
@@ -90,6 +91,7 @@ class Cassie
|
|
90
91
|
@prepared_statements = {}
|
91
92
|
@last_prepare_warning = Time.now
|
92
93
|
@subscribers = Subscribers.new
|
94
|
+
@consistency = ((config.cluster || {})[:consistency] || :local_one)
|
93
95
|
end
|
94
96
|
|
95
97
|
# Open a connection to the Cassandra cluster.
|
@@ -180,7 +182,7 @@ class Cassie
|
|
180
182
|
batch_statement.add(statement)
|
181
183
|
end
|
182
184
|
end
|
183
|
-
execute(batch_statement)
|
185
|
+
execute(batch_statement, nil, options)
|
184
186
|
end
|
185
187
|
ensure
|
186
188
|
Thread.current[:cassie_batch] = nil
|
@@ -215,10 +217,13 @@ class Cassie
|
|
215
217
|
end
|
216
218
|
cql = "INSERT INTO #{table} (#{columns.join(', ')}) VALUES (#{question_marks(columns.size)})"
|
217
219
|
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
220
|
+
if options && options.include?(:ttl)
|
221
|
+
options = options.dup
|
222
|
+
ttl = options.delete(:ttl)
|
223
|
+
if ttl
|
224
|
+
cql << " USING TTL ?"
|
225
|
+
values << Integer(ttl)
|
226
|
+
end
|
222
227
|
end
|
223
228
|
|
224
229
|
batch_or_execute(cql, values, options)
|
@@ -245,11 +250,16 @@ class Cassie
|
|
245
250
|
values = update_values + key_values
|
246
251
|
|
247
252
|
cql = "UPDATE #{table}"
|
248
|
-
|
249
|
-
if ttl
|
250
|
-
|
251
|
-
|
253
|
+
|
254
|
+
if options && options.include?(:ttl)
|
255
|
+
options = options.dup
|
256
|
+
ttl = options.delete(:ttl)
|
257
|
+
if ttl
|
258
|
+
cql << " USING TTL ?"
|
259
|
+
values.unshift(Integer(ttl))
|
260
|
+
end
|
252
261
|
end
|
262
|
+
|
253
263
|
cql << " SET #{update_cql.join(', ')} WHERE #{key_cql}"
|
254
264
|
|
255
265
|
batch_or_execute(cql, values, options)
|
@@ -287,9 +297,13 @@ class Cassie
|
|
287
297
|
end
|
288
298
|
|
289
299
|
# Set a default consistency from a block context if it isn't explicitly set.
|
290
|
-
|
291
|
-
if
|
292
|
-
|
300
|
+
statement_consistency = current_consistency
|
301
|
+
if statement_consistency
|
302
|
+
if options
|
303
|
+
options = options.merge(:consistency => statement_consistency) if options[:consistency].nil?
|
304
|
+
else
|
305
|
+
options = {:consistency => statement_consistency}
|
306
|
+
end
|
293
307
|
end
|
294
308
|
|
295
309
|
session.execute(statement, options || {})
|
@@ -303,6 +317,11 @@ class Cassie
|
|
303
317
|
end
|
304
318
|
end
|
305
319
|
end
|
320
|
+
|
321
|
+
# Return the current consistency level that has been set for statements.
|
322
|
+
def current_consistency
|
323
|
+
Thread.current[:cassie_consistency] || consistency
|
324
|
+
end
|
306
325
|
|
307
326
|
private
|
308
327
|
|
data/spec/cassie/model_spec.rb
CHANGED
@@ -132,9 +132,9 @@ describe Cassie::Model do
|
|
132
132
|
end
|
133
133
|
|
134
134
|
describe "batch" do
|
135
|
-
it "should delegate to Cassie.batch" do
|
135
|
+
it "should delegate to Cassie.batch using the write consistency" do
|
136
136
|
Cassie::Thing.connection.should be_a(Cassie)
|
137
|
-
expect(Cassie::Thing.connection).to receive(:batch).and_call_original
|
137
|
+
expect(Cassie::Thing.connection).to receive(:batch).with(:consistency => :quorum).and_call_original
|
138
138
|
Cassie::Thing.batch{}
|
139
139
|
end
|
140
140
|
end
|
@@ -183,6 +183,16 @@ describe Cassie::Model do
|
|
183
183
|
record.callbacks.should == [:save, :update]
|
184
184
|
Cassie::Thing.find(:owner => 1, :id => 2).value.should == 'bar'
|
185
185
|
end
|
186
|
+
|
187
|
+
it "should save new records with a ttl" do
|
188
|
+
expect(Cassie::Thing.connection).to receive(:insert).with("cassie_specs.things", {:owner=>1, :id=>2, :val=>'foo'}, {:consistency=>:quorum, :ttl=>10}).and_call_original
|
189
|
+
record = Cassie::Thing.new(:owner => 1, :id => 2, :val => 'foo')
|
190
|
+
record.persisted?.should == false
|
191
|
+
record.save(ttl: 10).should == true
|
192
|
+
record.persisted?.should == true
|
193
|
+
record.callbacks.should == [:save, :create]
|
194
|
+
Cassie::Thing.find(:owner => 1, :id => 2).should == record
|
195
|
+
end
|
186
196
|
end
|
187
197
|
|
188
198
|
describe "destroy" do
|
@@ -195,6 +205,54 @@ describe Cassie::Model do
|
|
195
205
|
end
|
196
206
|
end
|
197
207
|
|
208
|
+
describe "consistency" do
|
209
|
+
let(:connection){ Cassie::Thing.connection }
|
210
|
+
|
211
|
+
it "should be able to set a model level read consistency" do
|
212
|
+
expect(connection).to receive(:find).with("SELECT owner, id, val FROM cassie_specs.things WHERE owner = ?", [0], {:consistency => :one}).and_call_original
|
213
|
+
Cassie::Thing.find_all(where: {:owner => 0})
|
214
|
+
end
|
215
|
+
|
216
|
+
it "should be able to override the model level read consistency" do
|
217
|
+
save_val = Cassie::Thing.read_consistency
|
218
|
+
begin
|
219
|
+
Cassie::Thing.read_consistency = :quorum
|
220
|
+
expect(connection).to receive(:find).with("SELECT owner, id, val FROM cassie_specs.things WHERE owner = ?", [0], {:consistency => :quorum}).and_call_original
|
221
|
+
Cassie::Thing.find_all(where: {:owner => 0})
|
222
|
+
ensure
|
223
|
+
Cassie::Thing.read_consistency = save_val
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
227
|
+
it "should be able to set a model level write consistency" do
|
228
|
+
thing = Cassie::Thing.new(:owner => 1, :id => 2)
|
229
|
+
expect(connection).to receive(:insert).with("cassie_specs.things", {:owner=>1, :id=>2, :val=>nil}, {:consistency=>:quorum, :ttl=>nil}).and_call_original
|
230
|
+
thing.save
|
231
|
+
|
232
|
+
thing.val = "foo"
|
233
|
+
expect(connection).to receive(:update).with("cassie_specs.things", {:val=>"foo"}, {:owner=>1, :id=>2}, {:consistency=>:quorum, :ttl=>nil}).and_call_original
|
234
|
+
thing.save
|
235
|
+
|
236
|
+
expect(connection).to receive(:delete).with("cassie_specs.things", {:owner=>1, :id=>2}, {:consistency=>:quorum}).and_call_original
|
237
|
+
thing.destroy
|
238
|
+
end
|
239
|
+
|
240
|
+
it "should be able to override the model level write consistency" do
|
241
|
+
thing = Cassie::Thing.new(:owner => 1, :id => 2)
|
242
|
+
thing.write_consistency = :local_quorum
|
243
|
+
|
244
|
+
expect(connection).to receive(:insert).with("cassie_specs.things", {:owner=>1, :id=>2, :val=>nil}, {:consistency=>:local_quorum, :ttl=>nil}).and_call_original
|
245
|
+
thing.save
|
246
|
+
|
247
|
+
thing.val = "foo"
|
248
|
+
expect(connection).to receive(:update).with("cassie_specs.things", {:val=>"foo"}, {:owner=>1, :id=>2}, {:consistency=>:local_quorum, :ttl=>nil}).and_call_original
|
249
|
+
thing.save
|
250
|
+
|
251
|
+
expect(connection).to receive(:delete).with("cassie_specs.things", {:owner=>1, :id=>2}, {:consistency=>:local_quorum}).and_call_original
|
252
|
+
thing.destroy
|
253
|
+
end
|
254
|
+
end
|
255
|
+
|
198
256
|
describe "type conversion" do
|
199
257
|
let(:model){ Cassie::TypeTester.new }
|
200
258
|
|
data/spec/cassie_spec.rb
CHANGED
@@ -131,14 +131,14 @@ describe Cassie do
|
|
131
131
|
messages.size.should == 1
|
132
132
|
message = messages.shift
|
133
133
|
message.statement.should be_a(Cassandra::Statement)
|
134
|
-
message.options.should == {:arguments => [1]}
|
134
|
+
message.options.should == {:arguments => [1], :consistency => :local_one}
|
135
135
|
message.elapsed_time.should be_a(Float)
|
136
136
|
|
137
137
|
instance.execute("SELECT owner, id, val FROM #{table} WHERE owner = 1")
|
138
138
|
messages.size.should == 1
|
139
139
|
message = messages.shift
|
140
140
|
message.statement.should be_a(Cassandra::Statement)
|
141
|
-
message.options.should ==
|
141
|
+
message.options.should == {:consistency => :local_one}
|
142
142
|
message.elapsed_time.should be_a(Float)
|
143
143
|
|
144
144
|
instance.batch do
|
@@ -148,7 +148,7 @@ describe Cassie do
|
|
148
148
|
messages.size.should == 1
|
149
149
|
message = messages.shift
|
150
150
|
message.statement.should be_a(Cassandra::Statements::Batch)
|
151
|
-
message.options.should ==
|
151
|
+
message.options.should == {:consistency => :local_one}
|
152
152
|
message.elapsed_time.should be_a(Float)
|
153
153
|
ensure
|
154
154
|
instance.subscribers.clear
|
@@ -160,14 +160,24 @@ describe Cassie do
|
|
160
160
|
let(:session){ instance.send(:session) }
|
161
161
|
|
162
162
|
it "should not specify query consistency by default" do
|
163
|
-
expect(session).to receive(:execute).with(Cassandra::Statements::Simple.new("SELECT * FROM dual"), {})
|
163
|
+
expect(session).to receive(:execute).with(Cassandra::Statements::Simple.new("SELECT * FROM dual"), {:consistency => :local_one})
|
164
164
|
instance.execute("SELECT * FROM dual")
|
165
|
+
expect(instance.current_consistency).to eq :local_one
|
165
166
|
end
|
166
167
|
|
167
168
|
it "should allow specifying the consistency in a block" do
|
168
169
|
expect(session).to receive(:execute).with(Cassandra::Statements::Simple.new("SELECT * FROM dual"), {:consistency => :one})
|
169
170
|
Cassie.consistency(:one) do
|
170
171
|
instance.execute("SELECT * FROM dual")
|
172
|
+
expect(instance.current_consistency).to eq :one
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
it "should allow specifying the consistency in a block if statement consistency is explicitly nil" do
|
177
|
+
expect(session).to receive(:execute).with(Cassandra::Statements::Simple.new("SELECT * FROM dual"), {:consistency => :one})
|
178
|
+
Cassie.consistency(:one) do
|
179
|
+
instance.execute("SELECT * FROM dual", nil, :consistency => nil)
|
180
|
+
expect(instance.current_consistency).to eq :one
|
171
181
|
end
|
172
182
|
end
|
173
183
|
|
@@ -175,6 +185,35 @@ describe Cassie do
|
|
175
185
|
expect(session).to receive(:execute).with(Cassandra::Statements::Simple.new("SELECT * FROM dual"), {:consistency => :two})
|
176
186
|
Cassie.consistency(:one) do
|
177
187
|
instance.execute("SELECT * FROM dual", nil, :consistency => :two)
|
188
|
+
expect(instance.current_consistency).to eq :one
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
it "should use the consistency passed in the batch for all statements in the batch" do
|
193
|
+
expect(session).to receive(:execute).with(an_instance_of(Cassandra::Statements::Batch::Logged), {:consistency => :two})
|
194
|
+
Cassie.instance.batch(:consistency => :two) do
|
195
|
+
instance.insert(table, :owner => 1, :id => 2, :val => 'foo')
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
it "should be able to specify a global consistancy" do
|
200
|
+
expect(session).to receive(:execute).with(Cassandra::Statements::Simple.new("SELECT * FROM dual"), {:consistency => :one})
|
201
|
+
expect(session).to receive(:execute).with(Cassandra::Statements::Simple.new("SELECT COUNT(*) FROM dual"), {:consistency => :local_quorum})
|
202
|
+
expect(session).to receive(:execute).with(Cassandra::Statements::Simple.new("SELECT COUNT(1) FROM dual"), {:consistency => :local_one})
|
203
|
+
instance.execute("SELECT COUNT(1) FROM dual", nil)
|
204
|
+
expect(instance.current_consistency).to eq :local_one
|
205
|
+
|
206
|
+
begin
|
207
|
+
instance.consistency = :local_quorum
|
208
|
+
expect(instance.current_consistency).to eq :local_quorum
|
209
|
+
instance.execute("SELECT COUNT(*) FROM dual", nil)
|
210
|
+
Cassie.consistency(:one) do
|
211
|
+
instance.execute("SELECT * FROM dual", nil)
|
212
|
+
expect(instance.current_consistency).to eq :one
|
213
|
+
end
|
214
|
+
expect(instance.current_consistency).to eq :local_quorum
|
215
|
+
ensure
|
216
|
+
instance.consistency = :local_one
|
178
217
|
end
|
179
218
|
end
|
180
219
|
end
|
data/spec/models/thing.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -16,7 +16,13 @@ RSpec.configure do |config|
|
|
16
16
|
|
17
17
|
config.before(:suite) do
|
18
18
|
schema_dir = File.expand_path("../schema", __FILE__)
|
19
|
-
|
19
|
+
protocol_version = (ENV["protocol_version"] ? ENV["protocol_version"].to_i : 3)
|
20
|
+
Cassie.configure!(
|
21
|
+
:cluster => {:host => 'localhost', :protocol_version => protocol_version,},
|
22
|
+
:keyspaces => {"test" => "cassie_specs"},
|
23
|
+
:schema_directory => schema_dir,
|
24
|
+
:max_prepared_statements => 3
|
25
|
+
)
|
20
26
|
Cassie::Schema.load_all!
|
21
27
|
Cassie::Testing.prepare!
|
22
28
|
end
|
data/whi-cassie.gemspec
CHANGED
@@ -17,7 +17,7 @@ Gem::Specification.new do |spec|
|
|
17
17
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
18
|
spec.require_paths = ["lib"]
|
19
19
|
|
20
|
-
spec.add_dependency('cassandra-driver', '~>
|
20
|
+
spec.add_dependency('cassandra-driver', '~>3.0')
|
21
21
|
spec.add_dependency('activemodel', '~>4.0')
|
22
22
|
|
23
23
|
spec.add_development_dependency "bundler", "~>1.3"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: whi-cassie
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- We Heart It
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2017-07-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: cassandra-driver
|
@@ -17,14 +17,14 @@ dependencies:
|
|
17
17
|
requirements:
|
18
18
|
- - "~>"
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version:
|
20
|
+
version: '3.0'
|
21
21
|
type: :runtime
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
25
|
- - "~>"
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
-
version:
|
27
|
+
version: '3.0'
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: activemodel
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
@@ -89,7 +89,7 @@ extensions: []
|
|
89
89
|
extra_rdoc_files: []
|
90
90
|
files:
|
91
91
|
- ".gitignore"
|
92
|
-
- HISTORY.
|
92
|
+
- HISTORY.md
|
93
93
|
- MIT-LICENSE
|
94
94
|
- README.md
|
95
95
|
- Rakefile
|
@@ -131,7 +131,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
131
131
|
version: '0'
|
132
132
|
requirements: []
|
133
133
|
rubyforge_project:
|
134
|
-
rubygems_version: 2.
|
134
|
+
rubygems_version: 2.6.12
|
135
135
|
signing_key:
|
136
136
|
specification_version: 4
|
137
137
|
summary: Simple object mapper for Cassandra data tables specifically designed to work
|
data/HISTORY.txt
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
1.0.7
|
2
|
-
|
3
|
-
Add find_subscribers to Cassie::Model for instrumenting model find calls.
|
4
|
-
|
5
|
-
1.0.6
|
6
|
-
|
7
|
-
Wrap raw CQL in a Simple statement for code consistency in subscribers.
|
8
|
-
|
9
|
-
1.0.5
|
10
|
-
|
11
|
-
Add subscribers for instumenting code.
|
12
|
-
|
13
|
-
Remove hardcoded log warnings for long running statements since this can now be better handled with instrumentation.
|
14
|
-
|
15
|
-
1.0.4
|
16
|
-
|
17
|
-
Set less cryptic error message for invalid records exceptions.
|
18
|
-
|
19
|
-
1.0.3
|
20
|
-
|
21
|
-
Fix bugs preventing counter and set data types from working on models.
|
22
|
-
|
23
|
-
1.0.2
|
24
|
-
|
25
|
-
Set cluster logger on the Cassandra cluster if not already set.
|
26
|
-
|
27
|
-
1.0.1
|
28
|
-
|
29
|
-
Allow finding the offset to the row from a range.
|
30
|
-
|
31
|
-
1.0.0
|
32
|
-
|
33
|
-
Initial Release
|