cassandra 0.11.0 → 0.11.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +10 -0
- data/LICENSE +0 -0
- data/Manifest +12 -13
- data/README.md +344 -0
- data/Rakefile +52 -8
- data/cassandra.gemspec +5 -5
- data/conf/0.6/cassandra.in.sh +0 -0
- data/conf/0.6/log4j.properties +0 -0
- data/conf/0.6/schema.json +9 -0
- data/conf/0.6/storage-conf.xml +10 -0
- data/conf/0.7/cassandra.in.sh +0 -0
- data/conf/0.7/cassandra.yaml +0 -0
- data/conf/0.7/log4j-server.properties +0 -0
- data/conf/0.7/schema.json +9 -0
- data/conf/0.7/schema.txt +5 -16
- data/conf/0.8/cassandra.in.sh +0 -0
- data/conf/0.8/cassandra.yaml +1 -1
- data/conf/0.8/log4j-server.properties +0 -0
- data/conf/0.8/schema.json +19 -1
- data/conf/0.8/schema.txt +12 -17
- data/lib/cassandra.rb +3 -2
- data/lib/cassandra/0.6.rb +0 -0
- data/lib/cassandra/0.6/cassandra.rb +57 -6
- data/lib/cassandra/0.6/columns.rb +19 -0
- data/lib/cassandra/0.6/protocol.rb +2 -1
- data/lib/cassandra/0.7.rb +0 -0
- data/lib/cassandra/0.7/cassandra.rb +0 -270
- data/lib/cassandra/0.7/columns.rb +1 -81
- data/lib/cassandra/0.7/protocol.rb +0 -112
- data/lib/cassandra/0.8.rb +0 -0
- data/lib/cassandra/0.8/cassandra.rb +5 -267
- data/lib/cassandra/0.8/columns.rb +1 -81
- data/lib/cassandra/0.8/protocol.rb +9 -103
- data/lib/cassandra/array.rb +0 -0
- data/lib/cassandra/cassandra.rb +715 -92
- data/lib/cassandra/{0.7/column_family.rb → column_family.rb} +0 -0
- data/lib/cassandra/columns.rb +63 -6
- data/lib/cassandra/comparable.rb +0 -0
- data/lib/cassandra/constants.rb +0 -0
- data/lib/cassandra/debug.rb +0 -0
- data/lib/cassandra/helpers.rb +0 -0
- data/lib/cassandra/{0.7/keyspace.rb → keyspace.rb} +0 -0
- data/lib/cassandra/long.rb +0 -0
- data/lib/cassandra/mock.rb +45 -8
- data/lib/cassandra/ordered_hash.rb +0 -0
- data/lib/cassandra/protocol.rb +119 -0
- data/lib/cassandra/time.rb +0 -0
- data/test/cassandra_client_test.rb +0 -0
- data/test/cassandra_mock_test.rb +3 -0
- data/test/cassandra_test.rb +202 -20
- data/test/comparable_types_test.rb +0 -0
- data/test/eventmachine_test.rb +0 -0
- data/test/ordered_hash_test.rb +0 -0
- data/test/test_helper.rb +1 -1
- data/vendor/0.6/gen-rb/cassandra.rb +0 -0
- data/vendor/0.6/gen-rb/cassandra_constants.rb +0 -0
- data/vendor/0.6/gen-rb/cassandra_types.rb +0 -0
- data/vendor/0.7/gen-rb/cassandra.rb +0 -0
- data/vendor/0.7/gen-rb/cassandra_constants.rb +0 -0
- data/vendor/0.7/gen-rb/cassandra_types.rb +0 -0
- data/vendor/0.8/gen-rb/cassandra.rb +0 -0
- data/vendor/0.8/gen-rb/cassandra_constants.rb +0 -0
- data/vendor/0.8/gen-rb/cassandra_types.rb +0 -0
- metadata +27 -29
- data/README.rdoc +0 -99
- data/lib/cassandra/0.8/column_family.rb +0 -3
- data/lib/cassandra/0.8/keyspace.rb +0 -3
data/cassandra.gemspec
CHANGED
@@ -2,18 +2,18 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{cassandra}
|
5
|
-
s.version = "0.11.
|
5
|
+
s.version = "0.11.1"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0.8") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Evan Weaver, Ryan King"]
|
9
|
-
s.date = %q{2011-
|
9
|
+
s.date = %q{2011-06-01}
|
10
10
|
s.description = %q{A Ruby client for the Cassandra distributed database.}
|
11
11
|
s.email = %q{}
|
12
12
|
s.executables = ["cassandra_helper"]
|
13
|
-
s.extra_rdoc_files = ["
|
14
|
-
s.files = ["
|
13
|
+
s.extra_rdoc_files = ["CHANGELOG", "LICENSE", "README.md", "bin/cassandra_helper", "lib/cassandra.rb", "lib/cassandra/0.6.rb", "lib/cassandra/0.6/cassandra.rb", "lib/cassandra/0.6/columns.rb", "lib/cassandra/0.6/protocol.rb", "lib/cassandra/0.7.rb", "lib/cassandra/0.7/cassandra.rb", "lib/cassandra/0.7/columns.rb", "lib/cassandra/0.7/protocol.rb", "lib/cassandra/0.8.rb", "lib/cassandra/0.8/cassandra.rb", "lib/cassandra/0.8/columns.rb", "lib/cassandra/0.8/protocol.rb", "lib/cassandra/array.rb", "lib/cassandra/cassandra.rb", "lib/cassandra/column_family.rb", "lib/cassandra/columns.rb", "lib/cassandra/comparable.rb", "lib/cassandra/constants.rb", "lib/cassandra/debug.rb", "lib/cassandra/helpers.rb", "lib/cassandra/keyspace.rb", "lib/cassandra/long.rb", "lib/cassandra/mock.rb", "lib/cassandra/ordered_hash.rb", "lib/cassandra/protocol.rb", "lib/cassandra/time.rb"]
|
14
|
+
s.files = ["CHANGELOG", "LICENSE", "Manifest", "README.md", "Rakefile", "bin/cassandra_helper", "conf/0.6/cassandra.in.sh", "conf/0.6/log4j.properties", "conf/0.6/schema.json", "conf/0.6/storage-conf.xml", "conf/0.7/cassandra.in.sh", "conf/0.7/cassandra.yaml", "conf/0.7/log4j-server.properties", "conf/0.7/schema.json", "conf/0.7/schema.txt", "conf/0.8/cassandra.in.sh", "conf/0.8/cassandra.yaml", "conf/0.8/log4j-server.properties", "conf/0.8/schema.json", "conf/0.8/schema.txt", "lib/cassandra.rb", "lib/cassandra/0.6.rb", "lib/cassandra/0.6/cassandra.rb", "lib/cassandra/0.6/columns.rb", "lib/cassandra/0.6/protocol.rb", "lib/cassandra/0.7.rb", "lib/cassandra/0.7/cassandra.rb", "lib/cassandra/0.7/columns.rb", "lib/cassandra/0.7/protocol.rb", "lib/cassandra/0.8.rb", "lib/cassandra/0.8/cassandra.rb", "lib/cassandra/0.8/columns.rb", "lib/cassandra/0.8/protocol.rb", "lib/cassandra/array.rb", "lib/cassandra/cassandra.rb", "lib/cassandra/column_family.rb", "lib/cassandra/columns.rb", "lib/cassandra/comparable.rb", "lib/cassandra/constants.rb", "lib/cassandra/debug.rb", "lib/cassandra/helpers.rb", "lib/cassandra/keyspace.rb", "lib/cassandra/long.rb", "lib/cassandra/mock.rb", "lib/cassandra/ordered_hash.rb", "lib/cassandra/protocol.rb", "lib/cassandra/time.rb", "test/cassandra_client_test.rb", "test/cassandra_mock_test.rb", "test/cassandra_test.rb", "test/comparable_types_test.rb", "test/eventmachine_test.rb", "test/ordered_hash_test.rb", "test/test_helper.rb", "vendor/0.6/gen-rb/cassandra.rb", "vendor/0.6/gen-rb/cassandra_constants.rb", "vendor/0.6/gen-rb/cassandra_types.rb", "vendor/0.7/gen-rb/cassandra.rb", "vendor/0.7/gen-rb/cassandra_constants.rb", "vendor/0.7/gen-rb/cassandra_types.rb", "vendor/0.8/gen-rb/cassandra.rb", "vendor/0.8/gen-rb/cassandra_constants.rb", "vendor/0.8/gen-rb/cassandra_types.rb", "cassandra.gemspec"]
|
15
15
|
s.homepage = %q{http://fauna.github.com/fauna/cassandra/}
|
16
|
-
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Cassandra", "--main", "README.
|
16
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Cassandra", "--main", "README.md"]
|
17
17
|
s.require_paths = ["lib"]
|
18
18
|
s.rubyforge_project = %q{fauna}
|
19
19
|
s.rubygems_version = %q{1.7.2}
|
data/conf/0.6/cassandra.in.sh
CHANGED
File without changes
|
data/conf/0.6/log4j.properties
CHANGED
File without changes
|
data/conf/0.6/schema.json
CHANGED
@@ -44,5 +44,14 @@
|
|
44
44
|
"Comments":{
|
45
45
|
"CompareWith":"org.apache.cassandra.db.marshal.LongType",
|
46
46
|
"Type":"Standard"}
|
47
|
+
},
|
48
|
+
"TypeConversions":{
|
49
|
+
"UUIDColumnConversion":{
|
50
|
+
"CompareWith":"org.apache.cassandra.db.marshal.TimeUUIDType",
|
51
|
+
"Type":"Standard"},
|
52
|
+
"SuperUUID":{
|
53
|
+
"CompareSubcolumnsWith":"org.apache.cassandra.db.marshal.TimeUUIDType",
|
54
|
+
"CompareWith":"org.apache.cassandra.db.marshal.TimeUUIDType",
|
55
|
+
"Type":"Super"}
|
47
56
|
}
|
48
57
|
}
|
data/conf/0.6/storage-conf.xml
CHANGED
@@ -91,6 +91,16 @@
|
|
91
91
|
<EndPointSnitch>org.apache.cassandra.locator.EndPointSnitch</EndPointSnitch>
|
92
92
|
</Keyspace>
|
93
93
|
|
94
|
+
<Keyspace Name="TypeConversions">
|
95
|
+
<KeysCachedFraction>0.01</KeysCachedFraction>
|
96
|
+
<ColumnFamily CompareWith="TimeUUIDType" Name="UUIDColumnConversion"/>
|
97
|
+
<ColumnFamily CompareWith="TimeUUIDType" CompareSubcolumnsWith="UTF8Type" ColumnType="Super" Name="SuperUUID"/>
|
98
|
+
|
99
|
+
<ReplicaPlacementStrategy>org.apache.cassandra.locator.RackUnawareStrategy</ReplicaPlacementStrategy>
|
100
|
+
<ReplicationFactor>1</ReplicationFactor>
|
101
|
+
<EndPointSnitch>org.apache.cassandra.locator.EndPointSnitch</EndPointSnitch>
|
102
|
+
</Keyspace>
|
103
|
+
|
94
104
|
<Keyspace Name="CassandraObject">
|
95
105
|
<KeysCachedFraction>0.01</KeysCachedFraction>
|
96
106
|
<ColumnFamily CompareWith="UTF8Type" Name="Customers" />
|
data/conf/0.7/cassandra.in.sh
CHANGED
File without changes
|
data/conf/0.7/cassandra.yaml
CHANGED
File without changes
|
File without changes
|
data/conf/0.7/schema.json
CHANGED
@@ -44,5 +44,14 @@
|
|
44
44
|
"Comments":{
|
45
45
|
"comparator_type":"org.apache.cassandra.db.marshal.LongType",
|
46
46
|
"column_type":"Standard"}
|
47
|
+
},
|
48
|
+
"TypeConversions":{
|
49
|
+
"UUIDColumnConversion":{
|
50
|
+
"comparator_type":"org.apache.cassandra.db.marshal.TimeUUIDType",
|
51
|
+
"column_type":"Standard"},
|
52
|
+
"SuperUUID":{
|
53
|
+
"subcomparator_type":"org.apache.cassandra.db.marshal.TimeUUIDType",
|
54
|
+
"comparator_type":"org.apache.cassandra.db.marshal.TimeUUIDType",
|
55
|
+
"column_type":"Super"}
|
47
56
|
}
|
48
57
|
}
|
data/conf/0.7/schema.txt
CHANGED
@@ -36,21 +36,10 @@ use MultiblogLong;
|
|
36
36
|
create column family Blogs with comparator = 'LongType';
|
37
37
|
create column family Comments with comparator = 'LongType';
|
38
38
|
|
39
|
-
create keyspace
|
39
|
+
create keyspace TypeConversions with
|
40
40
|
placement_strategy = 'org.apache.cassandra.locator.SimpleStrategy' AND
|
41
41
|
replication_factor = 1;
|
42
|
-
use
|
43
|
-
create column family
|
44
|
-
create column family
|
45
|
-
|
46
|
-
column_type = 'Super' AND
|
47
|
-
subcomparator = 'TimeUUIDType';
|
48
|
-
create column family CustomersByLastName with comparator = 'TimeUUIDType';
|
49
|
-
create column family Invoices with comparator = 'UTF8Type';
|
50
|
-
create column family InvoiceRelationships with
|
51
|
-
comparator = 'UTF8Type' AND
|
52
|
-
column_type = 'Super' AND
|
53
|
-
subcomparator = 'TimeUUIDType';
|
54
|
-
create column family InvoicesByNumber with comparator = 'UTF8Type';
|
55
|
-
create column family Payments with comparator = 'UTF8Type';
|
56
|
-
create column family Appointments with comparator = 'UTF8Type';
|
42
|
+
use TypeConversions;
|
43
|
+
create column family UUIDColumnConversion with comparator = TimeUUIDType;
|
44
|
+
create column family SuperUUID with comparator = TimeUUIDType and column_type = Super;
|
45
|
+
|
data/conf/0.8/cassandra.in.sh
CHANGED
File without changes
|
data/conf/0.8/cassandra.yaml
CHANGED
@@ -42,7 +42,7 @@ incremental_backups: false
|
|
42
42
|
snapshot_before_compaction: false
|
43
43
|
column_index_size_in_kb: 64
|
44
44
|
in_memory_compaction_limit_in_mb: 64
|
45
|
-
|
45
|
+
concurrent_compactors: 1
|
46
46
|
compaction_throughput_mb_per_sec: 16
|
47
47
|
compaction_preheat_key_cache: true
|
48
48
|
rpc_timeout_in_ms: 10000
|
File without changes
|
data/conf/0.8/schema.json
CHANGED
@@ -5,7 +5,16 @@
|
|
5
5
|
"UserAudits":{
|
6
6
|
"comparator_type":"org.apache.cassandra.db.marshal.UTF8Type",
|
7
7
|
"column_type":"Standard"},
|
8
|
-
"
|
8
|
+
"UserCounters":{
|
9
|
+
"comparator_type":"org.apache.cassandra.db.marshal.UTF8Type",
|
10
|
+
"column_type":"Standard",
|
11
|
+
"default_validation_class":"CounterColumnType"},
|
12
|
+
"UserCounterAggregates":{
|
13
|
+
"subcomparator_type":"org.apache.cassandra.db.marshal.UTF8Type",
|
14
|
+
"comparator_type":"org.apache.cassandra.db.marshal.UTF8Type",
|
15
|
+
"column_type":"Super",
|
16
|
+
"default_validation_class":"CounterColumnType"},
|
17
|
+
"UserRelationships":{
|
9
18
|
"subcomparator_type":"org.apache.cassandra.db.marshal.TimeUUIDType",
|
10
19
|
"comparator_type":"org.apache.cassandra.db.marshal.UTF8Type",
|
11
20
|
"column_type":"Super"},
|
@@ -44,5 +53,14 @@
|
|
44
53
|
"Comments":{
|
45
54
|
"comparator_type":"org.apache.cassandra.db.marshal.LongType",
|
46
55
|
"column_type":"Standard"}
|
56
|
+
},
|
57
|
+
"TypeConversions":{
|
58
|
+
"UUIDColumnConversion":{
|
59
|
+
"comparator_type":"org.apache.cassandra.db.marshal.TimeUUIDType",
|
60
|
+
"column_type":"Standard"},
|
61
|
+
"SuperUUID":{
|
62
|
+
"subcomparator_type":"org.apache.cassandra.db.marshal.TimeUUIDType",
|
63
|
+
"comparator_type":"org.apache.cassandra.db.marshal.TimeUUIDType",
|
64
|
+
"column_type":"Super"}
|
47
65
|
}
|
48
66
|
}
|
data/conf/0.8/schema.txt
CHANGED
@@ -4,7 +4,13 @@ create keyspace Twitter with
|
|
4
4
|
use Twitter;
|
5
5
|
create column family Users with comparator = 'UTF8Type';
|
6
6
|
create column family UserAudits with comparator = 'UTF8Type';
|
7
|
-
create column family
|
7
|
+
create column family UserCounters with comparator = 'UTF8Type' and
|
8
|
+
default_validation_class = CounterColumnType;
|
9
|
+
create column family UserCounterAggregates with column_type = 'Super'
|
10
|
+
and comparator = 'UTF8Type' and
|
11
|
+
subcomparator = 'UTF8Type' and
|
12
|
+
default_validation_class = CounterColumnType;
|
13
|
+
create column family UserRelationships with
|
8
14
|
comparator = 'UTF8Type' and
|
9
15
|
column_type = 'Super' and
|
10
16
|
subcomparator = 'TimeUUIDType';
|
@@ -36,21 +42,10 @@ use MultiblogLong;
|
|
36
42
|
create column family Blogs with comparator = 'LongType';
|
37
43
|
create column family Comments with comparator = 'LongType';
|
38
44
|
|
39
|
-
create keyspace
|
45
|
+
create keyspace TypeConversions with
|
40
46
|
placement_strategy = 'org.apache.cassandra.locator.LocalStrategy' AND
|
41
47
|
strategy_options = [{replication_factor:1}];
|
42
|
-
use
|
43
|
-
create column family
|
44
|
-
create column family
|
45
|
-
|
46
|
-
column_type = 'Super' AND
|
47
|
-
subcomparator = 'TimeUUIDType';
|
48
|
-
create column family CustomersByLastName with comparator = 'TimeUUIDType';
|
49
|
-
create column family Invoices with comparator = 'UTF8Type';
|
50
|
-
create column family InvoiceRelationships with
|
51
|
-
comparator = 'UTF8Type' AND
|
52
|
-
column_type = 'Super' AND
|
53
|
-
subcomparator = 'TimeUUIDType';
|
54
|
-
create column family InvoicesByNumber with comparator = 'UTF8Type';
|
55
|
-
create column family Payments with comparator = 'UTF8Type';
|
56
|
-
create column family Appointments with comparator = 'UTF8Type';
|
48
|
+
use TypeConversions;
|
49
|
+
create column family UUIDColumnConversion with comparator = TimeUUIDType;
|
50
|
+
create column family SuperUUID with comparator = TimeUUIDType and column_type = Super;
|
51
|
+
|
data/lib/cassandra.rb
CHANGED
@@ -25,13 +25,14 @@ require 'cassandra/comparable'
|
|
25
25
|
require 'cassandra/long'
|
26
26
|
require 'cassandra/ordered_hash'
|
27
27
|
require 'cassandra/columns'
|
28
|
+
require 'cassandra/protocol'
|
28
29
|
require "cassandra/#{Cassandra.VERSION}/columns"
|
29
30
|
require "cassandra/#{Cassandra.VERSION}/protocol"
|
30
31
|
require "cassandra/cassandra"
|
31
32
|
require "cassandra/#{Cassandra.VERSION}/cassandra"
|
32
33
|
unless Cassandra.VERSION.eql?("0.6")
|
33
|
-
require "cassandra
|
34
|
-
require "cassandra
|
34
|
+
require "cassandra/column_family"
|
35
|
+
require "cassandra/keyspace"
|
35
36
|
end
|
36
37
|
require 'cassandra/constants'
|
37
38
|
require 'cassandra/debug' if ENV['DEBUG']
|
data/lib/cassandra/0.6.rb
CHANGED
File without changes
|
@@ -2,13 +2,40 @@ class Cassandra
|
|
2
2
|
def self.DEFAULT_TRANSPORT_WRAPPER
|
3
3
|
Thrift::BufferedTransport
|
4
4
|
end
|
5
|
-
|
6
|
-
## Delete
|
7
5
|
|
8
|
-
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
6
|
+
##
|
7
|
+
# Issues a login attempt using the username and password specified.
|
8
|
+
#
|
9
|
+
# * username
|
10
|
+
# * password
|
11
|
+
#
|
12
|
+
def login!(username, password)
|
13
|
+
@auth_request = CassandraThrift::AuthenticationRequest.new
|
14
|
+
@auth_request.credentials = {'username' => username, 'password' => password}
|
15
|
+
client.login(@keyspace, @auth_request)
|
16
|
+
end
|
17
|
+
|
18
|
+
def inspect
|
19
|
+
"#<Cassandra:#{object_id}, @keyspace=#{keyspace.inspect}, @schema={#{
|
20
|
+
schema(false).map {|name, hash| ":#{name} => #{hash['type'].inspect}"}.join(', ')
|
21
|
+
}}, @servers=#{servers.inspect}>"
|
22
|
+
end
|
23
|
+
|
24
|
+
##
|
25
|
+
# Returns an array of available keyspaces.
|
26
|
+
#
|
27
|
+
def keyspaces
|
28
|
+
@keyspaces ||= client.describe_keyspaces()
|
29
|
+
end
|
30
|
+
|
31
|
+
##
|
32
|
+
# Remove all rows in the column family you request.
|
33
|
+
#
|
34
|
+
# * column_family
|
35
|
+
# * options
|
36
|
+
# * consitency
|
37
|
+
# * timestamp
|
38
|
+
#
|
12
39
|
def clear_column_family!(column_family, options = {})
|
13
40
|
each_key(column_family) do |key|
|
14
41
|
remove(column_family, key, options)
|
@@ -24,6 +51,30 @@ class Cassandra
|
|
24
51
|
schema.keys.each { |column_family| clear_column_family!(column_family, options) }
|
25
52
|
end
|
26
53
|
|
54
|
+
# Open a batch operation and yield self. Inserts and deletes will be queued
|
55
|
+
# until the block closes, and then sent atomically to the server. Supports
|
56
|
+
# the <tt>:consistency</tt> option, which overrides the consistency set in
|
57
|
+
# the individual commands.
|
58
|
+
def batch(options = {})
|
59
|
+
_, _, _, options =
|
60
|
+
extract_and_validate_params(schema.keys.first, "", [options], WRITE_DEFAULTS)
|
61
|
+
|
62
|
+
@batch = []
|
63
|
+
yield(self)
|
64
|
+
compacted_map,seen_clevels = compact_mutations!
|
65
|
+
clevel = if options[:consistency] != nil # Override any clevel from individual mutations if
|
66
|
+
options[:consistency]
|
67
|
+
elsif seen_clevels.length > 1 # Cannot choose which CLevel to use if there are several ones
|
68
|
+
raise "Multiple consistency levels used in the batch, and no override...cannot pick one"
|
69
|
+
else # if no consistency override has been provided but all the clevels in the batch are the same: use that one
|
70
|
+
seen_clevels.first
|
71
|
+
end
|
72
|
+
|
73
|
+
_mutate(compacted_map,clevel)
|
74
|
+
ensure
|
75
|
+
@batch = nil
|
76
|
+
end
|
77
|
+
|
27
78
|
protected
|
28
79
|
|
29
80
|
def schema(load=true)
|
@@ -3,6 +3,25 @@ class Cassandra
|
|
3
3
|
module Columns #:nodoc:
|
4
4
|
private
|
5
5
|
|
6
|
+
def is_super(column_family)
|
7
|
+
@is_super[column_family] ||= column_family_property(column_family, 'Type') == "Super"
|
8
|
+
end
|
9
|
+
|
10
|
+
def column_name_class(column_family)
|
11
|
+
@column_name_class[column_family] ||= column_name_class_for_key(column_family, "CompareWith")
|
12
|
+
end
|
13
|
+
|
14
|
+
def sub_column_name_class(column_family)
|
15
|
+
@sub_column_name_class[column_family] ||= column_name_class_for_key(column_family, "CompareSubcolumnsWith")
|
16
|
+
end
|
17
|
+
|
18
|
+
def column_family_property(column_family, key)
|
19
|
+
unless schema[column_family]
|
20
|
+
raise AccessError, "Invalid column family \"#{column_family}\""
|
21
|
+
end
|
22
|
+
schema[column_family][key]
|
23
|
+
end
|
24
|
+
|
6
25
|
def _standard_insert_mutation(column_family, column_name, value, timestamp, _=nil)
|
7
26
|
CassandraThrift::Mutation.new(
|
8
27
|
:column_or_supercolumn => CassandraThrift::ColumnOrSuperColumn.new(
|
@@ -19,6 +19,7 @@ class Cassandra
|
|
19
19
|
)
|
20
20
|
end
|
21
21
|
|
22
|
+
# FIXME: add support for start, stop, count functionality
|
22
23
|
def _get_columns(column_family, key, columns, sub_columns, consistency)
|
23
24
|
result = if is_super(column_family)
|
24
25
|
if sub_columns
|
@@ -60,7 +61,7 @@ class Cassandra
|
|
60
61
|
:count => count,
|
61
62
|
:start => start,
|
62
63
|
:finish => finish))
|
63
|
-
|
64
|
+
|
64
65
|
if is_super(column_family) and column
|
65
66
|
column_parent = CassandraThrift::ColumnParent.new(:column_family => column_family, :super_column => column)
|
66
67
|
multi_sub_columns_to_hash!(column_family, client.multiget_slice(@keyspace, keys, column_parent, predicate, consistency))
|
data/lib/cassandra/0.7.rb
CHANGED
File without changes
|
@@ -1,272 +1,2 @@
|
|
1
1
|
class Cassandra
|
2
|
-
|
3
|
-
def self.DEFAULT_TRANSPORT_WRAPPER
|
4
|
-
Thrift::FramedTransport
|
5
|
-
end
|
6
|
-
|
7
|
-
def login!(username, password)
|
8
|
-
@auth_request = CassandraThrift::AuthenticationRequest.new
|
9
|
-
@auth_request.credentials = {'username' => username, 'password' => password}
|
10
|
-
client.login(@auth_request)
|
11
|
-
end
|
12
|
-
|
13
|
-
def inspect
|
14
|
-
"#<Cassandra:#{object_id}, @keyspace=#{keyspace.inspect}, @schema={#{
|
15
|
-
Array(schema(false).cf_defs).map {|cfdef| ":#{cfdef.name} => #{cfdef.column_type}"}.join(', ')
|
16
|
-
}}, @servers=#{servers.inspect}>"
|
17
|
-
end
|
18
|
-
|
19
|
-
def keyspace=(ks)
|
20
|
-
client.set_keyspace(ks)
|
21
|
-
@schema = nil; @keyspace = ks
|
22
|
-
end
|
23
|
-
|
24
|
-
def keyspaces
|
25
|
-
client.describe_keyspaces.to_a.collect {|ksdef| ksdef.name }
|
26
|
-
end
|
27
|
-
|
28
|
-
def schema(load=true)
|
29
|
-
if !load && !@schema
|
30
|
-
Cassandra::Keyspace.new
|
31
|
-
else
|
32
|
-
@schema ||= client.describe_keyspace(@keyspace)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def schema_agreement?
|
37
|
-
client.describe_schema_versions().length == 1
|
38
|
-
end
|
39
|
-
|
40
|
-
def version
|
41
|
-
client.describe_version()
|
42
|
-
end
|
43
|
-
|
44
|
-
def cluster_name
|
45
|
-
@cluster_name ||= client.describe_cluster_name()
|
46
|
-
end
|
47
|
-
|
48
|
-
def ring
|
49
|
-
client.describe_ring(@keyspace)
|
50
|
-
end
|
51
|
-
|
52
|
-
def partitioner
|
53
|
-
client.describe_partitioner()
|
54
|
-
end
|
55
|
-
|
56
|
-
## Delete
|
57
|
-
|
58
|
-
# Remove all rows in the column family you request.
|
59
|
-
def truncate!(column_family)
|
60
|
-
client.truncate(column_family.to_s)
|
61
|
-
end
|
62
|
-
alias clear_column_family! truncate!
|
63
|
-
|
64
|
-
# Remove all rows in the keyspace.
|
65
|
-
def clear_keyspace!
|
66
|
-
schema.cf_defs.each { |cfdef| truncate!(cfdef.name) }
|
67
|
-
end
|
68
|
-
|
69
|
-
### Read
|
70
|
-
|
71
|
-
def add_column_family(cf_def)
|
72
|
-
begin
|
73
|
-
res = client.system_add_column_family(cf_def)
|
74
|
-
rescue CassandraThrift::TimedOutException => te
|
75
|
-
puts "Timed out: #{te.inspect}"
|
76
|
-
end
|
77
|
-
@schema = nil
|
78
|
-
res
|
79
|
-
end
|
80
|
-
|
81
|
-
def drop_column_family(cf_name)
|
82
|
-
begin
|
83
|
-
res = client.system_drop_column_family(cf_name)
|
84
|
-
rescue CassandraThrift::TimedOutException => te
|
85
|
-
puts "Timed out: #{te.inspect}"
|
86
|
-
end
|
87
|
-
@schema = nil
|
88
|
-
res
|
89
|
-
end
|
90
|
-
|
91
|
-
def rename_column_family(old_name, new_name)
|
92
|
-
begin
|
93
|
-
res = client.system_rename_column_family(old_name, new_name)
|
94
|
-
rescue CassandraThrift::TimedOutException => te
|
95
|
-
puts "Timed out: #{te.inspect}"
|
96
|
-
end
|
97
|
-
@schema = nil
|
98
|
-
res
|
99
|
-
end
|
100
|
-
|
101
|
-
def update_column_family(cf_def)
|
102
|
-
begin
|
103
|
-
res = client.system_update_column_family(cf_def)
|
104
|
-
rescue CassandraThrift::TimedOutException => te
|
105
|
-
puts "Timed out: #{te.inspect}"
|
106
|
-
end
|
107
|
-
@schema = nil
|
108
|
-
res
|
109
|
-
end
|
110
|
-
|
111
|
-
def add_keyspace(ks_def)
|
112
|
-
begin
|
113
|
-
res = client.system_add_keyspace(ks_def)
|
114
|
-
rescue CassandraThrift::TimedOutException => toe
|
115
|
-
puts "Timed out: #{toe.inspect}"
|
116
|
-
rescue Thrift::TransportException => te
|
117
|
-
puts "Timed out: #{te.inspect}"
|
118
|
-
end
|
119
|
-
@keyspaces = nil
|
120
|
-
res
|
121
|
-
end
|
122
|
-
|
123
|
-
def drop_keyspace(ks_name)
|
124
|
-
begin
|
125
|
-
res = client.system_drop_keyspace(ks_name)
|
126
|
-
rescue CassandraThrift::TimedOutException => toe
|
127
|
-
puts "Timed out: #{toe.inspect}"
|
128
|
-
rescue Thrift::TransportException => te
|
129
|
-
puts "Timed out: #{te.inspect}"
|
130
|
-
end
|
131
|
-
keyspace = "system" if ks_name.eql?(@keyspace)
|
132
|
-
@keyspaces = nil
|
133
|
-
res
|
134
|
-
end
|
135
|
-
|
136
|
-
def rename_keyspace(old_name, new_name)
|
137
|
-
begin
|
138
|
-
res = client.system_rename_keyspace(old_name, new_name)
|
139
|
-
rescue CassandraThrift::TimedOutException => toe
|
140
|
-
puts "Timed out: #{toe.inspect}"
|
141
|
-
rescue Thrift::TransportException => te
|
142
|
-
puts "Timed out: #{te.inspect}"
|
143
|
-
end
|
144
|
-
keyspace = new_name if old_name.eql?(@keyspace)
|
145
|
-
@keyspaces = nil
|
146
|
-
res
|
147
|
-
end
|
148
|
-
|
149
|
-
def update_keyspace(ks_def)
|
150
|
-
begin
|
151
|
-
res = client.system_update_keyspace(ks_def)
|
152
|
-
rescue CassandraThrift::TimedOutException => toe
|
153
|
-
puts "Timed out: #{toe.inspect}"
|
154
|
-
rescue Thrift::TransportException => te
|
155
|
-
puts "Timed out: #{te.inspect}"
|
156
|
-
end
|
157
|
-
@keyspaces = nil
|
158
|
-
res
|
159
|
-
end
|
160
|
-
|
161
|
-
# Open a batch operation and yield self. Inserts and deletes will be queued
|
162
|
-
# until the block closes, and then sent atomically to the server. Supports
|
163
|
-
# the <tt>:consistency</tt> option, which overrides the consistency set in
|
164
|
-
# the individual commands.
|
165
|
-
def batch(options = {})
|
166
|
-
_, _, _, options =
|
167
|
-
extract_and_validate_params(schema.cf_defs.first.name, "", [options], WRITE_DEFAULTS)
|
168
|
-
|
169
|
-
@batch = []
|
170
|
-
yield(self)
|
171
|
-
compacted_map,seen_clevels = compact_mutations!
|
172
|
-
clevel = if options[:consistency] != nil # Override any clevel from individual mutations if
|
173
|
-
options[:consistency]
|
174
|
-
elsif seen_clevels.length > 1 # Cannot choose which CLevel to use if there are several ones
|
175
|
-
raise "Multiple consistency levels used in the batch, and no override...cannot pick one"
|
176
|
-
else # if no consistency override has been provided but all the clevels in the batch are the same: use that one
|
177
|
-
seen_clevels.first
|
178
|
-
end
|
179
|
-
|
180
|
-
_mutate(compacted_map,clevel)
|
181
|
-
ensure
|
182
|
-
@batch = nil
|
183
|
-
end
|
184
|
-
|
185
|
-
### 2ary Indexing
|
186
|
-
|
187
|
-
def create_index(ks_name, cf_name, c_name, v_class)
|
188
|
-
cf_def = client.describe_keyspace(ks_name).cf_defs.find{|x| x.name == cf_name}
|
189
|
-
if !cf_def.nil? and !cf_def.column_metadata.find{|x| x.name == c_name}
|
190
|
-
c_def = CassandraThrift::ColumnDef.new do |cd|
|
191
|
-
cd.name = c_name
|
192
|
-
cd.validation_class = "org.apache.cassandra.db.marshal."+v_class
|
193
|
-
cd.index_type = CassandraThrift::IndexType::KEYS
|
194
|
-
end
|
195
|
-
cf_def.column_metadata.push(c_def)
|
196
|
-
update_column_family(cf_def)
|
197
|
-
end
|
198
|
-
end
|
199
|
-
|
200
|
-
def drop_index(ks_name, cf_name, c_name)
|
201
|
-
cf_def = client.describe_keyspace(ks_name).cf_defs.find{|x| x.name == cf_name}
|
202
|
-
if !cf_def.nil? and cf_def.column_metadata.find{|x| x.name == c_name}
|
203
|
-
cf_def.column_metadata.delete_if{|x| x.name == c_name}
|
204
|
-
update_column_family(cf_def)
|
205
|
-
end
|
206
|
-
end
|
207
|
-
|
208
|
-
def create_idx_expr(c_name, value, op)
|
209
|
-
CassandraThrift::IndexExpression.new(
|
210
|
-
:column_name => c_name,
|
211
|
-
:value => value,
|
212
|
-
:op => (case op
|
213
|
-
when nil, "EQ", "eq", "=="
|
214
|
-
CassandraThrift::IndexOperator::EQ
|
215
|
-
when "GTE", "gte", ">="
|
216
|
-
CassandraThrift::IndexOperator::GTE
|
217
|
-
when "GT", "gt", ">"
|
218
|
-
CassandraThrift::IndexOperator::GT
|
219
|
-
when "LTE", "lte", "<="
|
220
|
-
CassandraThrift::IndexOperator::LTE
|
221
|
-
when "LT", "lt", "<"
|
222
|
-
CassandraThrift::IndexOperator::LT
|
223
|
-
end ))
|
224
|
-
end
|
225
|
-
|
226
|
-
def create_idx_clause(idx_expressions, start = "")
|
227
|
-
CassandraThrift::IndexClause.new(
|
228
|
-
:start_key => start,
|
229
|
-
:expressions => idx_expressions)
|
230
|
-
end
|
231
|
-
|
232
|
-
# TODO: Supercolumn support.
|
233
|
-
def get_indexed_slices(column_family, idx_clause, *columns_and_options)
|
234
|
-
column_family, columns, _, options =
|
235
|
-
extract_and_validate_params(column_family, [], columns_and_options, READ_DEFAULTS)
|
236
|
-
key_slices = _get_indexed_slices(column_family, idx_clause, columns, options[:count], options[:start],
|
237
|
-
options[:finish], options[:reversed], options[:consistency])
|
238
|
-
|
239
|
-
key_slices.inject({}){|h, key_slice| h[key_slice.key] = key_slice.columns; h}
|
240
|
-
end
|
241
|
-
|
242
|
-
protected
|
243
|
-
|
244
|
-
def client
|
245
|
-
if @client.nil? || @client.current_server.nil?
|
246
|
-
reconnect!
|
247
|
-
@client.set_keyspace(@keyspace)
|
248
|
-
end
|
249
|
-
@client
|
250
|
-
end
|
251
|
-
|
252
|
-
def reconnect!
|
253
|
-
@servers = all_nodes
|
254
|
-
@client = new_client
|
255
|
-
end
|
256
|
-
|
257
|
-
def all_nodes
|
258
|
-
if @auto_discover_nodes && !@keyspace.eql?("system")
|
259
|
-
temp_client = new_client
|
260
|
-
begin
|
261
|
-
ips = (temp_client.describe_ring(@keyspace).map {|range| range.endpoints}).flatten.uniq
|
262
|
-
port = @servers.first.split(':').last
|
263
|
-
ips.map{|ip| "#{ip}:#{port}" }
|
264
|
-
ensure
|
265
|
-
temp_client.disconnect!
|
266
|
-
end
|
267
|
-
else
|
268
|
-
@servers
|
269
|
-
end
|
270
|
-
end
|
271
|
-
|
272
2
|
end
|