cassilds 0.9.2 → 0.12.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +51 -1
- data/LICENSE +0 -0
- data/Manifest +25 -7
- data/README.md +352 -0
- data/Rakefile +169 -1
- data/cassilds.gemspec +45 -0
- data/conf/{cassandra.in.sh → 0.6/cassandra.in.sh} +0 -0
- data/conf/{log4j.properties → 0.6/log4j.properties} +0 -0
- data/conf/0.6/schema.json +57 -0
- data/conf/{storage-conf.xml → 0.6/storage-conf.xml} +15 -5
- data/conf/0.7/cassandra.in.sh +46 -0
- data/conf/0.7/cassandra.yaml +336 -0
- data/conf/0.7/log4j-server.properties +41 -0
- data/conf/0.7/schema.json +57 -0
- data/conf/0.7/schema.txt +45 -0
- data/conf/0.8/cassandra.in.sh +41 -0
- data/conf/0.8/cassandra.yaml +61 -0
- data/conf/0.8/log4j-server.properties +40 -0
- data/conf/0.8/schema.json +66 -0
- data/conf/0.8/schema.txt +51 -0
- data/lib/cassandra/0.6/cassandra.rb +58 -13
- data/lib/cassandra/0.6/columns.rb +43 -0
- data/lib/cassandra/0.6/protocol.rb +16 -18
- data/lib/cassandra/0.6.rb +0 -0
- data/lib/cassandra/0.7/cassandra.rb +0 -270
- data/lib/cassandra/0.7/columns.rb +1 -64
- data/lib/cassandra/0.7/protocol.rb +0 -134
- data/lib/cassandra/0.7.rb +0 -0
- data/lib/cassandra/0.8/cassandra.rb +10 -0
- data/lib/cassandra/0.8/columns.rb +4 -0
- data/lib/cassandra/0.8/protocol.rb +23 -0
- data/lib/cassandra/0.8.rb +7 -0
- data/lib/cassandra/array.rb +0 -0
- data/lib/cassandra/cassandra.rb +877 -111
- data/lib/cassandra/{0.7/column_family.rb → column_family.rb} +0 -0
- data/lib/cassandra/columns.rb +72 -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 +1 -0
- data/lib/cassandra/{0.7/keyspace.rb → keyspace.rb} +0 -0
- data/lib/cassandra/long.rb +5 -0
- data/lib/cassandra/mock.rb +259 -85
- data/lib/cassandra/ordered_hash.rb +10 -18
- data/lib/cassandra/protocol.rb +120 -0
- data/lib/cassandra/time.rb +0 -0
- data/lib/cassandra.rb +6 -7
- data/test/cassandra_client_test.rb +0 -0
- data/test/cassandra_mock_test.rb +52 -28
- data/test/cassandra_test.rb +465 -44
- data/test/comparable_types_test.rb +0 -0
- data/test/eventmachine_test.rb +30 -30
- data/test/ordered_hash_test.rb +6 -0
- data/test/test_helper.rb +3 -2
- 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 +4 -2
- data/vendor/0.8/gen-rb/cassandra.rb +2215 -0
- data/vendor/0.8/gen-rb/cassandra_constants.rb +12 -0
- data/vendor/0.8/gen-rb/cassandra_types.rb +816 -0
- metadata +50 -27
- data/README.rdoc +0 -83
- data/cassandra.gemspec +0 -46
- data/conf/cassandra.yaml +0 -113
data/CHANGELOG
CHANGED
@@ -1,3 +1,53 @@
|
|
1
|
+
v0.12.1
|
2
|
+
- Fix issue with simple_uuid dependency.
|
3
|
+
- Fix issue with get_range & get_range_batch keeping all results when a block is given. Resolves Issue# 112.
|
4
|
+
|
5
|
+
v0.12.0 Changed thrift_client dependency to 0.7.0
|
6
|
+
|
7
|
+
v0.11.4
|
8
|
+
- Fix get_range to invoke blocks
|
9
|
+
- Fix current distribution urls in Rakfile. Resolves Issue# 97.
|
10
|
+
|
11
|
+
v0.11.3
|
12
|
+
- Fix login after reconnect
|
13
|
+
|
14
|
+
v0.11.2
|
15
|
+
- Update thrift_client gem to deal with failover bug.
|
16
|
+
|
17
|
+
v0.11.1
|
18
|
+
- Add counter support for Cassandra 0.8. (Thanks Swrve team!)
|
19
|
+
- Add additional rake tasks to start and stop cassandra in the background.
|
20
|
+
- Fix issue with non-utf8 column names not being encoded/decoded properly.
|
21
|
+
- Add way to specify a default read/write consistency.
|
22
|
+
- Consolidate 0.7 and 0.8 functions, and move 0.6 specific functions into lib/cassandra/0.6/
|
23
|
+
- Use 0.8-rc1 as 0.8 install target.
|
24
|
+
- Updated get_index_slices API to allow passing an array of hashes instead of IndexClause instance. (Maintains backward compatibility.)
|
25
|
+
- Fix permissions issue.
|
26
|
+
|
27
|
+
v0.11.0
|
28
|
+
- Remove direct thrift dependency. Allow thrift_client to require it.
|
29
|
+
- Add functions for each and each_key to iterate through key ranges.
|
30
|
+
- Add function for get_range_keys which returns an array of keys in a given range.
|
31
|
+
- Changed the return value of get_range to an OrderedHash.
|
32
|
+
- Change get_range to accept both a range of keys and a range of columns.
|
33
|
+
- Add batched range support to get_range and add get_range_batch.
|
34
|
+
|
35
|
+
v0.10.0 Major Update (rjackson)
|
36
|
+
- Update Rakefile to install 0.6.13, 0.7.4, 0.8.0-beta1 to ~/cassandra/cassandra-VERSION
|
37
|
+
- Add data:load task to Rakefile for creating the schema required for the tests
|
38
|
+
- Default the Rakefile to use 0.8-beta1
|
39
|
+
- Setup test suite to work on 0.6.13, 0.7.4, and 0.8.0-beta1
|
40
|
+
- All tests pass for all supported (0.6.13, 0.7.4, 0.8.0-beta1) versions.
|
41
|
+
- Added Support for 0.8-beta1
|
42
|
+
- Changed get_index_slices to return a hash of rows
|
43
|
+
- Updated Cassandra::Mock to pass all tests for each Cassandra version
|
44
|
+
|
45
|
+
v0.9.2 fix bug with deletions in batch mutations
|
46
|
+
|
47
|
+
v0.9.1 Support for secondary indexing. (jhermes)
|
48
|
+
Fix bug in mock where we didn't support range queries. (therealadam)
|
49
|
+
Support deletes in batch mutations. [blanquer]
|
50
|
+
|
1
51
|
v0.9.0 cassandra 0.7 compat
|
2
52
|
|
3
53
|
v0.8.2 Renamed :thrift_client_class option, UUID fix, 0.6 update, fixing cassanda install, much Mock fixes
|
@@ -18,7 +68,7 @@ v0.7.2 Switch to newly-extraced simple_uuid gem, minor bugfixes.
|
|
18
68
|
|
19
69
|
v0.7.1 update thrift-generated code to 0.5
|
20
70
|
|
21
|
-
v0.7 Various improvements.
|
71
|
+
v0.7 Various improvements.
|
22
72
|
- Compatibility with Cassandra 0.5.
|
23
73
|
- performance improvements
|
24
74
|
|
data/LICENSE
CHANGED
File without changes
|
data/Manifest
CHANGED
@@ -1,13 +1,23 @@
|
|
1
1
|
CHANGELOG
|
2
2
|
LICENSE
|
3
3
|
Manifest
|
4
|
-
README.
|
4
|
+
README.md
|
5
5
|
Rakefile
|
6
6
|
bin/cassandra_helper
|
7
|
-
conf/cassandra.in.sh
|
8
|
-
conf/
|
9
|
-
conf/
|
10
|
-
conf/storage-conf.xml
|
7
|
+
conf/0.6/cassandra.in.sh
|
8
|
+
conf/0.6/log4j.properties
|
9
|
+
conf/0.6/schema.json
|
10
|
+
conf/0.6/storage-conf.xml
|
11
|
+
conf/0.7/cassandra.in.sh
|
12
|
+
conf/0.7/cassandra.yaml
|
13
|
+
conf/0.7/log4j-server.properties
|
14
|
+
conf/0.7/schema.json
|
15
|
+
conf/0.7/schema.txt
|
16
|
+
conf/0.8/cassandra.in.sh
|
17
|
+
conf/0.8/cassandra.yaml
|
18
|
+
conf/0.8/log4j-server.properties
|
19
|
+
conf/0.8/schema.json
|
20
|
+
conf/0.8/schema.txt
|
11
21
|
lib/cassandra.rb
|
12
22
|
lib/cassandra/0.6.rb
|
13
23
|
lib/cassandra/0.6/cassandra.rb
|
@@ -15,20 +25,25 @@ lib/cassandra/0.6/columns.rb
|
|
15
25
|
lib/cassandra/0.6/protocol.rb
|
16
26
|
lib/cassandra/0.7.rb
|
17
27
|
lib/cassandra/0.7/cassandra.rb
|
18
|
-
lib/cassandra/0.7/column_family.rb
|
19
28
|
lib/cassandra/0.7/columns.rb
|
20
|
-
lib/cassandra/0.7/keyspace.rb
|
21
29
|
lib/cassandra/0.7/protocol.rb
|
30
|
+
lib/cassandra/0.8.rb
|
31
|
+
lib/cassandra/0.8/cassandra.rb
|
32
|
+
lib/cassandra/0.8/columns.rb
|
33
|
+
lib/cassandra/0.8/protocol.rb
|
22
34
|
lib/cassandra/array.rb
|
23
35
|
lib/cassandra/cassandra.rb
|
36
|
+
lib/cassandra/column_family.rb
|
24
37
|
lib/cassandra/columns.rb
|
25
38
|
lib/cassandra/comparable.rb
|
26
39
|
lib/cassandra/constants.rb
|
27
40
|
lib/cassandra/debug.rb
|
28
41
|
lib/cassandra/helpers.rb
|
42
|
+
lib/cassandra/keyspace.rb
|
29
43
|
lib/cassandra/long.rb
|
30
44
|
lib/cassandra/mock.rb
|
31
45
|
lib/cassandra/ordered_hash.rb
|
46
|
+
lib/cassandra/protocol.rb
|
32
47
|
lib/cassandra/time.rb
|
33
48
|
test/cassandra_client_test.rb
|
34
49
|
test/cassandra_mock_test.rb
|
@@ -43,3 +58,6 @@ vendor/0.6/gen-rb/cassandra_types.rb
|
|
43
58
|
vendor/0.7/gen-rb/cassandra.rb
|
44
59
|
vendor/0.7/gen-rb/cassandra_constants.rb
|
45
60
|
vendor/0.7/gen-rb/cassandra_types.rb
|
61
|
+
vendor/0.8/gen-rb/cassandra.rb
|
62
|
+
vendor/0.8/gen-rb/cassandra_constants.rb
|
63
|
+
vendor/0.8/gen-rb/cassandra_types.rb
|
data/README.md
ADDED
@@ -0,0 +1,352 @@
|
|
1
|
+
# cassandra
|
2
|
+
A Ruby client for the Cassandra distributed database.
|
3
|
+
|
4
|
+
Supports 1.8.7, 1.9.2, and rubinius on Cassandra 0.6.13, 0.7.8, 0.8.4.
|
5
|
+
|
6
|
+
## Getting Started
|
7
|
+
|
8
|
+
Here is a quick sample of the general use (more details in Read/Write
|
9
|
+
API below):
|
10
|
+
|
11
|
+
require 'cassandra'
|
12
|
+
client = Cassandra.new('Twitter', '127.0.0.1:9160')
|
13
|
+
client.insert(:Users, "5", {'screen_name' => "buttonscat"})
|
14
|
+
|
15
|
+
## License
|
16
|
+
|
17
|
+
Copyright 2009-2011 Twitter, Inc. See included LICENSE file. Portions copyright 2004-2009 David Heinemeier Hansson, and used with permission.
|
18
|
+
|
19
|
+
## Cassandra Version
|
20
|
+
|
21
|
+
The Cassandra project is under very active development, and as such
|
22
|
+
there are a few different versions that you may need to use this gem
|
23
|
+
with. We have set up an easy sure fire mechanism for selecting the
|
24
|
+
specific version that you are connecting to while requiring the gem.
|
25
|
+
|
26
|
+
#### Require Method
|
27
|
+
The default version is the currently stable release of cassandra. (0.8
|
28
|
+
at this time.)
|
29
|
+
|
30
|
+
To use the default version simply use a normal require:
|
31
|
+
|
32
|
+
require 'cassandra'
|
33
|
+
|
34
|
+
To use a specific version (0.7 in this example) you would use a
|
35
|
+
slightly differently formatted require:
|
36
|
+
|
37
|
+
require 'cassandra/0.7'
|
38
|
+
|
39
|
+
#### Environment Variable Method
|
40
|
+
These mechanisms work well when you are using the cassandra gem in your
|
41
|
+
own projects or irb, but if you would rather not hard code your app to a
|
42
|
+
specific version you can always specify an environment variable with the
|
43
|
+
version you are using:
|
44
|
+
|
45
|
+
export CASSANDRA_VERSION=0.8
|
46
|
+
|
47
|
+
Then you would use the default require as listed above:
|
48
|
+
|
49
|
+
require 'cassandra'
|
50
|
+
|
51
|
+
## Read/Write API Method Reference
|
52
|
+
|
53
|
+
### insert
|
54
|
+
|
55
|
+
* column\_family - The column\_family that you are inserting into.
|
56
|
+
* key - The row key to insert.
|
57
|
+
* hash - The columns or super columns to insert.
|
58
|
+
* options - Valid options are:
|
59
|
+
* :timestamp - Uses the current time if none specified.
|
60
|
+
* :consistency - Uses the default write consistency if none specified.
|
61
|
+
* :ttl - If specified this is the number of seconds after the insert that this value will be available.
|
62
|
+
|
63
|
+
This is the main method used to insert rows into cassandra. If the
|
64
|
+
column\_family that you are inserting into is a SuperColumnFamily then
|
65
|
+
the hash passed in should be a nested hash, otherwise it should be a
|
66
|
+
flat hash.
|
67
|
+
|
68
|
+
This method can also be called while in batch mode. If in batch mode
|
69
|
+
then we queue up the mutations (an insert in this case) and pass them to
|
70
|
+
cassandra in a single batch at the end of the block.
|
71
|
+
|
72
|
+
Example:
|
73
|
+
|
74
|
+
@client.insert(:Statuses, key, {'body' => 'v', 'user' => 'v'})
|
75
|
+
|
76
|
+
columns = {@uuids[1] => 'v1', @uuids[2] => 'v2'}
|
77
|
+
@client.insert(:StatusRelationships, key, {'user_timelines' => columns})
|
78
|
+
|
79
|
+
|
80
|
+
### remove
|
81
|
+
|
82
|
+
* column\_family - The column\_family that you are working with.
|
83
|
+
* key - The row key to remove (or remove columns from).
|
84
|
+
* columns - Either a single super_column or a list of columns to remove.
|
85
|
+
* sub_columns - The list of sub\_columns to remove.
|
86
|
+
* options - Valid options are:
|
87
|
+
* :timestamp - Uses the current time if none specified.
|
88
|
+
* :consistency - Uses the default write consistency if none specified.
|
89
|
+
|
90
|
+
This method is used to delete (actually marking them as deleted with a
|
91
|
+
tombstone) rows, columns, or super columns depending on the parameters
|
92
|
+
passed. If only a key is passed the entire row will be marked as deleted.
|
93
|
+
If a column name is passed in that column will be deleted.
|
94
|
+
|
95
|
+
Example:
|
96
|
+
|
97
|
+
@client.insert(:Statuses, key, {'body' => 'v', 'subject' => 'v'})
|
98
|
+
|
99
|
+
@client.remove(:Statuses, key, 'body') # removes the 'body' column
|
100
|
+
@client.remove(:Statuses, key) # removes the row
|
101
|
+
|
102
|
+
### count\_columns
|
103
|
+
|
104
|
+
Count the columns for the provided parameters.
|
105
|
+
|
106
|
+
* column\_family - The column\_family that you are working with.
|
107
|
+
* key - The row key.
|
108
|
+
* columns - Either a single super_column or a list of columns.
|
109
|
+
* sub_columns - The list of sub\_columns to select.
|
110
|
+
* options - Valid options are:
|
111
|
+
* :start - The column name to start from.
|
112
|
+
* :stop - The column name to stop at.
|
113
|
+
* :count - The maximum count of columns to return. (By default cassandra will count up to 100 columns)
|
114
|
+
* :consistency - Uses the default read consistency if none specified.
|
115
|
+
|
116
|
+
Example:
|
117
|
+
|
118
|
+
@client.insert(:Statuses, key, {'body' => 'v1', 'user' => 'v2'})
|
119
|
+
@client.count_columns(:Statuses, key) # returns 2
|
120
|
+
|
121
|
+
### get
|
122
|
+
|
123
|
+
Return a hash (actually, a Cassandra::OrderedHash) or a single value
|
124
|
+
representing the element at the column_family:key:[column]:[sub_column]
|
125
|
+
path you request.
|
126
|
+
|
127
|
+
* column\_family - The column\_family that you are working with.
|
128
|
+
* key - The row key to select.
|
129
|
+
* columns - Either a single super\_column or a list of columns.
|
130
|
+
* sub\_columns - The list of sub\_columns to select.
|
131
|
+
* options - Valid options are:
|
132
|
+
* :count - The number of columns requested to be returned.
|
133
|
+
* :start - The starting value for selecting a range of columns.
|
134
|
+
* :finish - The final value for selecting a range of columns.
|
135
|
+
* :reversed - If set to true the results will be returned in
|
136
|
+
reverse order.
|
137
|
+
* :consistency - Uses the default read consistency if none specified.
|
138
|
+
|
139
|
+
Example:
|
140
|
+
|
141
|
+
@client.insert(:Users, key, {'body' => 'v', 'user' => 'v'})
|
142
|
+
@client.get(:Users, key)) # returns {'body' => 'v', 'user' => 'v'}
|
143
|
+
|
144
|
+
### multi\_get
|
145
|
+
|
146
|
+
Multi-key version of Cassandra#get.
|
147
|
+
|
148
|
+
This method allows you to select multiple rows with a single query.
|
149
|
+
If a key that is passed in doesn't exist an empty hash will be
|
150
|
+
returned.
|
151
|
+
|
152
|
+
Supports the same parameters as Cassandra#get.
|
153
|
+
|
154
|
+
* column_family - The column_family that you are working with.
|
155
|
+
* key - An array of keys to select.
|
156
|
+
* columns - Either a single super_column or a list of columns.
|
157
|
+
* sub_columns - The list of sub\_columns to select.
|
158
|
+
* options - Valid options are:
|
159
|
+
* :count - The number of columns requested to be returned.
|
160
|
+
* :start - The starting value for selecting a range of columns.
|
161
|
+
* :finish - The final value for selecting a range of columns.
|
162
|
+
* :reversed - If set to true the results will be returned in reverse order.
|
163
|
+
* :consistency - Uses the default read consistency if none specified.
|
164
|
+
|
165
|
+
Example:
|
166
|
+
|
167
|
+
@client.insert(:Users, '1', {'body' => 'v1', 'user' => 'v1'})
|
168
|
+
@client.insert(:Users, '2', {'body' => 'v2', 'user' => 'v2'})
|
169
|
+
|
170
|
+
expected = OrderedHash[
|
171
|
+
'1', {'body' => 'v1', 'user' => 'v1'},
|
172
|
+
'2', {'body' => 'v2', 'user' => 'v2'},
|
173
|
+
'bogus', {}
|
174
|
+
]
|
175
|
+
result = @client.multi_get(:Users, ['1', '2', 'bogus'])
|
176
|
+
|
177
|
+
### exists?
|
178
|
+
|
179
|
+
Return true if the column\_family:key:[column]:[sub\_column] path you
|
180
|
+
request exists.
|
181
|
+
|
182
|
+
If passed in only a row key it will query for any columns (limiting
|
183
|
+
to 1) for that row key. If a column is passed in it will query for
|
184
|
+
that specific column/super column.
|
185
|
+
|
186
|
+
This method will return true or false.
|
187
|
+
|
188
|
+
* column\_family - The column\_family that you are working with.
|
189
|
+
* key - The row key to check.
|
190
|
+
* columns - Either a single super\_column or a list of columns.
|
191
|
+
* sub\_columns - The list of sub\_columns to check.
|
192
|
+
* options - Valid options are:
|
193
|
+
* :consistency - Uses the default read consistency if none specified.
|
194
|
+
|
195
|
+
Example:
|
196
|
+
|
197
|
+
@client.insert(:Statuses, 'key', {'body' => 'v'})
|
198
|
+
@client.exists?(:Statuses, 'key') # returns true
|
199
|
+
@client.exists?(:Statuses, 'bogus') # returns false
|
200
|
+
@client.exists?(:Statuses, 'key', 'body') # returns true
|
201
|
+
@client.exists?(:Statuses, 'key', 'bogus') # returns false
|
202
|
+
|
203
|
+
### get\_range
|
204
|
+
Return an Cassandra::OrderedHash containing the columns specified for the given
|
205
|
+
range of keys in the column\_family you request.
|
206
|
+
|
207
|
+
This method is just a convenience wrapper around Cassandra#get_range_single
|
208
|
+
and Cassandra#get\_range\_batch. If :key\_size, :batch\_size, or a block
|
209
|
+
is passed in Cassandra#get\_range\_batch will be called. Otherwise
|
210
|
+
Cassandra#get\_range\_single will be used.
|
211
|
+
|
212
|
+
The start\_key and finish\_key parameters are only useful for iterating of all records
|
213
|
+
as is done in the Cassandra#each and Cassandra#each\_key methods if you are using the
|
214
|
+
RandomPartitioner.
|
215
|
+
|
216
|
+
If the table is partitioned with OrderPreservingPartitioner you may
|
217
|
+
use the start\_key and finish\_key params to select all records with
|
218
|
+
the same prefix value.
|
219
|
+
|
220
|
+
If a block is passed in we will yield the row key and columns for
|
221
|
+
each record returned.
|
222
|
+
|
223
|
+
Please note that Cassandra returns a row for each row that has existed in the
|
224
|
+
system since gc\_grace\_seconds. This is because deleted row keys are marked as
|
225
|
+
deleted, but left in the system until the cluster has had resonable time to replicate the deletion.
|
226
|
+
This function attempts to suppress deleted rows (actually any row returned without
|
227
|
+
columns is suppressed).
|
228
|
+
|
229
|
+
* column\_family - The column\_family that you are working with.
|
230
|
+
* options - Valid options are:
|
231
|
+
* :start\_key - The starting value for selecting a range of keys (only useful with OPP).
|
232
|
+
* :finish\_key - The final value for selecting a range of keys (only useful with OPP).
|
233
|
+
* :key\_count - The total number of keys to return from the query. (see note regarding deleted records)
|
234
|
+
* :batch\_size - The maximum number of keys to return per query. If specified will loop until :key\_count is obtained or all records have been returned.
|
235
|
+
* :columns - A list of columns to return.
|
236
|
+
* :count - The number of columns requested to be returned.
|
237
|
+
* :start - The starting value for selecting a range of columns.
|
238
|
+
* :finish - The final value for selecting a range of columns.
|
239
|
+
* :reversed - If set to true the results will be returned in reverse order.
|
240
|
+
* :consistency - Uses the default read consistency if none specified.
|
241
|
+
|
242
|
+
Example:
|
243
|
+
|
244
|
+
10.times do |i|
|
245
|
+
@client.insert(:Statuses, i.to_s, {'body' => '1'})
|
246
|
+
end
|
247
|
+
|
248
|
+
@client.get_range_keys(:Statuses, :key_count => 4)
|
249
|
+
|
250
|
+
# returns:
|
251
|
+
#{
|
252
|
+
# '0' => {'body' => '1'},
|
253
|
+
# '1' => {'body' => '1'},
|
254
|
+
# '2' => {'body' => '1'},
|
255
|
+
# '3' => {'body' => '1'}
|
256
|
+
#}
|
257
|
+
|
258
|
+
### count\_range
|
259
|
+
|
260
|
+
Return an Array containing all of the keys within a given range.
|
261
|
+
|
262
|
+
This method just calls Cassandra#get\_range and returns the
|
263
|
+
row keys for the records returned.
|
264
|
+
|
265
|
+
See Cassandra#get\_range for options.
|
266
|
+
|
267
|
+
### get\_range\_keys
|
268
|
+
|
269
|
+
Return an Array containing all of the keys within a given range.
|
270
|
+
|
271
|
+
This method just calls Cassandra#get\_range and returns the
|
272
|
+
row keys for the records returned.
|
273
|
+
|
274
|
+
See Cassandra#get\_range for options.
|
275
|
+
|
276
|
+
### each\_key
|
277
|
+
Iterate through each key within the given range parameters. This function can be
|
278
|
+
used to iterate over each key in the given column family.
|
279
|
+
|
280
|
+
This method just calls Cassandra#get\_range and yields each row key.
|
281
|
+
|
282
|
+
See Cassandra#get\_range for options.
|
283
|
+
|
284
|
+
Example:
|
285
|
+
10.times do |i|
|
286
|
+
@client.insert(:Statuses, k + i.to_s, {"body-#{i.to_s}" => 'v'})
|
287
|
+
end
|
288
|
+
|
289
|
+
@client.each_key(:Statuses) do |key|
|
290
|
+
print key
|
291
|
+
end
|
292
|
+
|
293
|
+
# returns 0123456789
|
294
|
+
|
295
|
+
### each
|
296
|
+
Iterate through each row within the given column\_family.
|
297
|
+
|
298
|
+
This method just calls Cassandra#get\_range and yields the key and
|
299
|
+
columns.
|
300
|
+
|
301
|
+
See Cassandra#get\_range for options.
|
302
|
+
|
303
|
+
### get\_index\_slices
|
304
|
+
This method is used to query a secondary index with a set of
|
305
|
+
provided search parameters
|
306
|
+
|
307
|
+
Please note that you can either specify a
|
308
|
+
CassandraThrift::IndexClause or an array of hashes with the
|
309
|
+
format as below.
|
310
|
+
|
311
|
+
* column\_family - The Column Family this operation will be run on.
|
312
|
+
* index\_clause - This can either be a CassandraThrift::IndexClause or an array of hashes with the following keys:
|
313
|
+
* :column\_name - Column to be compared
|
314
|
+
* :value - Value to compare against
|
315
|
+
* :comparison - Type of comparison to do.
|
316
|
+
* options
|
317
|
+
* :key\_count - Set maximum number of rows to return. (Only works if CassandraThrift::IndexClause is not passed in.)
|
318
|
+
* :key\_start - Set starting row key for search. (Only works if CassandraThrift::IndexClause is not passed in.)
|
319
|
+
* :consistency
|
320
|
+
|
321
|
+
Example:
|
322
|
+
|
323
|
+
@client.create_index('Twitter', 'Statuses', 'x', 'LongType')
|
324
|
+
|
325
|
+
@client.insert(:Statuses, 'row1', { 'x' => [0,10].pack("NN") })
|
326
|
+
|
327
|
+
(2..10).to_a.each do |i|
|
328
|
+
@twitter.insert(:Statuses, 'row' + i.to_s, { 'x' => [0,20].pack("NN"), 'non_indexed' => [i].pack('N*') })
|
329
|
+
end
|
330
|
+
|
331
|
+
@client.insert(:Statuses, 'row11', { 'x' => [0,30].pack("NN") })
|
332
|
+
|
333
|
+
expressions = [{:column_name => 'x', :value => [0,20].pack("NN"), :comparison => "=="}]
|
334
|
+
|
335
|
+
# verify multiples will be returned
|
336
|
+
@client.get_indexed_slices(:Statuses, expressions).length # returns 9
|
337
|
+
|
338
|
+
# verify that GT and LT queries perform properly
|
339
|
+
expressions = [
|
340
|
+
{ :column_name => 'x',
|
341
|
+
:value => [0,20].pack("NN"),
|
342
|
+
:comparison => "=="},
|
343
|
+
{ :column_name => 'non_indexed',
|
344
|
+
:value => [5].pack("N*"),
|
345
|
+
:comparison => ">"}
|
346
|
+
]
|
347
|
+
|
348
|
+
@client.get_indexed_slices(:Statuses, expressions).length # returns 5
|
349
|
+
|
350
|
+
## Reporting Problems
|
351
|
+
|
352
|
+
The Github issue tracker is [here](http://github.com/fauna/cassandra/issues). If you have problems with this library or Cassandra itself, please use the [cassandra-user mailing list](http://mail-archives.apache.org/mod_mbox/incubator-cassandra-user/).
|
data/Rakefile
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'bundler'
|
2
|
-
require
|
2
|
+
require 'fileutils'
|
3
|
+
require 'rspec/core/rake_task'
|
3
4
|
|
4
5
|
task :default => [:spec]
|
5
6
|
|
@@ -7,3 +8,170 @@ desc "Run specs"
|
|
7
8
|
RSpec::Core::RakeTask.new(:spec)
|
8
9
|
|
9
10
|
Bundler::GemHelper.install_tasks
|
11
|
+
|
12
|
+
|
13
|
+
# Cassilds uses Bundler
|
14
|
+
#unless ENV['FROM_BIN_CASSANDRA_HELPER']
|
15
|
+
# require 'rubygems'
|
16
|
+
# require 'echoe'
|
17
|
+
#
|
18
|
+
# Echoe.new("cassandra") do |p|
|
19
|
+
# p.author = "Evan Weaver, Ryan King"
|
20
|
+
# p.project = "fauna"
|
21
|
+
# p.summary = "A Ruby client for the Cassandra distributed database."
|
22
|
+
# p.rubygems_version = ">= 0.8"
|
23
|
+
# p.dependencies = ['thrift_client >=0.7.0', 'json', 'rake', 'simple_uuid >=0.2.0']
|
24
|
+
# p.ignore_pattern = /^(data|vendor\/cassandra|cassandra|vendor\/thrift|.*\.rbc)/
|
25
|
+
# p.rdoc_pattern = /^(lib|bin|tasks|ext)|^README|^CHANGELOG|^TODO|^LICENSE|^COPYING$/
|
26
|
+
# p.retain_gemspec = true
|
27
|
+
# end
|
28
|
+
#end
|
29
|
+
|
30
|
+
CassandraBinaries = {
|
31
|
+
'0.6' => 'http://archive.apache.org/dist/cassandra/0.6.13/apache-cassandra-0.6.13-bin.tar.gz',
|
32
|
+
'0.7' => 'http://archive.apache.org/dist/cassandra/0.7.8/apache-cassandra-0.7.8-bin.tar.gz',
|
33
|
+
'0.8' => 'http://archive.apache.org/dist/cassandra/0.8.4/apache-cassandra-0.8.4-bin.tar.gz'
|
34
|
+
}
|
35
|
+
|
36
|
+
CASSANDRA_HOME = ENV['CASSANDRA_HOME'] || "#{ENV['HOME']}/cassandra"
|
37
|
+
CASSANDRA_VERSION = ENV['CASSANDRA_VERSION'] || '0.8'
|
38
|
+
CASSANDRA_PIDFILE = ENV['CASSANDRA_PIDFILE'] || "#{CASSANDRA_HOME}/cassandra.pid"
|
39
|
+
|
40
|
+
def setup_cassandra_version(version = CASSANDRA_VERSION)
|
41
|
+
FileUtils.mkdir_p CASSANDRA_HOME
|
42
|
+
|
43
|
+
destination_directory = File.join(CASSANDRA_HOME, 'cassandra-' + CASSANDRA_VERSION)
|
44
|
+
|
45
|
+
unless File.exists?(File.join(destination_directory, 'bin','cassandra'))
|
46
|
+
download_source = CassandraBinaries[CASSANDRA_VERSION]
|
47
|
+
download_destination = File.join("/tmp", File.basename(download_source))
|
48
|
+
untar_directory = File.join(CASSANDRA_HOME, File.basename(download_source,'-bin.tar.gz'))
|
49
|
+
|
50
|
+
puts "downloading cassandra"
|
51
|
+
sh "curl -L -o #{download_destination} #{download_source}"
|
52
|
+
|
53
|
+
sh "tar xzf #{download_destination} -C #{CASSANDRA_HOME}"
|
54
|
+
sh "mv #{untar_directory} #{destination_directory}"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def setup_environment
|
59
|
+
env = ""
|
60
|
+
if !ENV["CASSANDRA_INCLUDE"]
|
61
|
+
env << "CASSANDRA_INCLUDE=#{File.expand_path(Dir.pwd)}/conf/#{CASSANDRA_VERSION}/cassandra.in.sh "
|
62
|
+
env << "CASSANDRA_HOME=#{CASSANDRA_HOME}/cassandra-#{CASSANDRA_VERSION} "
|
63
|
+
env << "CASSANDRA_CONF=#{File.expand_path(Dir.pwd)}/conf/#{CASSANDRA_VERSION}"
|
64
|
+
else
|
65
|
+
env << "CASSANDRA_INCLUDE=#{ENV['CASSANDRA_INCLUDE']} "
|
66
|
+
env << "CASSANDRA_HOME=#{ENV['CASSANDRA_HOME']} "
|
67
|
+
env << "CASSANDRA_CONF=#{ENV['CASSANDRA_CONF']}"
|
68
|
+
end
|
69
|
+
|
70
|
+
env
|
71
|
+
end
|
72
|
+
|
73
|
+
def running?(pid_file = nil)
|
74
|
+
pid_file ||= CASSANDRA_PIDFILE
|
75
|
+
|
76
|
+
if File.exists?(pid_file)
|
77
|
+
pid = File.new(pid_file).read.to_i
|
78
|
+
begin
|
79
|
+
Process.kill(0, pid)
|
80
|
+
return true
|
81
|
+
rescue
|
82
|
+
File.delete(pid_file)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
false
|
87
|
+
end
|
88
|
+
|
89
|
+
namespace :cassandra do
|
90
|
+
desc "Start Cassandra"
|
91
|
+
task :start, [:daemonize] => :java do |t, args|
|
92
|
+
args.with_defaults(:daemonize => true)
|
93
|
+
|
94
|
+
setup_cassandra_version
|
95
|
+
|
96
|
+
env = setup_environment
|
97
|
+
|
98
|
+
Dir.chdir(File.join(CASSANDRA_HOME, "cassandra-#{CASSANDRA_VERSION}")) do
|
99
|
+
sh("env #{env} bin/cassandra #{'-f' unless args.daemonize} -p #{CASSANDRA_PIDFILE}")
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
desc "Stop Cassandra"
|
104
|
+
task :stop => :java do
|
105
|
+
setup_cassandra_version
|
106
|
+
env = setup_environment
|
107
|
+
sh("kill $(cat #{CASSANDRA_PIDFILE})")
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
desc "Start Cassandra"
|
112
|
+
task :cassandra => :java do
|
113
|
+
begin
|
114
|
+
Rake::Task["cassandra:start"].invoke(false)
|
115
|
+
rescue RuntimeError => e
|
116
|
+
raise e unless e.message =~ /Command failed with status \(130\)/ # handle keyboard interupt errors
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
desc "Run the Cassandra CLI"
|
121
|
+
task :cli do
|
122
|
+
Dir.chdir(File.join(CASSANDRA_HOME, "cassandra-#{CASSANDRA_VERSION}")) do
|
123
|
+
sh("bin/cassandra-cli -host localhost -port 9160")
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
desc "Check Java version"
|
128
|
+
task :java do
|
129
|
+
unless `java -version 2>&1`.split("\n").first =~ /java version "1.6/ #"
|
130
|
+
puts "You need to configure your environment for Java 1.6."
|
131
|
+
puts "If you're on OS X, just export the following environment variables:"
|
132
|
+
puts ' JAVA_HOME="/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home"'
|
133
|
+
puts ' PATH="/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home/bin:$PATH"'
|
134
|
+
exit(1)
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
namespace :data do
|
139
|
+
desc "Reset test data"
|
140
|
+
task :reset do
|
141
|
+
puts "Resetting test data"
|
142
|
+
sh("rm -rf #{File.join(CASSANDRA_HOME, "cassandra-#{CASSANDRA_VERSION}", 'data')}")
|
143
|
+
end
|
144
|
+
|
145
|
+
desc "Load test data structures."
|
146
|
+
task :load do
|
147
|
+
unless CASSANDRA_VERSION == '0.6'
|
148
|
+
|
149
|
+
schema_path = "#{File.expand_path(Dir.pwd)}/conf/#{CASSANDRA_VERSION}/schema.txt"
|
150
|
+
puts "Loading test data structures."
|
151
|
+
Dir.chdir(File.join(CASSANDRA_HOME, "cassandra-#{CASSANDRA_VERSION}")) do
|
152
|
+
begin
|
153
|
+
sh("bin/cassandra-cli --host localhost --batch < #{schema_path}")
|
154
|
+
rescue
|
155
|
+
puts "Schema already loaded."
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
task :test => 'data:load'
|
163
|
+
|
164
|
+
# desc "Regenerate thrift bindings for Cassandra" # Dev only
|
165
|
+
task :thrift do
|
166
|
+
puts "Generating Thrift bindings"
|
167
|
+
system(
|
168
|
+
"cd vendor &&
|
169
|
+
rm -rf gen-rb &&
|
170
|
+
thrift -gen rb #{CASSANDRA_HOME}/interface/cassandra.thrift")
|
171
|
+
end
|
172
|
+
|
173
|
+
task :fix_perms do
|
174
|
+
chmod_R 0755, './'
|
175
|
+
end
|
176
|
+
|
177
|
+
task :pkg => [:fix_perms]
|