Class: Cassandra
- Inherits:
-
Object
- Object
- Cassandra
- Defined in:
- lib/cassandra/cassandra.rb,
lib/cassandra.rb,
lib/cassandra/0.6.rb,
lib/cassandra/0.7.rb,
lib/cassandra/0.8.rb,
lib/cassandra/long.rb,
lib/cassandra/columns.rb,
lib/cassandra/helpers.rb,
lib/cassandra/constants.rb,
lib/cassandra/comparable.rb,
lib/cassandra/0.6/columns.rb,
lib/cassandra/0.7/columns.rb,
lib/cassandra/0.8/columns.rb,
lib/cassandra/0.6/protocol.rb,
lib/cassandra/0.7/keyspace.rb,
lib/cassandra/0.7/protocol.rb,
lib/cassandra/0.8/keyspace.rb,
lib/cassandra/0.8/protocol.rb,
lib/cassandra/ordered_hash.rb,
lib/cassandra/0.6/cassandra.rb,
lib/cassandra/0.7/cassandra.rb,
lib/cassandra/0.8/cassandra.rb,
lib/cassandra/0.7/column_family.rb,
lib/cassandra/0.8/column_family.rb,
lib/cassandra/mock.rb
Overview
OrderedHash is namespaced to prevent conflicts with other implementations
Defined Under Namespace
Modules: Columns, Consistency, Constants, Helpers, Protocol Classes: AccessError, ColumnFamily, Comparable, Keyspace, Long, Mock, OrderedHash, OrderedHashInt
Constant Summary collapse
- WRITE_DEFAULTS =
{ :count => 1000, :timestamp => nil, :consistency => Consistency::ONE, :ttl => nil }.freeze
- READ_DEFAULTS =
{ :count => 100, :start => nil, :finish => nil, :reversed => false, :consistency => Consistency::ONE }.freeze
- THRIFT_DEFAULTS =
{ :transport_wrapper => Thrift::BufferedTransport, :thrift_client_class => ThriftClient }.freeze
Instance Attribute Summary collapse
-
#auth_request ⇒ Object
readonly
Returns the value of attribute auth_request.
-
#keyspace ⇒ Object
Returns the value of attribute keyspace.
-
#schema(load = true) ⇒ Object
readonly
Returns the value of attribute schema.
-
#servers ⇒ Object
readonly
Returns the value of attribute servers.
-
#thrift_client_class ⇒ Object
readonly
Returns the value of attribute thrift_client_class.
-
#thrift_client_options ⇒ Object
readonly
Returns the value of attribute thrift_client_options.
Class Method Summary collapse
Instance Method Summary collapse
-
#add_column_family(cf_def) ⇒ Object
Read.
- #add_keyspace(ks_def) ⇒ Object
-
#batch(options = {}) ⇒ Object
Open a batch operation and yield self.
-
#clear_keyspace! ⇒ Object
Remove all rows in the keyspace.
- #cluster_name ⇒ Object
-
#count_columns(column_family, key, *columns_and_options) ⇒ Object
Count the elements at the column_family:key: path you request.
-
#count_range(column_family, options = {}) ⇒ Object
Count all rows in the column_family you request.
- #create_idx_clause(idx_expressions, start = "") ⇒ Object
- #create_idx_expr(c_name, value, op) ⇒ Object
-
#create_index(ks_name, cf_name, c_name, v_class) ⇒ Object
2ary Indexing.
- #disable_node_auto_discovery! ⇒ Object
- #disconnect! ⇒ Object
- #drop_column_family(cf_name) ⇒ Object
- #drop_index(ks_name, cf_name, c_name) ⇒ Object
- #drop_keyspace(ks_name) ⇒ Object
-
#each(column_family, options = {}) ⇒ Object
Iterate through each row and yields each key and value within the given parameters.
-
#each_key(column_family, options = {}) ⇒ Object
Iterate through each key within the given parameters.
-
#exists?(column_family, key, *columns_and_options) ⇒ Boolean
Return true if the column_family:key::[sub_column] path you request exists.
-
#get(column_family, key, *columns_and_options) ⇒ Object
Return a hash (actually, a Cassandra::OrderedHash) or a single value representing the element at the column_family:key::[sub_column] path you request.
-
#get_columns(column_family, key, *columns_and_options) ⇒ Object
Return a list of single values for the elements at the column_family:key:column:[sub_columns] path you request.
-
#get_indexed_slices(column_family, idx_clause, *columns_and_options) ⇒ Object
TODO: Supercolumn support.
-
#get_range(column_family, options = {}) ⇒ Object
Return an OrderedHash containing the columns specified for the given range of keys in the column_family you request.
- #get_range_batch(column_family, options = {}) ⇒ Object
-
#get_range_keys(column_family, options = {}) ⇒ Object
Return an Array containing all of the keys within a given range.
- #get_range_single(column_family, options = {}) ⇒ Object
-
#initialize(keyspace, servers = "127.0.0.1:9160", thrift_client_options = {}) ⇒ Cassandra
constructor
Create a new Cassandra instance and open the connection.
-
#insert(column_family, key, hash, options = {}) ⇒ Object
Insert a row for a key.
- #inspect ⇒ Object
- #keyspaces ⇒ Object
- #login!(username, password) ⇒ Object
-
#multi_count_columns(column_family, keys, *options) ⇒ Object
Multi-key version of Cassandra#count_columns.
-
#multi_get(column_family, keys, *columns_and_options) ⇒ Object
Multi-key version of Cassandra#get.
-
#multi_get_columns(column_family, keys, *options) ⇒ Object
Multi-key version of Cassandra#get_columns.
- #partitioner ⇒ Object
-
#remove(column_family, key, *columns_and_options) ⇒ Object
_mutate the element at the column_family:key::[sub_column] path you request.
- #rename_column_family(old_name, new_name) ⇒ Object
- #rename_keyspace(old_name, new_name) ⇒ Object
- #ring ⇒ Object
- #schema_agreement? ⇒ Boolean
- #update_column_family(cf_def) ⇒ Object
- #update_keyspace(ks_def) ⇒ Object
- #version ⇒ Object
Methods included from Helpers
#extract_and_validate_params, #s_map
Methods included from Columns
#column_family_property, #column_name_class, #is_super, #sub_column_name_class
Constructor Details
#initialize(keyspace, servers = "127.0.0.1:9160", thrift_client_options = {}) ⇒ Cassandra
Create a new Cassandra instance and open the connection.
70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/cassandra/cassandra.rb', line 70 def initialize(keyspace, servers = "127.0.0.1:9160", = {}) @is_super = {} @column_name_class = {} @sub_column_name_class = {} @auto_discover_nodes = true [:transport_wrapper] ||= Cassandra.DEFAULT_TRANSPORT_WRAPPER @thrift_client_options = THRIFT_DEFAULTS.merge() @thrift_client_class = @thrift_client_options[:thrift_client_class] @keyspace = keyspace @servers = Array(servers) end |
Instance Attribute Details
#auth_request ⇒ Object (readonly)
Returns the value of attribute auth_request.
67 68 69 |
# File 'lib/cassandra/cassandra.rb', line 67 def auth_request @auth_request end |
#keyspace ⇒ Object
Returns the value of attribute keyspace.
67 68 69 |
# File 'lib/cassandra/cassandra.rb', line 67 def keyspace @keyspace end |
#schema(load = true) ⇒ Object (readonly)
Returns the value of attribute schema.
67 68 69 |
# File 'lib/cassandra/cassandra.rb', line 67 def schema @schema end |
#servers ⇒ Object (readonly)
Returns the value of attribute servers.
67 68 69 |
# File 'lib/cassandra/cassandra.rb', line 67 def servers @servers end |
#thrift_client_class ⇒ Object (readonly)
Returns the value of attribute thrift_client_class.
67 68 69 |
# File 'lib/cassandra/cassandra.rb', line 67 def thrift_client_class @thrift_client_class end |
#thrift_client_options ⇒ Object (readonly)
Returns the value of attribute thrift_client_options.
67 68 69 |
# File 'lib/cassandra/cassandra.rb', line 67 def @thrift_client_options end |
Class Method Details
.DEFAULT_TRANSPORT_WRAPPER ⇒ Object
2 3 4 |
# File 'lib/cassandra/0.6/cassandra.rb', line 2 def self.DEFAULT_TRANSPORT_WRAPPER Thrift::BufferedTransport end |
.VERSION ⇒ Object
2 3 4 |
# File 'lib/cassandra/0.6.rb', line 2 def self.VERSION "0.6" end |
Instance Method Details
#add_column_family(cf_def) ⇒ Object
Read
71 72 73 74 75 76 77 78 79 |
# File 'lib/cassandra/0.7/cassandra.rb', line 71 def add_column_family(cf_def) begin res = client.system_add_column_family(cf_def) rescue CassandraThrift::TimedOutException => te puts "Timed out: #{te.inspect}" end @schema = nil res end |
#add_keyspace(ks_def) ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/cassandra/0.7/cassandra.rb', line 111 def add_keyspace(ks_def) begin res = client.system_add_keyspace(ks_def) rescue CassandraThrift::TimedOutException => toe puts "Timed out: #{toe.inspect}" rescue Thrift::TransportException => te puts "Timed out: #{te.inspect}" end @keyspaces = nil res end |
#batch(options = {}) ⇒ Object
Open a batch operation and yield self. Inserts and deletes will be queued until the block closes, and then sent atomically to the server. Supports the :consistency
option, which overrides the consistency set in the individual commands.
349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 |
# File 'lib/cassandra/cassandra.rb', line 349 def batch( = {}) _, _, _, = extract_and_validate_params(schema.keys.first, "", [], WRITE_DEFAULTS) @batch = [] yield(self) compacted_map,seen_clevels = compact_mutations! clevel = if [:consistency] != nil # Override any clevel from individual mutations if [:consistency] elsif seen_clevels.length > 1 # Cannot choose which CLevel to use if there are several ones raise "Multiple consistency levels used in the batch, and no override...cannot pick one" else # if no consistency override has been provided but all the clevels in the batch are the same: use that one seen_clevels.first end _mutate(compacted_map,clevel) ensure @batch = nil end |
#clear_keyspace! ⇒ Object
Remove all rows in the keyspace.
23 24 25 |
# File 'lib/cassandra/0.6/cassandra.rb', line 23 def clear_keyspace!( = {}) schema.keys.each { |column_family| clear_column_family!(column_family, ) } end |
#cluster_name ⇒ Object
44 45 46 |
# File 'lib/cassandra/0.7/cassandra.rb', line 44 def cluster_name @cluster_name ||= client.describe_cluster_name() end |
#count_columns(column_family, key, *columns_and_options) ⇒ Object
Count the elements at the column_family:key: path you request. Supports the :consistency
option.
167 168 169 170 171 |
# File 'lib/cassandra/cassandra.rb', line 167 def count_columns(column_family, key, *) column_family, super_column, _, = extract_and_validate_params(column_family, key, , READ_DEFAULTS) _count_columns(column_family, key, super_column, [:consistency]) end |
#count_range(column_family, options = {}) ⇒ Object
Count all rows in the column_family you request. Supports the :start_key
, :finish_key
, and :consistency
options. Please note that :start_key
and :finish_key
only work properly when OrderPreservingPartitioner.
306 307 308 |
# File 'lib/cassandra/cassandra.rb', line 306 def count_range(column_family, = {}) get_range_keys(column_family, ).length end |
#create_idx_clause(idx_expressions, start = "") ⇒ Object
226 227 228 229 230 |
# File 'lib/cassandra/0.7/cassandra.rb', line 226 def create_idx_clause(idx_expressions, start = "") CassandraThrift::IndexClause.new( :start_key => start, :expressions => idx_expressions) end |
#create_idx_expr(c_name, value, op) ⇒ Object
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
# File 'lib/cassandra/0.7/cassandra.rb', line 208 def create_idx_expr(c_name, value, op) CassandraThrift::IndexExpression.new( :column_name => c_name, :value => value, :op => (case op when nil, "EQ", "eq", "==" CassandraThrift::IndexOperator::EQ when "GTE", "gte", ">=" CassandraThrift::IndexOperator::GTE when "GT", "gt", ">" CassandraThrift::IndexOperator::GT when "LTE", "lte", "<=" CassandraThrift::IndexOperator::LTE when "LT", "lt", "<" CassandraThrift::IndexOperator::LT end )) end |
#create_index(ks_name, cf_name, c_name, v_class) ⇒ Object
2ary Indexing
187 188 189 190 191 192 193 194 195 196 197 198 |
# File 'lib/cassandra/0.7/cassandra.rb', line 187 def create_index(ks_name, cf_name, c_name, v_class) cf_def = client.describe_keyspace(ks_name).cf_defs.find{|x| x.name == cf_name} if !cf_def.nil? and !cf_def..find{|x| x.name == c_name} c_def = CassandraThrift::ColumnDef.new do |cd| cd.name = c_name cd.validation_class = "org.apache.cassandra.db.marshal."+v_class cd.index_type = CassandraThrift::IndexType::KEYS end cf_def..push(c_def) update_column_family(cf_def) end end |
#disable_node_auto_discovery! ⇒ Object
82 83 84 |
# File 'lib/cassandra/cassandra.rb', line 82 def disable_node_auto_discovery! @auto_discover_nodes = false end |
#disconnect! ⇒ Object
86 87 88 89 90 91 |
# File 'lib/cassandra/cassandra.rb', line 86 def disconnect! if @client @client.disconnect! @client = nil end end |
#drop_column_family(cf_name) ⇒ Object
81 82 83 84 85 86 87 88 89 |
# File 'lib/cassandra/0.7/cassandra.rb', line 81 def drop_column_family(cf_name) begin res = client.system_drop_column_family(cf_name) rescue CassandraThrift::TimedOutException => te puts "Timed out: #{te.inspect}" end @schema = nil res end |
#drop_index(ks_name, cf_name, c_name) ⇒ Object
200 201 202 203 204 205 206 |
# File 'lib/cassandra/0.7/cassandra.rb', line 200 def drop_index(ks_name, cf_name, c_name) cf_def = client.describe_keyspace(ks_name).cf_defs.find{|x| x.name == cf_name} if !cf_def.nil? and cf_def..find{|x| x.name == c_name} cf_def..delete_if{|x| x.name == c_name} update_column_family(cf_def) end end |
#drop_keyspace(ks_name) ⇒ Object
123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/cassandra/0.7/cassandra.rb', line 123 def drop_keyspace(ks_name) begin res = client.system_drop_keyspace(ks_name) rescue CassandraThrift::TimedOutException => toe puts "Timed out: #{toe.inspect}" rescue Thrift::TransportException => te puts "Timed out: #{te.inspect}" end keyspace = "system" if ks_name.eql?(@keyspace) @keyspaces = nil res end |
#each(column_family, options = {}) ⇒ Object
Iterate through each row and yields each key and value within the given parameters. This function can be used to iterate over each key in the given column family. However, if you only want to walk through a range of keys you need to have your cluster setup with OrderPreservingPartitioner. Please note that this function walks the list of keys in batches using the passed in :count
option. Supports the :key_count
, :start_key
, :finish_key
, :columns
, :start
, :finish
, :count
, and :consistency
options.
339 340 341 342 343 |
# File 'lib/cassandra/cassandra.rb', line 339 def each(column_family, = {}) get_range_batch(column_family, ) do |key, columns| yield key, columns end end |
#each_key(column_family, options = {}) ⇒ Object
Iterate through each key within the given parameters. This function can be used to iterate over each key in the given column family. However, if you only want to walk through a range of keys you need to have your cluster setup with OrderPreservingPartitioner. Please note that this function walks the list of keys in batches using the passed in :count
option. Supports :start_key
, :finish_key
, :count
, and :consistency
options.
325 326 327 328 329 |
# File 'lib/cassandra/cassandra.rb', line 325 def each_key(column_family, = {}) get_range_batch(column_family, ) do |key, columns| yield key end end |
#exists?(column_family, key, *columns_and_options) ⇒ Boolean
Return true if the column_family:key::[sub_column] path you request exists. Supports the :consistency
option.
219 220 221 222 223 224 225 226 227 |
# File 'lib/cassandra/cassandra.rb', line 219 def exists?(column_family, key, *) column_family, column, sub_column, = extract_and_validate_params(column_family, key, , READ_DEFAULTS) if column _multiget(column_family, [key], column, sub_column, 1, nil, nil, nil, [:consistency])[key] else _multiget(column_family, [key], nil, nil, 1, '', '', false, [:consistency])[key] end end |
#get(column_family, key, *columns_and_options) ⇒ Object
Return a hash (actually, a Cassandra::OrderedHash) or a single value representing the element at the column_family:key::[sub_column] path you request. Supports options :count
, :start
, :finish
, :reversed
, and :consistency
.
200 201 202 |
# File 'lib/cassandra/cassandra.rb', line 200 def get(column_family, key, *) multi_get(column_family, [key], *)[key] end |
#get_columns(column_family, key, *columns_and_options) ⇒ Object
Return a list of single values for the elements at the column_family:key:column:[sub_columns] path you request. Supports the :consistency
option.
183 184 185 186 187 |
# File 'lib/cassandra/cassandra.rb', line 183 def get_columns(column_family, key, *) column_family, columns, sub_columns, = extract_and_validate_params(column_family, key, , READ_DEFAULTS) _get_columns(column_family, key, columns, sub_columns, [:consistency]) end |
#get_indexed_slices(column_family, idx_clause, *columns_and_options) ⇒ Object
TODO: Supercolumn support.
233 234 235 236 237 238 239 240 |
# File 'lib/cassandra/0.7/cassandra.rb', line 233 def get_indexed_slices(column_family, idx_clause, *) column_family, columns, _, = extract_and_validate_params(column_family, [], , READ_DEFAULTS) key_slices = _get_indexed_slices(column_family, idx_clause, columns, [:count], [:start], [:finish], [:reversed], [:consistency]) key_slices.inject({}){|h, key_slice| h[key_slice.key] = key_slice.columns; h} end |
#get_range(column_family, options = {}) ⇒ Object
Return an OrderedHash containing the columns specified for the given range of keys in the column_family you request. Only works well if the table is partitioned with OrderPreservingPartitioner. Supports the :key_count
, :start_key
, :finish_key
, :columns
, :start
, :finish
, :count
, and :consistency
options. Please note that Cassandra returns a row for each row that has existed in the system since gc_grace_seconds. This is because deleted row keys are marked as deleted, but left in the system until the cluster has had resonable time to replicate the deletion. This function attempts to suppress deleted rows (actually any row returned without columns is suppressed).
240 241 242 243 244 245 246 |
# File 'lib/cassandra/cassandra.rb', line 240 def get_range(column_family, = {}) if block_given? || [:key_count] || [:batch_size] get_range_batch(column_family, ) else get_range_single(column_family, ) end end |
#get_range_batch(column_family, options = {}) ⇒ Object
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 |
# File 'lib/cassandra/cassandra.rb', line 273 def get_range_batch(column_family, = {}) batch_size = .delete(:batch_size) || 100 count = .delete(:key_count) result = {} [:start_key] ||= '' last_key = nil while [:start_key] != last_key && (count.nil? || count > result.length) [:start_key] = last_key res = get_range_single(column_family, .merge!(:start_key => last_key, :key_count => batch_size, :return_empty_rows => true )) res.each do |key, columns| next if [:start_key] == key next if result.length == count unless columns == {} yield key, columns if block_given? result[key] = columns end last_key = key end end result end |
#get_range_keys(column_family, options = {}) ⇒ Object
Return an Array containing all of the keys within a given range. (Only works properly if the Cassandra cluster is using the OrderPreservingPartitioner.) Supports :start_key
, :finish_key
, :count
, and :consistency
options.
314 315 316 |
# File 'lib/cassandra/cassandra.rb', line 314 def get_range_keys(column_family, = {}) get_range(column_family,.merge!(:count => 1)).keys end |
#get_range_single(column_family, options = {}) ⇒ Object
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 |
# File 'lib/cassandra/cassandra.rb', line 248 def get_range_single(column_family, = {}) return_empty_rows = .delete(:return_empty_rows) || false column_family, _, _, = extract_and_validate_params(column_family, "", [], READ_DEFAULTS.merge(:start_key => '', :end_key => '', :key_count => 100, :columns => nil ) ) results = _get_range( column_family, [:start_key].to_s, [:finish_key].to_s, [:key_count], [:columns], [:start].to_s, [:finish].to_s, [:count], [:consistency] ) multi_key_slices_to_hash(column_family, results, return_empty_rows) end |
#insert(column_family, key, hash, options = {}) ⇒ Object
Insert a row for a key. Pass a flat hash for a regular column family, and a nested hash for a super column family. Supports the :consistency
, :timestamp
and :ttl
options.
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/cassandra/cassandra.rb', line 114 def insert(column_family, key, hash, = {}) column_family, _, _, = extract_and_validate_params(column_family, key, [], WRITE_DEFAULTS) = [:timestamp] || Time.stamp mutation_map = if is_super(column_family) { key => { column_family => hash.collect{|k,v| _super_insert_mutation(column_family, k, v, , [:ttl]) } } } else { key => { column_family => hash.collect{|k,v| _standard_insert_mutation(column_family, k, v, , [:ttl])} } } end @batch ? @batch << [mutation_map, [:consistency]] : _mutate(mutation_map, [:consistency]) end |
#inspect ⇒ Object
103 104 105 106 107 |
# File 'lib/cassandra/cassandra.rb', line 103 def inspect "#<Cassandra:#{object_id}, @keyspace=#{keyspace.inspect}, @schema={#{ schema(false).map {|name, hash| ":#{name} => #{hash['type'].inspect}"}.join(', ') }}, @servers=#{servers.inspect}>" end |
#keyspaces ⇒ Object
93 94 95 |
# File 'lib/cassandra/cassandra.rb', line 93 def keyspaces @keyspaces ||= client.describe_keyspaces() end |
#login!(username, password) ⇒ Object
97 98 99 100 101 |
# File 'lib/cassandra/cassandra.rb', line 97 def login!(username, password) @auth_request = CassandraThrift::AuthenticationRequest.new @auth_request.credentials = {'username' => username, 'password' => password} client.login(@keyspace, @auth_request) end |
#multi_count_columns(column_family, keys, *options) ⇒ Object
Multi-key version of Cassandra#count_columns. Supports options :count
, :start
, :finish
, :reversed
, and :consistency
. FIXME Not real multi; needs server support
176 177 178 |
# File 'lib/cassandra/cassandra.rb', line 176 def multi_count_columns(column_family, keys, *) OrderedHash[*keys.map { |key| [key, count_columns(column_family, key, *)] }._flatten_once] end |
#multi_get(column_family, keys, *columns_and_options) ⇒ Object
Multi-key version of Cassandra#get. Supports options :count
, :start
, :finish
, :reversed
, and :consistency
.
206 207 208 209 210 211 212 213 214 215 |
# File 'lib/cassandra/cassandra.rb', line 206 def multi_get(column_family, keys, *) column_family, column, sub_column, = extract_and_validate_params(column_family, keys, , READ_DEFAULTS) hash = _multiget(column_family, keys, column, sub_column, [:count], [:start], [:finish], [:reversed], [:consistency]) # Restore order ordered_hash = OrderedHash.new keys.each { |key| ordered_hash[key] = hash[key] || (OrderedHash.new if is_super(column_family) and !sub_column) } ordered_hash end |
#multi_get_columns(column_family, keys, *options) ⇒ Object
Multi-key version of Cassandra#get_columns. Supports the :consistency
option. FIXME Not real multi; needs to use a Column predicate
192 193 194 |
# File 'lib/cassandra/cassandra.rb', line 192 def multi_get_columns(column_family, keys, *) OrderedHash[*keys.map { |key| [key, get_columns(column_family, key, *)] }._flatten_once] end |
#partitioner ⇒ Object
52 53 54 |
# File 'lib/cassandra/0.7/cassandra.rb', line 52 def partitioner client.describe_partitioner() end |
#remove(column_family, key, *columns_and_options) ⇒ Object
_mutate the element at the column_family:key::[sub_column] path you request. Supports the :consistency
and :timestamp
options. TODO: we could change this function or add another that support multi-column removal (by list or predicate)
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/cassandra/cassandra.rb', line 142 def remove(column_family, key, *) column_family, column, sub_column, = extract_and_validate_params(column_family, key, , WRITE_DEFAULTS) if @batch mutation_map = { key => { column_family => [ _delete_mutation(column_family, column, sub_column, [:timestamp]|| Time.stamp) ] } } @batch << [mutation_map, [:consistency]] else # Let's continue using the 'remove' thrift method...not sure about the implications/performance of using the mutate instead # Otherwise we coul get use the mutation_map above, and do _mutate(mutation_map, options[:consistency]) args = {:column_family => column_family} columns = is_super(column_family) ? {:super_column => column, :column => sub_column} : {:column => column} column_path = CassandraThrift::ColumnPath.new(args.merge(columns)) _remove(key, column_path, [:timestamp] || Time.stamp, [:consistency]) end end |
#rename_column_family(old_name, new_name) ⇒ Object
91 92 93 94 95 96 97 98 99 |
# File 'lib/cassandra/0.7/cassandra.rb', line 91 def rename_column_family(old_name, new_name) begin res = client.system_rename_column_family(old_name, new_name) rescue CassandraThrift::TimedOutException => te puts "Timed out: #{te.inspect}" end @schema = nil res end |
#rename_keyspace(old_name, new_name) ⇒ Object
136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/cassandra/0.7/cassandra.rb', line 136 def rename_keyspace(old_name, new_name) begin res = client.system_rename_keyspace(old_name, new_name) rescue CassandraThrift::TimedOutException => toe puts "Timed out: #{toe.inspect}" rescue Thrift::TransportException => te puts "Timed out: #{te.inspect}" end keyspace = new_name if old_name.eql?(@keyspace) @keyspaces = nil res end |
#ring ⇒ Object
48 49 50 |
# File 'lib/cassandra/0.7/cassandra.rb', line 48 def ring client.describe_ring(@keyspace) end |
#schema_agreement? ⇒ Boolean
36 37 38 |
# File 'lib/cassandra/0.7/cassandra.rb', line 36 def schema_agreement? client.describe_schema_versions().length == 1 end |
#update_column_family(cf_def) ⇒ Object
101 102 103 104 105 106 107 108 109 |
# File 'lib/cassandra/0.7/cassandra.rb', line 101 def update_column_family(cf_def) begin res = client.system_update_column_family(cf_def) rescue CassandraThrift::TimedOutException => te puts "Timed out: #{te.inspect}" end @schema = nil res end |
#update_keyspace(ks_def) ⇒ Object
149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/cassandra/0.7/cassandra.rb', line 149 def update_keyspace(ks_def) begin res = client.system_update_keyspace(ks_def) rescue CassandraThrift::TimedOutException => toe puts "Timed out: #{toe.inspect}" rescue Thrift::TransportException => te puts "Timed out: #{te.inspect}" end @keyspaces = nil res end |
#version ⇒ Object
40 41 42 |
# File 'lib/cassandra/0.7/cassandra.rb', line 40 def version client.describe_version() end |