cassandra 0.8.2 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +2 -0
- data/Manifest +18 -4
- data/README.rdoc +14 -2
- data/Rakefile +8 -4
- data/cassandra.gemspec +9 -9
- data/conf/cassandra.yaml +113 -0
- data/conf/storage-conf.xml +2 -1
- data/lib/cassandra.rb +22 -5
- data/lib/cassandra/0.6.rb +7 -0
- data/lib/cassandra/0.6/cassandra.rb +63 -0
- data/lib/cassandra/0.6/columns.rb +35 -0
- data/lib/cassandra/{protocol.rb → 0.6/protocol.rb} +2 -2
- data/lib/cassandra/0.7.rb +7 -0
- data/lib/cassandra/0.7/cassandra.rb +195 -0
- data/lib/cassandra/0.7/column_family.rb +3 -0
- data/lib/cassandra/0.7/columns.rb +59 -0
- data/lib/cassandra/0.7/keyspace.rb +3 -0
- data/lib/cassandra/0.7/protocol.rb +95 -0
- data/lib/cassandra/cassandra.rb +35 -72
- data/lib/cassandra/columns.rb +7 -35
- data/lib/cassandra/debug.rb +2 -0
- data/lib/cassandra/ordered_hash.rb +66 -7
- data/test/cassandra_test.rb +60 -4
- data/test/ordered_hash_test.rb +182 -3
- data/vendor/{gen-rb → 0.6/gen-rb}/cassandra.rb +85 -82
- data/vendor/{gen-rb → 0.6/gen-rb}/cassandra_constants.rb +0 -0
- data/vendor/{gen-rb → 0.6/gen-rb}/cassandra_types.rb +48 -45
- data/vendor/0.7/gen-rb/cassandra.rb +1936 -0
- data/vendor/0.7/gen-rb/cassandra_constants.rb +12 -0
- data/vendor/0.7/gen-rb/cassandra_types.rb +679 -0
- metadata +48 -12
data/CHANGELOG
CHANGED
data/Manifest
CHANGED
@@ -5,9 +5,20 @@ README.rdoc
|
|
5
5
|
Rakefile
|
6
6
|
bin/cassandra_helper
|
7
7
|
conf/cassandra.in.sh
|
8
|
+
conf/cassandra.yaml
|
8
9
|
conf/log4j.properties
|
9
10
|
conf/storage-conf.xml
|
10
11
|
lib/cassandra.rb
|
12
|
+
lib/cassandra/0.6.rb
|
13
|
+
lib/cassandra/0.6/cassandra.rb
|
14
|
+
lib/cassandra/0.6/columns.rb
|
15
|
+
lib/cassandra/0.6/protocol.rb
|
16
|
+
lib/cassandra/0.7.rb
|
17
|
+
lib/cassandra/0.7/cassandra.rb
|
18
|
+
lib/cassandra/0.7/column_family.rb
|
19
|
+
lib/cassandra/0.7/columns.rb
|
20
|
+
lib/cassandra/0.7/keyspace.rb
|
21
|
+
lib/cassandra/0.7/protocol.rb
|
11
22
|
lib/cassandra/array.rb
|
12
23
|
lib/cassandra/cassandra.rb
|
13
24
|
lib/cassandra/columns.rb
|
@@ -18,14 +29,17 @@ lib/cassandra/helpers.rb
|
|
18
29
|
lib/cassandra/long.rb
|
19
30
|
lib/cassandra/mock.rb
|
20
31
|
lib/cassandra/ordered_hash.rb
|
21
|
-
lib/cassandra/protocol.rb
|
22
32
|
lib/cassandra/time.rb
|
23
33
|
test/cassandra_client_test.rb
|
24
34
|
test/cassandra_mock_test.rb
|
25
35
|
test/cassandra_test.rb
|
26
36
|
test/comparable_types_test.rb
|
37
|
+
test/eventmachine_test.rb
|
27
38
|
test/ordered_hash_test.rb
|
28
39
|
test/test_helper.rb
|
29
|
-
vendor/gen-rb/cassandra.rb
|
30
|
-
vendor/gen-rb/cassandra_constants.rb
|
31
|
-
vendor/gen-rb/cassandra_types.rb
|
40
|
+
vendor/0.6/gen-rb/cassandra.rb
|
41
|
+
vendor/0.6/gen-rb/cassandra_constants.rb
|
42
|
+
vendor/0.6/gen-rb/cassandra_types.rb
|
43
|
+
vendor/0.7/gen-rb/cassandra.rb
|
44
|
+
vendor/0.7/gen-rb/cassandra_constants.rb
|
45
|
+
vendor/0.7/gen-rb/cassandra_types.rb
|
data/README.rdoc
CHANGED
@@ -4,7 +4,7 @@ A Ruby client for the Cassandra distributed database.
|
|
4
4
|
|
5
5
|
== License
|
6
6
|
|
7
|
-
Copyright 2009 Twitter, Inc. See included LICENSE file. Portions copyright 2004-2009 David Heinemeier Hansson, and used with permission.
|
7
|
+
Copyright 2009, 2010 Twitter, Inc. See included LICENSE file. Portions copyright 2004-2009 David Heinemeier Hansson, and used with permission.
|
8
8
|
|
9
9
|
== Features
|
10
10
|
|
@@ -30,14 +30,26 @@ WARNING: Don't use the test folder for your data, as it will get overwritten whe
|
|
30
30
|
|
31
31
|
== Usage
|
32
32
|
|
33
|
-
Now, start IRb and require the library:
|
33
|
+
Now, start IRb and require the library, which defaults to version 0.6 of the Cassandra API:
|
34
34
|
|
35
35
|
require 'cassandra'
|
36
36
|
|
37
|
+
Alternatively, you can specify a version of the Cassandra API to use:
|
38
|
+
|
39
|
+
require 'cassandra/0.6'
|
40
|
+
|
41
|
+
or
|
42
|
+
|
43
|
+
require 'cassandra/0.7'
|
44
|
+
|
37
45
|
Connect to a server and keyspace:
|
38
46
|
|
39
47
|
client = Cassandra.new('Twitter', '127.0.0.1:9160')
|
40
48
|
|
49
|
+
Login on server if the keyspace require authentication:
|
50
|
+
|
51
|
+
client.login!('username','password')
|
52
|
+
|
41
53
|
Insert into a column family. You can insert a `Cassandra::OrderedHash`, or a regular Hash, if order doesn't matter:
|
42
54
|
|
43
55
|
client.insert(:Users, "5", {'screen_name' => "buttonscat"})
|
data/Rakefile
CHANGED
@@ -7,7 +7,7 @@ unless ENV['FROM_BIN_CASSANDRA_HELPER']
|
|
7
7
|
p.project = "fauna"
|
8
8
|
p.summary = "A Ruby client for the Cassandra distributed database."
|
9
9
|
p.rubygems_version = ">= 0.8"
|
10
|
-
p.dependencies = ['thrift_client >=0.
|
10
|
+
p.dependencies = ['thrift_client >=0.6.0', 'json', 'rake', 'simple_uuid >=0.1.0']
|
11
11
|
p.ignore_pattern = /^(data|vendor\/cassandra|cassandra|vendor\/thrift)/
|
12
12
|
p.rdoc_pattern = /^(lib|bin|tasks|ext)|^README|^CHANGELOG|^TODO|^LICENSE|^COPYING$/
|
13
13
|
p.url = "http://blog.evanweaver.com/files/doc/fauna/cassandra/"
|
@@ -17,7 +17,7 @@ end
|
|
17
17
|
|
18
18
|
CASSANDRA_HOME = ENV['CASSANDRA_HOME'] || "#{ENV['HOME']}/cassandra"
|
19
19
|
DOWNLOAD_DIR = "/tmp"
|
20
|
-
DIST_URL = "http://
|
20
|
+
DIST_URL = "http://www.takeyellow.com/apachemirror//cassandra/0.6.8/apache-cassandra-0.6.8-bin.tar.gz"
|
21
21
|
DIST_FILE = DIST_URL.split('/').last
|
22
22
|
|
23
23
|
directory CASSANDRA_HOME
|
@@ -30,6 +30,10 @@ task :cassandra => [:java, File.join(CASSANDRA_HOME, 'server'), File.join(CASSAN
|
|
30
30
|
env << "CASSANDRA_INCLUDE=#{File.expand_path(Dir.pwd)}/conf/cassandra.in.sh "
|
31
31
|
env << "CASSANDRA_HOME=#{CASSANDRA_HOME}/server "
|
32
32
|
env << "CASSANDRA_CONF=#{File.expand_path(Dir.pwd)}/conf"
|
33
|
+
else
|
34
|
+
env << "CASSANDRA_INCLUDE=#{ENV['CASSANDRA_INCLUDE']} "
|
35
|
+
env << "CASSANDRA_HOME=#{ENV['CASSANDRA_HOME']} "
|
36
|
+
env << "CASSANDRA_CONF=#{ENV['CASSANDRA_CONF']}"
|
33
37
|
end
|
34
38
|
|
35
39
|
Dir.chdir(File.join(CASSANDRA_HOME, 'server')) do
|
@@ -65,7 +69,7 @@ namespace :data do
|
|
65
69
|
desc "Reset test data"
|
66
70
|
task :reset do
|
67
71
|
puts "Resetting test data"
|
68
|
-
|
72
|
+
sh("rm -rf #{File.join(CASSANDRA_HOME, 'server', 'data')}")
|
69
73
|
end
|
70
74
|
end
|
71
75
|
|
@@ -75,5 +79,5 @@ task :thrift do
|
|
75
79
|
system(
|
76
80
|
"cd vendor &&
|
77
81
|
rm -rf gen-rb &&
|
78
|
-
thrift -gen rb #{CASSANDRA_HOME}/
|
82
|
+
thrift -gen rb #{CASSANDRA_HOME}/interface/cassandra.thrift")
|
79
83
|
end
|
data/cassandra.gemspec
CHANGED
@@ -2,22 +2,22 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{cassandra}
|
5
|
-
s.version = "0.
|
5
|
+
s.version = "0.9.0"
|
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{2010-
|
9
|
+
s.date = %q{2010-12-08}
|
10
10
|
s.default_executable = %q{cassandra_helper}
|
11
11
|
s.description = %q{A Ruby client for the Cassandra distributed database.}
|
12
12
|
s.email = %q{}
|
13
13
|
s.executables = ["cassandra_helper"]
|
14
|
-
s.extra_rdoc_files = ["CHANGELOG", "LICENSE", "README.rdoc", "bin/cassandra_helper", "lib/cassandra.rb", "lib/cassandra/
|
15
|
-
s.files = ["CHANGELOG", "LICENSE", "Manifest", "README.rdoc", "Rakefile", "bin/cassandra_helper", "conf/cassandra.in.sh", "conf/log4j.properties", "conf/storage-conf.xml", "lib/cassandra.rb", "lib/cassandra/
|
14
|
+
s.extra_rdoc_files = ["CHANGELOG", "LICENSE", "README.rdoc", "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/column_family.rb", "lib/cassandra/0.7/columns.rb", "lib/cassandra/0.7/keyspace.rb", "lib/cassandra/0.7/protocol.rb", "lib/cassandra/array.rb", "lib/cassandra/cassandra.rb", "lib/cassandra/columns.rb", "lib/cassandra/comparable.rb", "lib/cassandra/constants.rb", "lib/cassandra/debug.rb", "lib/cassandra/helpers.rb", "lib/cassandra/long.rb", "lib/cassandra/mock.rb", "lib/cassandra/ordered_hash.rb", "lib/cassandra/time.rb"]
|
15
|
+
s.files = ["CHANGELOG", "LICENSE", "Manifest", "README.rdoc", "Rakefile", "bin/cassandra_helper", "conf/cassandra.in.sh", "conf/cassandra.yaml", "conf/log4j.properties", "conf/storage-conf.xml", "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/column_family.rb", "lib/cassandra/0.7/columns.rb", "lib/cassandra/0.7/keyspace.rb", "lib/cassandra/0.7/protocol.rb", "lib/cassandra/array.rb", "lib/cassandra/cassandra.rb", "lib/cassandra/columns.rb", "lib/cassandra/comparable.rb", "lib/cassandra/constants.rb", "lib/cassandra/debug.rb", "lib/cassandra/helpers.rb", "lib/cassandra/long.rb", "lib/cassandra/mock.rb", "lib/cassandra/ordered_hash.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", "cassandra.gemspec"]
|
16
16
|
s.homepage = %q{http://blog.evanweaver.com/files/doc/fauna/cassandra/}
|
17
17
|
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Cassandra", "--main", "README.rdoc"]
|
18
18
|
s.require_paths = ["lib"]
|
19
19
|
s.rubyforge_project = %q{fauna}
|
20
|
-
s.rubygems_version = %q{1.3.
|
20
|
+
s.rubygems_version = %q{1.3.7}
|
21
21
|
s.summary = %q{A Ruby client for the Cassandra distributed database.}
|
22
22
|
s.test_files = ["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"]
|
23
23
|
|
@@ -25,19 +25,19 @@ Gem::Specification.new do |s|
|
|
25
25
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
26
26
|
s.specification_version = 3
|
27
27
|
|
28
|
-
if Gem::Version.new(Gem::
|
29
|
-
s.add_runtime_dependency(%q<thrift_client>, [">= 0.
|
28
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
29
|
+
s.add_runtime_dependency(%q<thrift_client>, [">= 0.6.0"])
|
30
30
|
s.add_runtime_dependency(%q<json>, [">= 0"])
|
31
31
|
s.add_runtime_dependency(%q<rake>, [">= 0"])
|
32
32
|
s.add_runtime_dependency(%q<simple_uuid>, [">= 0.1.0"])
|
33
33
|
else
|
34
|
-
s.add_dependency(%q<thrift_client>, [">= 0.
|
34
|
+
s.add_dependency(%q<thrift_client>, [">= 0.6.0"])
|
35
35
|
s.add_dependency(%q<json>, [">= 0"])
|
36
36
|
s.add_dependency(%q<rake>, [">= 0"])
|
37
37
|
s.add_dependency(%q<simple_uuid>, [">= 0.1.0"])
|
38
38
|
end
|
39
39
|
else
|
40
|
-
s.add_dependency(%q<thrift_client>, [">= 0.
|
40
|
+
s.add_dependency(%q<thrift_client>, [">= 0.6.0"])
|
41
41
|
s.add_dependency(%q<json>, [">= 0"])
|
42
42
|
s.add_dependency(%q<rake>, [">= 0"])
|
43
43
|
s.add_dependency(%q<simple_uuid>, [">= 0.1.0"])
|
data/conf/cassandra.yaml
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
# Cassandra YAML generated from previous config
|
2
|
+
# Configuration wiki: http://wiki.apache.org/cassandra/StorageConfiguration
|
3
|
+
|
4
|
+
cluster_name: Test
|
5
|
+
|
6
|
+
listen_address: localhost
|
7
|
+
storage_port: 7000
|
8
|
+
rpc_port: 9160
|
9
|
+
seeds:
|
10
|
+
- 127.0.0.1
|
11
|
+
data_file_directories:
|
12
|
+
- data/cassandra/data
|
13
|
+
commitlog_directory: data/cassandra/commitlog
|
14
|
+
auto_bootstrap: false
|
15
|
+
partitioner: org.apache.cassandra.dht.RandomPartitioner
|
16
|
+
authenticator: org.apache.cassandra.auth.AllowAllAuthenticator
|
17
|
+
|
18
|
+
binary_memtable_throughput_in_mb: 256
|
19
|
+
column_index_size_in_kb: 64
|
20
|
+
commitlog_rotation_threshold_in_mb: 128
|
21
|
+
commitlog_sync: periodic
|
22
|
+
commitlog_sync_period_in_ms: 10000
|
23
|
+
concurrent_reads: 8
|
24
|
+
concurrent_writes: 32
|
25
|
+
disk_access_mode: auto
|
26
|
+
dynamic_snitch: false
|
27
|
+
hinted_handoff_enabled: true
|
28
|
+
in_memory_compaction_limit_in_mb: 256
|
29
|
+
memtable_flush_after_mins: 60
|
30
|
+
memtable_operations_in_millions: 0.3
|
31
|
+
memtable_throughput_in_mb: 64
|
32
|
+
phi_convict_threshold: 8
|
33
|
+
rpc_timeout_in_ms: 5000
|
34
|
+
sliced_buffer_size_in_kb: 64
|
35
|
+
snapshot_before_compaction: false
|
36
|
+
thrift_framed_transport_size_in_mb: 15
|
37
|
+
thrift_max_message_length_in_mb: 16
|
38
|
+
|
39
|
+
|
40
|
+
keyspaces:
|
41
|
+
|
42
|
+
- name: Twitter
|
43
|
+
replication_factor: 1
|
44
|
+
replica_placement_strategy: org.apache.cassandra.locator.RackUnawareStrategy
|
45
|
+
column_families:
|
46
|
+
- name: Users
|
47
|
+
compare_with: UTF8Type
|
48
|
+
- name: UserAudits
|
49
|
+
compare_with: UTF8Type
|
50
|
+
- name: UserRelationships
|
51
|
+
compare_with: UTF8Type
|
52
|
+
column_type: Super
|
53
|
+
compare_subcolumns_with: TimeUUIDType
|
54
|
+
- name: Usernames
|
55
|
+
compare_with: UTF8Type
|
56
|
+
- name: Statuses
|
57
|
+
compare_with: UTF8Type
|
58
|
+
- name: StatusAudits
|
59
|
+
compare_with: UTF8Type
|
60
|
+
- name: StatusRelationships
|
61
|
+
compare_with: UTF8Type
|
62
|
+
column_type: Super
|
63
|
+
compare_subcolumns_with: TimeUUIDType
|
64
|
+
- name: Index
|
65
|
+
compare_with: UTF8Type
|
66
|
+
column_type: Super
|
67
|
+
- name: TimelinishThings
|
68
|
+
compare_with: BytesType
|
69
|
+
column_type: Standard
|
70
|
+
|
71
|
+
- name: Multiblog
|
72
|
+
replication_factor: 1
|
73
|
+
replica_placement_strategy: org.apache.cassandra.locator.RackUnawareStrategy
|
74
|
+
column_families:
|
75
|
+
- name: Blogs
|
76
|
+
compare_with: TimeUUIDType
|
77
|
+
- name: Comments
|
78
|
+
compare_with: TimeUUIDType
|
79
|
+
|
80
|
+
- name: MultiblogLong
|
81
|
+
replication_factor: 1
|
82
|
+
replica_placement_strategy: org.apache.cassandra.locator.RackUnawareStrategy
|
83
|
+
column_families:
|
84
|
+
- name: Blogs
|
85
|
+
compare_with: LongType
|
86
|
+
- name: Comments
|
87
|
+
compare_with: LongType
|
88
|
+
|
89
|
+
- name: CassandraObject
|
90
|
+
replication_factor: 1
|
91
|
+
replica_placement_strategy: org.apache.cassandra.locator.RackUnawareStrategy
|
92
|
+
column_families:
|
93
|
+
- name: Customers
|
94
|
+
compare_with: UTF8Type
|
95
|
+
- name: CustomerRelationships
|
96
|
+
compare_with: UTF8Type
|
97
|
+
column_type: Super
|
98
|
+
compare_subcolumns_with: TimeUUIDType
|
99
|
+
- name: CustomersByLastName
|
100
|
+
compare_with: TimeUUIDType
|
101
|
+
- name: Invoices
|
102
|
+
compare_with: UTF8Type
|
103
|
+
- name: InvoiceRelationships
|
104
|
+
compare_with: UTF8Type
|
105
|
+
column_type: Super
|
106
|
+
compare_subcolumns_with: TimeUUIDType
|
107
|
+
- name: InvoicesByNumber
|
108
|
+
compare_with: UTF8Type
|
109
|
+
- name: Payments
|
110
|
+
compare_with: UTF8Type
|
111
|
+
- name: Appointments
|
112
|
+
compare_with: UTF8Type
|
113
|
+
|
data/conf/storage-conf.xml
CHANGED
@@ -95,12 +95,13 @@
|
|
95
95
|
<KeysCachedFraction>0.01</KeysCachedFraction>
|
96
96
|
<ColumnFamily CompareWith="UTF8Type" Name="Customers" />
|
97
97
|
<ColumnFamily CompareWith="UTF8Type" CompareSubcolumnsWith="TimeUUIDType" ColumnType="Super" Name="CustomerRelationships" />
|
98
|
-
<ColumnFamily CompareWith="
|
98
|
+
<ColumnFamily CompareWith="TimeUUIDType" Name="CustomersByLastName" />
|
99
99
|
<ColumnFamily CompareWith="UTF8Type" Name="Invoices" />
|
100
100
|
<ColumnFamily CompareWith="UTF8Type" CompareSubcolumnsWith="TimeUUIDType" ColumnType="Super" Name="InvoiceRelationships" />
|
101
101
|
<ColumnFamily CompareWith="UTF8Type" Name="InvoicesByNumber" />
|
102
102
|
<ColumnFamily CompareWith="UTF8Type" Name="Payments" />
|
103
103
|
<ColumnFamily CompareWith="UTF8Type" Name="Appointments" />
|
104
|
+
<!-- <ColumnFamily CompareWith="UTF8Type" Name="FirstNames" /> -->
|
104
105
|
|
105
106
|
<ReplicaPlacementStrategy>org.apache.cassandra.locator.RackUnawareStrategy</ReplicaPlacementStrategy>
|
106
107
|
<ReplicationFactor>1</ReplicationFactor>
|
data/lib/cassandra.rb
CHANGED
@@ -1,11 +1,22 @@
|
|
1
1
|
require 'rubygems'
|
2
|
+
gem 'thrift', '~> 0.5.0'
|
3
|
+
require 'thrift'
|
4
|
+
gem 'thrift_client', '~> 0.6.0'
|
2
5
|
require 'thrift_client'
|
3
|
-
|
6
|
+
gem 'simple_uuid' , '~> 0.1.0'
|
4
7
|
require 'simple_uuid'
|
8
|
+
|
9
|
+
require 'json' unless defined?(JSON)
|
10
|
+
|
5
11
|
here = File.expand_path(File.dirname(__FILE__))
|
6
12
|
|
7
|
-
|
8
|
-
|
13
|
+
class Cassandra ; end
|
14
|
+
unless Cassandra.respond_to?(:VERSION)
|
15
|
+
require "#{here}/cassandra/0.6"
|
16
|
+
end
|
17
|
+
|
18
|
+
$LOAD_PATH << "#{here}/../vendor/#{Cassandra.VERSION}/gen-rb"
|
19
|
+
require "#{here}/../vendor/#{Cassandra.VERSION}/gen-rb/cassandra"
|
9
20
|
|
10
21
|
$LOAD_PATH << "#{here}"
|
11
22
|
|
@@ -16,7 +27,13 @@ require 'cassandra/comparable'
|
|
16
27
|
require 'cassandra/long'
|
17
28
|
require 'cassandra/ordered_hash'
|
18
29
|
require 'cassandra/columns'
|
19
|
-
require
|
20
|
-
require
|
30
|
+
require "cassandra/#{Cassandra.VERSION}/columns"
|
31
|
+
require "cassandra/#{Cassandra.VERSION}/protocol"
|
32
|
+
require "cassandra/cassandra"
|
33
|
+
require "cassandra/#{Cassandra.VERSION}/cassandra"
|
34
|
+
unless Cassandra.VERSION.eql?("0.6")
|
35
|
+
require "cassandra/#{Cassandra.VERSION}/column_family"
|
36
|
+
require "cassandra/#{Cassandra.VERSION}/keyspace"
|
37
|
+
end
|
21
38
|
require 'cassandra/constants'
|
22
39
|
require 'cassandra/debug' if ENV['DEBUG']
|
@@ -0,0 +1,63 @@
|
|
1
|
+
class Cassandra
|
2
|
+
def self.DEFAULT_TRANSPORT_WRAPPER
|
3
|
+
Thrift::BufferedTransport
|
4
|
+
end
|
5
|
+
|
6
|
+
## Delete
|
7
|
+
|
8
|
+
# Remove all rows in the column family you request. Supports options
|
9
|
+
# <tt>:consistency</tt> and <tt>:timestamp</tt>.
|
10
|
+
# FIXME May not currently delete all records without multiple calls. Waiting
|
11
|
+
# for ranged remove support in Cassandra.
|
12
|
+
def clear_column_family!(column_family, options = {})
|
13
|
+
each_key(column_family) do |key|
|
14
|
+
remove(column_family, key, options)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
# Remove all rows in the keyspace. Supports options <tt>:consistency</tt> and
|
19
|
+
# <tt>:timestamp</tt>.
|
20
|
+
# FIXME May not currently delete all records without multiple calls. Waiting
|
21
|
+
# for ranged remove support in Cassandra.
|
22
|
+
def clear_keyspace!(options = {})
|
23
|
+
schema.keys.each { |column_family| clear_column_family!(column_family, options) }
|
24
|
+
end
|
25
|
+
|
26
|
+
protected
|
27
|
+
|
28
|
+
def schema(load=true)
|
29
|
+
if !load && !@schema
|
30
|
+
[]
|
31
|
+
else
|
32
|
+
@schema ||= client.describe_keyspace(@keyspace)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def client
|
37
|
+
reconnect! if @client.nil?
|
38
|
+
@client
|
39
|
+
end
|
40
|
+
|
41
|
+
def reconnect!
|
42
|
+
@servers = all_nodes
|
43
|
+
@client = new_client
|
44
|
+
check_keyspace
|
45
|
+
end
|
46
|
+
|
47
|
+
def check_keyspace
|
48
|
+
unless (keyspaces = client.get_string_list_property("keyspaces")).include?(@keyspace)
|
49
|
+
raise AccessError, "Keyspace #{@keyspace.inspect} not found. Available: #{keyspaces.inspect}"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def all_nodes
|
54
|
+
if @auto_discover_nodes
|
55
|
+
ips = ::JSON.parse(new_client.get_string_property('token map')).values
|
56
|
+
port = @servers.first.split(':').last
|
57
|
+
ips.map{|ip| "#{ip}:#{port}" }
|
58
|
+
else
|
59
|
+
@servers
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
class Cassandra
|
2
|
+
# A bunch of crap, mostly related to introspecting on column types
|
3
|
+
module Columns #:nodoc:
|
4
|
+
private
|
5
|
+
|
6
|
+
def _standard_insert_mutation(column_family, column_name, value, timestamp, _=nil)
|
7
|
+
CassandraThrift::Mutation.new(
|
8
|
+
:column_or_supercolumn => CassandraThrift::ColumnOrSuperColumn.new(
|
9
|
+
:column => CassandraThrift::Column.new(
|
10
|
+
:name => column_name_class(column_family).new(column_name).to_s,
|
11
|
+
:value => value,
|
12
|
+
:timestamp => timestamp
|
13
|
+
)
|
14
|
+
)
|
15
|
+
)
|
16
|
+
end
|
17
|
+
|
18
|
+
def _super_insert_mutation(column_family, super_column_name, sub_columns, timestamp, _=nil)
|
19
|
+
CassandraThrift::Mutation.new(:column_or_supercolumn =>
|
20
|
+
CassandraThrift::ColumnOrSuperColumn.new(
|
21
|
+
:super_column => CassandraThrift::SuperColumn.new(
|
22
|
+
:name => column_name_class(column_family).new(super_column_name).to_s,
|
23
|
+
:columns => sub_columns.collect { |sub_column_name, sub_column_value|
|
24
|
+
CassandraThrift::Column.new(
|
25
|
+
:name => sub_column_name_class(column_family).new(sub_column_name).to_s,
|
26
|
+
:value => sub_column_value.to_s,
|
27
|
+
:timestamp => timestamp
|
28
|
+
)
|
29
|
+
}
|
30
|
+
)
|
31
|
+
)
|
32
|
+
)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|