cassilds 0.9.2 → 0.12.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. data/CHANGELOG +51 -1
  2. data/LICENSE +0 -0
  3. data/Manifest +25 -7
  4. data/README.md +352 -0
  5. data/Rakefile +169 -1
  6. data/cassilds.gemspec +45 -0
  7. data/conf/{cassandra.in.sh → 0.6/cassandra.in.sh} +0 -0
  8. data/conf/{log4j.properties → 0.6/log4j.properties} +0 -0
  9. data/conf/0.6/schema.json +57 -0
  10. data/conf/{storage-conf.xml → 0.6/storage-conf.xml} +15 -5
  11. data/conf/0.7/cassandra.in.sh +46 -0
  12. data/conf/0.7/cassandra.yaml +336 -0
  13. data/conf/0.7/log4j-server.properties +41 -0
  14. data/conf/0.7/schema.json +57 -0
  15. data/conf/0.7/schema.txt +45 -0
  16. data/conf/0.8/cassandra.in.sh +41 -0
  17. data/conf/0.8/cassandra.yaml +61 -0
  18. data/conf/0.8/log4j-server.properties +40 -0
  19. data/conf/0.8/schema.json +66 -0
  20. data/conf/0.8/schema.txt +51 -0
  21. data/lib/cassandra/0.6/cassandra.rb +58 -13
  22. data/lib/cassandra/0.6/columns.rb +43 -0
  23. data/lib/cassandra/0.6/protocol.rb +16 -18
  24. data/lib/cassandra/0.6.rb +0 -0
  25. data/lib/cassandra/0.7/cassandra.rb +0 -270
  26. data/lib/cassandra/0.7/columns.rb +1 -64
  27. data/lib/cassandra/0.7/protocol.rb +0 -134
  28. data/lib/cassandra/0.7.rb +0 -0
  29. data/lib/cassandra/0.8/cassandra.rb +10 -0
  30. data/lib/cassandra/0.8/columns.rb +4 -0
  31. data/lib/cassandra/0.8/protocol.rb +23 -0
  32. data/lib/cassandra/0.8.rb +7 -0
  33. data/lib/cassandra/array.rb +0 -0
  34. data/lib/cassandra/cassandra.rb +877 -111
  35. data/lib/cassandra/{0.7/column_family.rb → column_family.rb} +0 -0
  36. data/lib/cassandra/columns.rb +72 -6
  37. data/lib/cassandra/comparable.rb +0 -0
  38. data/lib/cassandra/constants.rb +0 -0
  39. data/lib/cassandra/debug.rb +0 -0
  40. data/lib/cassandra/helpers.rb +1 -0
  41. data/lib/cassandra/{0.7/keyspace.rb → keyspace.rb} +0 -0
  42. data/lib/cassandra/long.rb +5 -0
  43. data/lib/cassandra/mock.rb +259 -85
  44. data/lib/cassandra/ordered_hash.rb +10 -18
  45. data/lib/cassandra/protocol.rb +120 -0
  46. data/lib/cassandra/time.rb +0 -0
  47. data/lib/cassandra.rb +6 -7
  48. data/test/cassandra_client_test.rb +0 -0
  49. data/test/cassandra_mock_test.rb +52 -28
  50. data/test/cassandra_test.rb +465 -44
  51. data/test/comparable_types_test.rb +0 -0
  52. data/test/eventmachine_test.rb +30 -30
  53. data/test/ordered_hash_test.rb +6 -0
  54. data/test/test_helper.rb +3 -2
  55. data/vendor/0.6/gen-rb/cassandra.rb +0 -0
  56. data/vendor/0.6/gen-rb/cassandra_constants.rb +0 -0
  57. data/vendor/0.6/gen-rb/cassandra_types.rb +0 -0
  58. data/vendor/0.7/gen-rb/cassandra.rb +0 -0
  59. data/vendor/0.7/gen-rb/cassandra_constants.rb +0 -0
  60. data/vendor/0.7/gen-rb/cassandra_types.rb +4 -2
  61. data/vendor/0.8/gen-rb/cassandra.rb +2215 -0
  62. data/vendor/0.8/gen-rb/cassandra_constants.rb +12 -0
  63. data/vendor/0.8/gen-rb/cassandra_types.rb +816 -0
  64. metadata +50 -27
  65. data/README.rdoc +0 -83
  66. data/cassandra.gemspec +0 -46
  67. data/conf/cassandra.yaml +0 -113
@@ -0,0 +1,45 @@
1
+ create keyspace Twitter with
2
+ placement_strategy = 'org.apache.cassandra.locator.SimpleStrategy' AND
3
+ replication_factor = 1;
4
+ use Twitter;
5
+ create column family Users with comparator = 'UTF8Type';
6
+ create column family UserAudits with comparator = 'UTF8Type';
7
+ create column family UserRelationships with
8
+ comparator = 'UTF8Type' and
9
+ column_type = 'Super' and
10
+ subcomparator = 'TimeUUIDType';
11
+ create column family Usernames with comparator = 'UTF8Type';
12
+ create column family Statuses with comparator = 'UTF8Type';
13
+ create column family StatusAudits with comparator = 'UTF8Type';
14
+ create column family StatusRelationships with
15
+ comparator = 'UTF8Type' and
16
+ column_type = 'Super' and
17
+ subcomparator = 'TimeUUIDType';
18
+ create column family Indexes with
19
+ comparator = 'UTF8Type' and
20
+ column_type = 'Super';
21
+ create column family TimelinishThings with
22
+ comparator = 'BytesType';
23
+
24
+ create keyspace Multiblog with
25
+ placement_strategy = 'org.apache.cassandra.locator.SimpleStrategy' AND
26
+ replication_factor = 1;
27
+ use Multiblog;
28
+ create column family Blogs with comparator = 'TimeUUIDType';
29
+ create column family Comments with comparator = 'TimeUUIDType';
30
+
31
+
32
+ create keyspace MultiblogLong with
33
+ placement_strategy = 'org.apache.cassandra.locator.SimpleStrategy' AND
34
+ replication_factor = 1;
35
+ use MultiblogLong;
36
+ create column family Blogs with comparator = 'LongType';
37
+ create column family Comments with comparator = 'LongType';
38
+
39
+ create keyspace TypeConversions with
40
+ placement_strategy = 'org.apache.cassandra.locator.SimpleStrategy' AND
41
+ replication_factor = 1;
42
+ use TypeConversions;
43
+ create column family UUIDColumnConversion with comparator = TimeUUIDType;
44
+ create column family SuperUUID with comparator = TimeUUIDType and column_type = Super;
45
+
@@ -0,0 +1,41 @@
1
+ # Licensed to the Apache Software Foundation (ASF) under one
2
+ # or more contributor license agreements. See the NOTICE file
3
+ # distributed with this work for additional information
4
+ # regarding copyright ownership. The ASF licenses this file
5
+ # to you under the Apache License, Version 2.0 (the
6
+ # "License"); you may not use this file except in compliance
7
+ # with the License. You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ if [ "x$CASSANDRA_HOME" = "x" ]; then
18
+ CASSANDRA_HOME=`dirname $0`/..
19
+ fi
20
+
21
+ # The directory where Cassandra's configs live (required)
22
+ if [ "x$CASSANDRA_CONF" = "x" ]; then
23
+ CASSANDRA_CONF=$CASSANDRA_HOME/conf
24
+ fi
25
+
26
+ # This can be the path to a jar file, or a directory containing the
27
+ # compiled classes. NOTE: This isn't needed by the startup script,
28
+ # it's just used here in constructing the classpath.
29
+ cassandra_bin=$CASSANDRA_HOME/build/classes/main
30
+ cassandra_bin=$cassandra_bin:$CASSANDRA_HOME/build/classes/thrift
31
+ #cassandra_bin=$cassandra_home/build/cassandra.jar
32
+
33
+ # JAVA_HOME can optionally be set here
34
+ #JAVA_HOME=/usr/local/jdk6
35
+
36
+ # The java classpath (required)
37
+ CLASSPATH=$CASSANDRA_CONF:$cassandra_bin
38
+
39
+ for jar in $CASSANDRA_HOME/lib/*.jar; do
40
+ CLASSPATH=$CLASSPATH:$jar
41
+ done
@@ -0,0 +1,61 @@
1
+ # Cassandra storage config YAML
2
+ cluster_name: 'Test'
3
+ initial_token:
4
+ auto_bootstrap: false
5
+ hinted_handoff_enabled: true
6
+ max_hint_window_in_ms: 3600000 # one hour
7
+ hinted_handoff_throttle_delay_in_ms: 50
8
+ authenticator: org.apache.cassandra.auth.AllowAllAuthenticator
9
+ authority: org.apache.cassandra.auth.AllowAllAuthority
10
+ partitioner: org.apache.cassandra.dht.RandomPartitioner
11
+
12
+ # directories where Cassandra should store data on disk.
13
+ data_file_directories:
14
+ - data/data
15
+ commitlog_directory: data/commitlog
16
+
17
+ # saved caches
18
+ saved_caches_directory: data/saved_caches
19
+
20
+ commitlog_rotation_threshold_in_mb: 128
21
+ commitlog_sync: periodic
22
+ commitlog_sync_period_in_ms: 10000
23
+ seed_provider:
24
+ - class_name: org.apache.cassandra.locator.SimpleSeedProvider
25
+ parameters:
26
+ - seeds: "127.0.0.1"
27
+ flush_largest_memtables_at: 0.75
28
+ reduce_cache_sizes_at: 0.85
29
+ reduce_cache_capacity_to: 0.6
30
+ concurrent_reads: 32
31
+ concurrent_writes: 32
32
+ memtable_flush_queue_size: 4
33
+ sliced_buffer_size_in_kb: 64
34
+ storage_port: 7000
35
+ listen_address: localhost
36
+ rpc_address: localhost
37
+ rpc_port: 9160
38
+ rpc_keepalive: true
39
+ thrift_framed_transport_size_in_mb: 15
40
+ thrift_max_message_length_in_mb: 16
41
+ incremental_backups: false
42
+ snapshot_before_compaction: false
43
+ column_index_size_in_kb: 64
44
+ in_memory_compaction_limit_in_mb: 64
45
+ concurrent_compactors: 1
46
+ compaction_throughput_mb_per_sec: 16
47
+ compaction_preheat_key_cache: true
48
+ rpc_timeout_in_ms: 10000
49
+ endpoint_snitch: org.apache.cassandra.locator.SimpleSnitch
50
+ dynamic_snitch: true
51
+ dynamic_snitch_update_interval_in_ms: 100
52
+ dynamic_snitch_reset_interval_in_ms: 600000
53
+ dynamic_snitch_badness_threshold: 0.0
54
+ request_scheduler: org.apache.cassandra.scheduler.NoScheduler
55
+ index_interval: 128
56
+ encryption_options:
57
+ internode_encryption: none
58
+ keystore: conf/.keystore
59
+ keystore_password: cassandra
60
+ truststore: conf/.truststore
61
+ truststore_password: cassandra
@@ -0,0 +1,40 @@
1
+ # Licensed to the Apache Software Foundation (ASF) under one
2
+ # or more contributor license agreements. See the NOTICE file
3
+ # distributed with this work for additional information
4
+ # regarding copyright ownership. The ASF licenses this file
5
+ # to you under the Apache License, Version 2.0 (the
6
+ # "License"); you may not use this file except in compliance
7
+ # with the License. You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ # for production, you should probably set pattern to %c instead of %l.
18
+ # (%l is slower.)
19
+
20
+ # output messages into a rolling log file as well as stdout
21
+ log4j.rootLogger=DEBUG,stdout,R
22
+
23
+ # stdout
24
+ log4j.appender.stdout=org.apache.log4j.ConsoleAppender
25
+ log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
26
+ log4j.appender.stdout.layout.ConversionPattern=%5p %d{HH:mm:ss,SSS} %m%n
27
+
28
+ # rolling log file
29
+ log4j.appender.R=org.apache.log4j.RollingFileAppender
30
+ log4j.appender.R.maxFileSize=20MB
31
+ log4j.appender.R.maxBackupIndex=50
32
+ log4j.appender.R.layout=org.apache.log4j.PatternLayout
33
+ log4j.appender.R.layout.ConversionPattern=%5p [%t] %d{ISO8601} %F (line %L) %m%n
34
+ # Edit the next line to point to your logs directory
35
+ log4j.appender.R.File=data/logs/system.log
36
+
37
+ # Application logging options
38
+ #log4j.logger.org.apache.cassandra=DEBUG
39
+ #log4j.logger.org.apache.cassandra.db=DEBUG
40
+ #log4j.logger.org.apache.cassandra.service.StorageProxy=DEBUG
@@ -0,0 +1,66 @@
1
+ {"Twitter":{
2
+ "Users":{
3
+ "comparator_type":"org.apache.cassandra.db.marshal.UTF8Type",
4
+ "column_type":"Standard"},
5
+ "UserAudits":{
6
+ "comparator_type":"org.apache.cassandra.db.marshal.UTF8Type",
7
+ "column_type":"Standard"},
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":{
18
+ "subcomparator_type":"org.apache.cassandra.db.marshal.TimeUUIDType",
19
+ "comparator_type":"org.apache.cassandra.db.marshal.UTF8Type",
20
+ "column_type":"Super"},
21
+ "Usernames":{
22
+ "comparator_type":"org.apache.cassandra.db.marshal.UTF8Type",
23
+ "column_type":"Standard"},
24
+ "Statuses":{
25
+ "comparator_type":"org.apache.cassandra.db.marshal.UTF8Type",
26
+ "column_type":"Standard"},
27
+ "StatusAudits":{
28
+ "comparator_type":"org.apache.cassandra.db.marshal.UTF8Type",
29
+ "column_type":"Standard"},
30
+ "StatusRelationships":{
31
+ "subcomparator_type":"org.apache.cassandra.db.marshal.TimeUUIDType",
32
+ "comparator_type":"org.apache.cassandra.db.marshal.UTF8Type",
33
+ "column_type":"Super"},
34
+ "Indexes":{
35
+ "comparator_type":"org.apache.cassandra.db.marshal.UTF8Type",
36
+ "column_type":"Super"},
37
+ "TimelinishThings":{
38
+ "comparator_type":"org.apache.cassandra.db.marshal.BytesType",
39
+ "column_type":"Standard"}
40
+ },
41
+ "Multiblog":{
42
+ "Blogs":{
43
+ "comparator_type":"org.apache.cassandra.db.marshal.TimeUUIDType",
44
+ "column_type":"Standard"},
45
+ "Comments":{
46
+ "comparator_type":"org.apache.cassandra.db.marshal.TimeUUIDType",
47
+ "column_type":"Standard"}
48
+ },
49
+ "MultiblogLong":{
50
+ "Blogs":{
51
+ "comparator_type":"org.apache.cassandra.db.marshal.LongType",
52
+ "column_type":"Standard"},
53
+ "Comments":{
54
+ "comparator_type":"org.apache.cassandra.db.marshal.LongType",
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"}
65
+ }
66
+ }
@@ -0,0 +1,51 @@
1
+ create keyspace Twitter with
2
+ placement_strategy = 'org.apache.cassandra.locator.LocalStrategy' AND
3
+ strategy_options = [{replication_factor:1}];
4
+ use Twitter;
5
+ create column family Users with comparator = 'UTF8Type';
6
+ create column family UserAudits with comparator = 'UTF8Type';
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
14
+ comparator = 'UTF8Type' and
15
+ column_type = 'Super' and
16
+ subcomparator = 'TimeUUIDType';
17
+ create column family Usernames with comparator = 'UTF8Type';
18
+ create column family Statuses with comparator = 'UTF8Type';
19
+ create column family StatusAudits with comparator = 'UTF8Type';
20
+ create column family StatusRelationships with
21
+ comparator = 'UTF8Type' and
22
+ column_type = 'Super' and
23
+ subcomparator = 'TimeUUIDType';
24
+ create column family Indexes with
25
+ comparator = 'UTF8Type' and
26
+ column_type = 'Super';
27
+ create column family TimelinishThings with
28
+ comparator = 'BytesType';
29
+
30
+ create keyspace Multiblog with
31
+ placement_strategy = 'org.apache.cassandra.locator.LocalStrategy' AND
32
+ strategy_options = [{replication_factor:1}];
33
+ use Multiblog;
34
+ create column family Blogs with comparator = 'TimeUUIDType';
35
+ create column family Comments with comparator = 'TimeUUIDType';
36
+
37
+
38
+ create keyspace MultiblogLong with
39
+ placement_strategy = 'org.apache.cassandra.locator.LocalStrategy' AND
40
+ strategy_options = [{replication_factor:1}];
41
+ use MultiblogLong;
42
+ create column family Blogs with comparator = 'LongType';
43
+ create column family Comments with comparator = 'LongType';
44
+
45
+ create keyspace TypeConversions with
46
+ placement_strategy = 'org.apache.cassandra.locator.LocalStrategy' AND
47
+ strategy_options = [{replication_factor:1}];
48
+ use TypeConversions;
49
+ create column family UUIDColumnConversion with comparator = TimeUUIDType;
50
+ create column family SuperUUID with comparator = TimeUUIDType and column_type = Super;
51
+
@@ -2,18 +2,46 @@ class Cassandra
2
2
  def self.DEFAULT_TRANSPORT_WRAPPER
3
3
  Thrift::BufferedTransport
4
4
  end
5
-
6
- ## Delete
7
5
 
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.
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)
15
42
  end
16
43
  end
44
+ alias truncate! clear_column_family!
17
45
 
18
46
  # Remove all rows in the keyspace. Supports options <tt>:consistency</tt> and
19
47
  # <tt>:timestamp</tt>.
@@ -23,6 +51,30 @@ class Cassandra
23
51
  schema.keys.each { |column_family| clear_column_family!(column_family, options) }
24
52
  end
25
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
+
26
78
  protected
27
79
 
28
80
  def schema(load=true)
@@ -41,13 +93,6 @@ class Cassandra
41
93
  def reconnect!
42
94
  @servers = all_nodes
43
95
  @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
96
  end
52
97
 
53
98
  def all_nodes
@@ -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(
@@ -31,5 +50,29 @@ class Cassandra
31
50
  )
32
51
  )
33
52
  end
53
+
54
+ # General info about a deletion object within a mutation
55
+ # timestamp - required. If this is the only param, it will cause deletion of the whole key at that TS
56
+ # supercolumn - opt. If passed, the deletes will only occur within that supercolumn (only subcolumns
57
+ # will be deleted). Otherwise the normal columns will be deleted.
58
+ # predicate - opt. Defines how to match the columns to delete. if supercolumn passed, the slice will
59
+ # be scoped to subcolumns of that supercolumn.
60
+
61
+ # Deletes a single column from the containing key/CF (and possibly supercolumn), at a given timestamp.
62
+ # Although mutations (as opposed to 'remove' calls) support deleting slices and lists of columns in one shot, this is not implemented here.
63
+ # The main reason being that the batch function takes removes, but removes don't have that capability...so we'd need to change the remove
64
+ # methods to use delete mutation calls...although that might have performance implications. We'll leave that refactoring for later.
65
+ def _delete_mutation(cf, column, subcolumn, timestamp, options={})
66
+ deletion_hash = {:timestamp => timestamp}
67
+ if is_super(cf)
68
+ deletion_hash[:super_column] = column if column
69
+ deletion_hash[:predicate] = CassandraThrift::SlicePredicate.new(:column_names => [subcolumn]) if subcolumn
70
+ else
71
+ deletion_hash[:predicate] = CassandraThrift::SlicePredicate.new(:column_names => [column]) if column
72
+ end
73
+ CassandraThrift::Mutation.new(
74
+ :deletion => CassandraThrift::Deletion.new(deletion_hash)
75
+ )
76
+ end
34
77
  end
35
78
  end
@@ -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
@@ -43,7 +44,7 @@ class Cassandra
43
44
  (sub_columns || columns).map { |name| result[klass.new(name)] }
44
45
  end
45
46
 
46
- def _multiget(column_family, keys, column, sub_column, count, start, finish, reversed, consistency)
47
+ def _multiget(column_family, keys, column, sub_column, start, finish, count, reversed, consistency)
47
48
  # Single values; count and range parameters have no effect
48
49
  if is_super(column_family) and sub_column
49
50
  column_path = CassandraThrift::ColumnPath.new(:column_family => column_family, :super_column => column, :column => sub_column)
@@ -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))
@@ -71,22 +72,19 @@ class Cassandra
71
72
  end
72
73
  end
73
74
 
74
- def _get_range(column_family, start, finish, count, consistency)
75
+ def _get_range(column_family, start_key, finish_key, key_count, columns, start, finish, count, consistency)
75
76
  column_parent = CassandraThrift::ColumnParent.new(:column_family => column_family)
76
- predicate = CassandraThrift::SlicePredicate.new(:slice_range => CassandraThrift::SliceRange.new(:start => '', :finish => ''))
77
- range = CassandraThrift::KeyRange.new(:start_key => start, :end_key => finish, :count => count)
78
- client.get_range_slices(@keyspace, column_parent, predicate, range, 1)
79
- end
80
-
81
- def _get_range_keys(column_family, start, finish, count, consistency)
82
- _get_range(column_family, start, finish, count, consistency).collect{|i| i.key }
83
- end
84
-
85
- def each_key(column_family)
86
- column_parent = CassandraThrift::ColumnParent.new(:column_family => column_family.to_s)
87
- predicate = CassandraThrift::SlicePredicate.new(:column_names => [])
88
- range = CassandraThrift::KeyRange.new(:start_key => '', :end_key => '')
89
- client.get_range_slices(@keyspace, column_parent, predicate, range, 1).each{|i| yield i.key }
77
+ predicate = if columns
78
+ CassandraThrift::SlicePredicate.new(:column_names => columns)
79
+ else
80
+ CassandraThrift::SlicePredicate.new(:slice_range =>
81
+ CassandraThrift::SliceRange.new(
82
+ :start => start,
83
+ :finish => finish,
84
+ :count => count))
85
+ end
86
+ range = CassandraThrift::KeyRange.new(:start_key => start_key, :end_key => finish_key, :count => key_count)
87
+ client.get_range_slices(@keyspace, column_parent, predicate, range, consistency)
90
88
  end
91
89
  end
92
- end
90
+ end
data/lib/cassandra/0.6.rb CHANGED
File without changes