GithubHelp home page GithubHelp logo

cassandra-rb / cassandra Goto Github PK

View Code? Open in Web Editor NEW
663.0 102.0 155.0 1.15 MB

A Ruby client for the Cassandra distributed database

License: Apache License 2.0

Perl 2.82% Ruby 90.30% Erlang 1.17% Shell 4.56% C 1.14%

cassandra's Introduction

cassandra

A Ruby client for the Cassandra distributed database.

Supports 1.8.7, 1.9.2, 1.9.3, 2.0.0, 2.1 and rubinius on Cassandra 0.7.x through 2.0.x.

Status of this gem

There is no longer much development effort being put into this gem. If you are just getting started with Cassandra then you probably want to use the Datastax ruby-driver.

We are still happy to take patches if you want to improve this gem.

Getting Started

Here is a quick sample of the general use (more details in Read/Write API below):

require 'cassandra'
client = Cassandra.new('Twitter', '127.0.0.1:9160')
client.insert(:Users, "5", {'screen_name' => "buttonscat"})

License

Copyright 2009-2011 Twitter, Inc. See included LICENSE file. Portions copyright 2004-2009 David Heinemeier Hansson, and used with permission.

Cassandra Version

The Cassandra project is under very active development, and as such there are a few different versions that you may need to use this gem with. We have set up an easy sure fire mechanism for selecting the specific version that you are connecting to while requiring the gem.

Require Method

The default version is the currently stable release of cassandra. (0.8 at this time.)

To use the default version simply use a normal require:

require 'cassandra'

To use a specific version (1.0 in this example) you would use a slightly differently formatted require:

require 'cassandra/1.0'

Environment Variable Method

These mechanisms work well when you are using the cassandra gem in your own projects or irb, but if you would rather not hard code your app to a specific version you can always specify an environment variable with the version you are using:

export CASSANDRA_VERSION=0.8

Then you would use the default require as listed above:

require 'cassandra'

Read/Write API Method Reference

insert

  • column_family - The column_family that you are inserting into.
  • key - The row key to insert.
  • hash - The columns or super columns to insert.
  • options - Valid options are:
    • :timestamp - Uses the current time if none specified.
    • :consistency - Uses the default write consistency if none specified.
    • :ttl - If specified this is the number of seconds after the insert that this value will be available.

This is the main method used to insert rows into cassandra. If the column_family that you are inserting into is a SuperColumnFamily then the hash passed in should be a nested hash, otherwise it should be a flat hash.

This method can also be called while in batch mode. If in batch mode then we queue up the mutations (an insert in this case) and pass them to cassandra in a single batch at the end of the block.

Example:

@client.insert(:Statuses, key, {'body' => 'v', 'user' => 'v'})

columns = {@uuids[1] => 'v1', @uuids[2] => 'v2'}
@client.insert(:StatusRelationships, key, {'user_timelines' => columns})

remove

  • column_family - The column_family that you are working with.
  • key - The row key to remove (or remove columns from).
  • columns - Either a single super_column or a list of columns to remove.
  • sub_columns - The list of sub_columns to remove.
  • options - Valid options are:
    • :timestamp - Uses the current time if none specified.
    • :consistency - Uses the default write consistency if none specified.

This method is used to delete (actually marking them as deleted with a tombstone) rows, columns, or super columns depending on the parameters passed. If only a key is passed the entire row will be marked as deleted. If a column name is passed in that column will be deleted.

Example:

@client.insert(:Statuses, key, {'body' => 'v', 'subject' => 'v'})

@client.remove(:Statuses, key, 'body')    # removes the 'body' column
@client.remove(:Statuses, key)            # removes the row

count_columns

Count the columns for the provided parameters.

  • column_family - The column_family that you are working with.
  • key - The row key.
  • columns - Either a single super_column or a list of columns.
  • sub_columns - The list of sub_columns to select.
  • options - Valid options are:
    • :start - The column name to start from.
    • :stop - The column name to stop at.
    • :count - The maximum count of columns to return. (By default cassandra will count up to 100 columns)
    • :consistency - Uses the default read consistency if none specified.

Example:

@client.insert(:Statuses, key, {'body' => 'v1', 'user' => 'v2'})
@client.count_columns(:Statuses, key)     # returns 2

get

Return a hash (actually, a Cassandra::OrderedHash) or a single value representing the element at the column_family:key:[column]:[sub_column] path you request.

  • column_family - The column_family that you are working with.
  • key - The row key to select.
  • columns - Either a single super_column or a list of columns.
  • sub_columns - The list of sub_columns to select.
  • options - Valid options are:
    • :count - The number of columns requested to be returned.
    • :start - The starting value for selecting a range of columns.
    • :finish - The final value for selecting a range of columns.
    • :reversed - If set to true the results will be returned in reverse order.
    • :consistency - Uses the default read consistency if none specified.

Example:

@client.insert(:Users, key, {'body' => 'v', 'user' => 'v'})
@client.get(:Users, key))           # returns {'body' => 'v', 'user' => 'v'}

multi_get

Multi-key version of Cassandra#get.

This method allows you to select multiple rows with a single query. If a key that is passed in doesn't exist an empty hash will be returned.

Supports the same parameters as Cassandra#get.

  • column_family - The column_family that you are working with.
  • key - An array of keys to select.
  • columns - Either a single super_column or a list of columns.
  • sub_columns - The list of sub_columns to select.
  • options - Valid options are:
    • :count - The number of columns requested to be returned.
    • :start - The starting value for selecting a range of columns.
    • :finish - The final value for selecting a range of columns.
    • :reversed - If set to true the results will be returned in reverse order.
    • :consistency - Uses the default read consistency if none specified.

Example:

@client.insert(:Users, '1', {'body' => 'v1', 'user' => 'v1'})
@client.insert(:Users, '2', {'body' => 'v2', 'user' => 'v2'})

expected = OrderedHash[
              '1', {'body' => 'v1', 'user' => 'v1'},
              '2', {'body' => 'v2', 'user' => 'v2'},
              'bogus', {}
          ]
result = @client.multi_get(:Users, ['1', '2', 'bogus'])

exists?

Return true if the column_family:key:[column]:[sub_column] path you request exists.

If passed in only a row key it will query for any columns (limiting to 1) for that row key. If a column is passed in it will query for that specific column/super column.

This method will return true or false.

  • column_family - The column_family that you are working with.
  • key - The row key to check.
  • columns - Either a single super_column or a list of columns.
  • sub_columns - The list of sub_columns to check.
  • options - Valid options are:
    • :consistency - Uses the default read consistency if none specified.

Example:

@client.insert(:Statuses, 'key', {'body' => 'v'})
@client.exists?(:Statuses, 'key')                   # returns true
@client.exists?(:Statuses, 'bogus')                 # returns false
@client.exists?(:Statuses, 'key', 'body')           # returns true
@client.exists?(:Statuses, 'key', 'bogus')          # returns false

get_range

Return an Cassandra::OrderedHash containing the columns specified for the given range of keys in the column_family you request.

This method is just a convenience wrapper around Cassandra#get_range_single and Cassandra#get_range_batch. If :key_size, :batch_size, or a block is passed in Cassandra#get_range_batch will be called. Otherwise Cassandra#get_range_single will be used.

The start_key and finish_key parameters are only useful for iterating of all records as is done in the Cassandra#each and Cassandra#each_key methods if you are using the RandomPartitioner.

If the table is partitioned with OrderPreservingPartitioner you may use the start_key and finish_key params to select all records with the same prefix value.

If a block is passed in we will yield the row key and columns for each record returned.

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).

  • column_family - The column_family that you are working with.
  • options - Valid options are:
    • :start_key - The starting value for selecting a range of keys (only useful with OPP).
    • :finish_key - The final value for selecting a range of keys (only useful with OPP).
    • :key_count - The total number of keys to return from the query. (see note regarding deleted records)
    • :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.
    • :columns - A list of columns to return.
    • :count - The number of columns requested to be returned.
    • :start - The starting value for selecting a range of columns.
    • :finish - The final value for selecting a range of columns.
    • :reversed - If set to true the results will be returned in reverse order.
    • :consistency - Uses the default read consistency if none specified.

Example:

10.times do |i|
  @client.insert(:Statuses, i.to_s, {'body' => '1'})
end

@client.get_range_keys(:Statuses, :key_count => 4)

# returns:
#{
#  '0' => {'body' => '1'},
#  '1' => {'body' => '1'},
#  '2' => {'body' => '1'},
#  '3' => {'body' => '1'}
#}

count_range

Return an Array containing all of the keys within a given range.

This method just calls Cassandra#get_range and returns the row keys for the records returned.

See Cassandra#get_range for options.

get_range_keys

Return an Array containing all of the keys within a given range.

This method just calls Cassandra#get_range and returns the row keys for the records returned.

See Cassandra#get_range for options.

each_key

Iterate through each key within the given range parameters. This function can be used to iterate over each key in the given column family.

This method just calls Cassandra#get_range and yields each row key.

See Cassandra#get_range for options.

Example: 10.times do |i| @client.insert(:Statuses, k + i.to_s, {"body-#{i.to_s}" => 'v'}) end

@client.each_key(:Statuses) do |key|
  print key
end

# returns 0123456789

each

Iterate through each row within the given column_family.

This method just calls Cassandra#get_range and yields the key and columns.

See Cassandra#get_range for options.

get_index_slices

This method is used to query a secondary index with a set of provided search parameters

Please note that you can either specify a CassandraThrift::IndexClause or an array of hashes with the format as below.

  • column_family - The Column Family this operation will be run on.
  • index_clause - This can either be a CassandraThrift::IndexClause or an array of hashes with the following keys:
    • :column_name - Column to be compared
    • :value - Value to compare against
    • :comparison - Type of comparison to do.
  • options
    • :key_count - Set maximum number of rows to return. (Only works if CassandraThrift::IndexClause is not passed in.)
    • :key_start - Set starting row key for search. (Only works if CassandraThrift::IndexClause is not passed in.)
    • :consistency

Example:

@client.create_index('Twitter', 'Statuses', 'x', 'LongType')

@client.insert(:Statuses, 'row1', { 'x' => [0,10].pack("NN")  })

(2..10).to_a.each do |i|
  @twitter.insert(:Statuses, 'row' + i.to_s, { 'x' => [0,20].pack("NN"), 'non_indexed' => [i].pack('N*') })
end

@client.insert(:Statuses, 'row11', { 'x' => [0,30].pack("NN")  })

expressions = [{:column_name => 'x', :value => [0,20].pack("NN"), :comparison => "=="}]

# verify multiples will be returned
@client.get_indexed_slices(:Statuses, expressions).length       # returns 9

# verify that GT and LT queries perform properly
expressions   =  [
                  { :column_name => 'x',
                    :value => [0,20].pack("NN"),
                    :comparison => "=="},
                  { :column_name => 'non_indexed',
                    :value => [5].pack("N*"),
                    :comparison => ">"}
                ]

@client.get_indexed_slices(:Statuses, expressions).length       # returns 5

batch

Takes a block where all the mutations (inserts and deletions) inside it are queued, and at the end of the block are passed to cassandra in a single batch.

If you don't want to send all the mutations inside the block in a big single batch, you can use the :queue_size option to send smaller batches. If the queue is not empty at the end of the block, the remaining mutations are sent.

  • options
    • :consistency - Override the consistency level from individual mutations.
    • :queue_size - Maximum number of mutations to send at once.

Example:

@client.batch do
  @client.insert(:Statuses, 'k1', {'body' => 'v1'})
  @client.insert(:Statuses, 'k2', {'body' => 'v2'})
  @client.remove(:Statuses, 'k3')
end

Reporting Problems

The Github issue tracker is here. If you have problems with this library or Cassandra itself, please use the cassandra-user mailing list.

cassandra's People

Contributors

aanand avatar b avatar bierbaum avatar blanquer avatar brandony avatar grantr avatar gregory-m avatar grobie avatar guilleiguaran avatar jamesgolick avatar jarib avatar jmhodges avatar matthuhiggins avatar mcmire avatar mheffner avatar mikong avatar mperham avatar nearbuyjason avatar nzkoz avatar ryanking avatar rykov avatar sergyenko avatar shyamalprasad avatar simbul avatar subelsky avatar therealadam avatar tommay avatar tritonrc avatar trydionel avatar villosil avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cassandra's Issues

thrift broken on 1.9

[6:36pm] brett_: fwiw, ruby1.9 + snow_leopard + cassandra gem == https://gist.github.com/3b21e5aca7f9bf3d2f83
[6:36pm] brett_: will investigate shortly
[6:37pm] evn: damn you thrift
[6:37pm] evn: look for a thrift ruby 1.9 compat thing
[6:37pm] brett_: -Werror is almost always the wrong answer, imho
[6:46pm] brett_: fwiw:    rb_raise(rb_eStandardError, str);  should be    rb_raise(rb_eStandardError, "%s", str);
[6:46pm] brett_: fin.
[6:46pm] evn: is that it?
[6:46pm] brett_: yeah, that fixes thrift
[6:47pm] brett_: gcc got pedantic at some point.
[6:47pm] evn: ok maybe i can find a magic checkout
[6:47pm] evn: that has that
[6:47pm] evn: otherwise i can just hack the gem

Error applying a patch during cassandra_helper cassandra (OS X 10.6, Ruby 1.8.7)

patching file test/system/test_server.py
[trunk]: created 52c5e33: "Applied patch: "http://issues.apache.org/jira/secure/attachment/12417533/388.patch""
9 files changed, 129 insertions(+), 1238 deletions(-)
delete mode 100644 interface/gen-java/org/apache/cassandra/service/BatchMutationSuper.java
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 1054 100 1054 0 0 18644 0 --:--:-- --:--:-- --:--:-- 0
patch unexpectedly ends in middle of line
patch: **** Only garbage was found in the patch input.
rake aborted!
http://issues.apache.org/jira/secure/attachment/12417682/CASSANDRA-336-code.diff failed
/Library/Ruby/Gems/1.8/gems/cassandra-0.5.5/Rakefile:94

host:port required for server config

The README needs a slight update:

Instead of

client = Cassandra.new('Twitter', '127.0.0.1')

it should be

client = Cassandra.new('Twitter', '127.0.0.1:9160')

otherwise you'll get a "ArgumentError: Servers must be in the form "host:port"" when you try to insert a row.

Thanks for the library!

Column Value Handling is inconsistent

Hey there,

found a "bug" in the code to handle the conversion from ruby hashes to cassandra mutations. Basically the column value for super columns can be anything (since .to_s will be called) while normal columns will fail.

Add this to "test/cassandra_test.rb" to see the error:

def test_super_allows_for_non_string_values_while_normal_does_not
  columns = {'user_timelines' => {@uuids[4] => 4, @uuids[5] => 5}}

  # right now: this works
  @twitter.insert(:StatusRelationships, key, columns)
  # this fails
  @twitter.insert(:Statuses, key, { 'body' => 1 })
end

Error: "NoMethodError: undefined method `length' for 1:Fixnum"

Looking at the code at lib/cassandra/columns.rb
standard_insert_mutation does :value => value
while
super_insert_mutation does :value => sub_column_value.to_s

Just think thats a little inconsitent and confused the hell out of me because I could add Time instances to supercolumns but not normal ones. I know now that values HAVE to be byte[] aka Strings in ruby but thought I'd mention this since I think the behavior should be the same for both cases.

keyslice to orderedhash

Hi,

Im trying to get the contents of an entire ColumnFamily. For that I am using get_range but this returns to me an key_slice array. Is there any method to convert this array to an OrderedHash?

reconnect! method resets the @servers parameter

I believe this code in cassandra.rb does not respect the @servers parameter:

def new_client
thrift_client_class.new(CassandraThrift::Cassandra::Client, @servers, @thrift_client_options)
end

It seems to return a client which uses the default localhost value for @servers, which causes this to happen:

irb(main):005:0> cass = Cassandra.new(:OtherInbox,"10.208.130.191:9160")
=> #<Cassandra:77305550, @keyspace=:OtherInbox, @Schema={}, @servers=["10.208.130.191:9160"]>
irb(main):006:0> cass.instance_eval { @servers }
=> ["10.208.130.191:9160"]
irb(main):007:0> cass.get(:MerchantDomains,'example.com')
ThriftClient::NoServersAvailable: No live servers in ["127.0.0.1:9160"] since Wed Apr 07 14:11:45 +0000 2010.
from /usr/local/lib/ruby/gems/1.8/gems/thrift_client-0.4.1/lib/thrift_client/abstract_thrift_client.rb:124:in next_server' from /usr/local/lib/ruby/gems/1.8/gems/thrift_client-0.4.1/lib/thrift_client/abstract_thrift_client.rb:102:inconnect!'
from /usr/local/lib/ruby/gems/1.8/gems/thrift_client-0.4.1/lib/thrift_client/abstract_thrift_client.rb:183:in connect!' from /usr/local/lib/ruby/gems/1.8/gems/thrift_client-0.4.1/lib/thrift_client/abstract_thrift_client.rb:55:inproxy'
from /usr/local/lib/ruby/gems/1.8/gems/thrift_client-0.4.1/lib/thrift_client/abstract_thrift_client.rb:146:in proxy' from /usr/local/lib/ruby/gems/1.8/gems/thrift_client-0.4.1/lib/thrift_client/abstract_thrift_client.rb:49:inhandled_proxy'
from /usr/local/lib/ruby/gems/1.8/gems/thrift_client-0.4.1/lib/thrift_client/abstract_thrift_client.rb:142:in handled_proxy' from /usr/local/lib/ruby/gems/1.8/gems/thrift_client-0.4.1/lib/thrift_client/abstract_thrift_client.rb:23:inget_string_list_property'
from /usr/local/lib/ruby/gems/1.8/gems/cassandra-0.8.1/lib/cassandra/cassandra.rb:286:in check_keyspace' from /usr/local/lib/ruby/gems/1.8/gems/cassandra-0.8.1/lib/cassandra/cassandra.rb:282:inreconnect!'
from /usr/local/lib/ruby/gems/1.8/gems/cassandra-0.8.1/lib/cassandra/cassandra.rb:275:in client' from /usr/local/lib/ruby/gems/1.8/gems/cassandra-0.8.1/lib/cassandra/cassandra.rb:270:inschema'
from /usr/local/lib/ruby/gems/1.8/gems/cassandra-0.8.1/lib/cassandra/columns.rb:31:in column_family_property' from /usr/local/lib/ruby/gems/1.8/gems/cassandra-0.8.1/lib/cassandra/columns.rb:20:incolumn_name_class_for_key'
from /usr/local/lib/ruby/gems/1.8/gems/cassandra-0.8.1/lib/cassandra/columns.rb:12:in column_name_class' from /usr/local/lib/ruby/gems/1.8/gems/cassandra-0.8.1/lib/cassandra/helpers.rb:20:inextract_and_validate_params'
from /usr/local/lib/ruby/gems/1.8/gems/cassandra-0.8.1/lib/cassandra/cassandra.rb:197:in multi_get' from /usr/local/lib/ruby/gems/1.8/gems/cassandra-0.8.1/lib/cassandra/cassandra.rb:190:inget'
from (irb
irb(main):009:0> cass.instance_eval { @servers }
=> ["127.0.0.1:9160"]

I am working on a patch but dont' fully understand how the thrift client works; thought I'd post here first in case this is already known to you.

Cassandra forces json gem

We'd like to use yajl-ruby's JSON gem compatibility API instead of the json gem. Would it be possible to remove the explicit dependency and just check for defined?(JSON) upon startup? Or remove the need for JSON at all (I noticed it's only used in one place)?

Hardcoded path in gemspec

When using the git version of cassandra with bundler I get this error on bundle install:

Installing cassandra (0.7.6) from git://github.com/fauna/cassandra.git (at master) /usr/local/lib/site_ruby/1.8/rubygems/security.rb:759:in `read': No such file or directory - /Users/ryan/.gemkeys/gem-private_key.pem (Errno::ENOENT)

make schema public

I'm sorry.
I can speak English only a little.
However, I question.
Are there any reasons though schema method is protected?
Actually, the application that obtains the ColumnFamily list is made, and I want to use schema method.
Does not the problem occur even if this is used?

Thrift is failing install - struct.c:286: error: implicit declaration of function ‘strlcpy’

Cassandra fails to install because Thrift appears broken when trying to build

I am running on Ubuntu 9.04 and not sure what I need to do to fix this.

Here is the output from the install of the Thrift gem:
/usr/local/ruby/lib/ruby/gems/1.9.1/gems/thrift-0.0.810255.1# ruby setup.rb
---> lib
---> lib/thrift
---> lib/thrift/server
<--- lib/thrift/server
---> lib/thrift/transport
<--- lib/thrift/transport
---> lib/thrift/serializer
<--- lib/thrift/serializer
---> lib/thrift/core_ext
<--- lib/thrift/core_ext
---> lib/thrift/protocol
<--- lib/thrift/protocol
<--- lib/thrift
<--- lib
---> ext
/usr/local/ruby-1.9.1-p243/bin/ruby /usr/local/ruby-1.9.1-p243/lib/ruby/gems/1.9.1/gems/thrift-0.0.810255.1/ext/extconf.rb
checking for strlcpy() in string.h... yes
creating Makefile
<--- ext
---> lib
---> lib/thrift
---> lib/thrift/server
<--- lib/thrift/server
---> lib/thrift/transport
<--- lib/thrift/transport
---> lib/thrift/serializer
<--- lib/thrift/serializer
---> lib/thrift/core_ext
<--- lib/thrift/core_ext
---> lib/thrift/protocol
<--- lib/thrift/protocol
<--- lib/thrift
<--- lib
---> ext
make
gcc -I. -I/usr/local/ruby-1.9.1-p243/include/ruby-1.9.1/i686-linux -I/usr/local/ruby-1.9.1-p243/include/ruby-1.9.1/ruby/backward -I/usr/local/ruby-1.9.1-p243/include/ruby-1.9.1 -I/usr/local/ruby-1.9.1-p243/lib/ruby/gems/1.9.1/gems/thrift-0.0.810255.1/ext -DHAVE_STRLCPY -D_FILE_OFFSET_BITS=64 -fPIC -g -O2 -Wall -Werror -o struct.o -c struct.c
cc1: warnings being treated as errors
struct.c: In function ‘get_field_value’:
struct.c:286: error: implicit declaration of function ‘strlcpy’
make: *** [struct.o] Error 1
setup.rb:655:in command': system("make") failed (RuntimeError) from setup.rb:664:inmake'
from setup.rb:1258:in setup_dir_ext' from setup.rb:1532:inblock in traverse'
from setup.rb:1549:in dive_into' from setup.rb:1530:intraverse'
from setup.rb:1524:in block in exec_task_traverse' from setup.rb:1519:ineach'
from setup.rb:1519:in exec_task_traverse' from setup.rb:1246:inexec_setup'
from setup.rb:996:in exec_setup' from setup.rb:813:ininvoke'
from setup.rb:773:in invoke' from setup.rb:1578:in

'

0.7 remove bug

>> client.remove :Foo, "bar", "baz"
NoMethodError: undefined method `validate' for 1281395191953732:Fixnum
    from /usr/local/lib/ruby/gems/1.8/gems/thrift-0.2.0.4/lib/thrift/client.rb:35:in `write'
    from /usr/local/lib/ruby/gems/1.8/gems/thrift-0.2.0.4/lib/thrift/client.rb:35:in `send_message'
    from /workspace/vendor/plugins/cassandra/lib/../vendor/0.7/gen-rb/cassandra.rb:179:in `send_remove'
    from /workspace/vendor/plugins/cassandra/lib/../vendor/0.7/gen-rb/cassandra.rb:174:in `remove'
    from /workspace/vendor/plugins/thrift_client/lib/thrift_client/abstract_thrift_client.rb:67:in `send'
    from /workspace/vendor/plugins/thrift_client/lib/thrift_client/abstract_thrift_client.rb:67:in `send_rpc'
    from /workspace/vendor/plugins/thrift_client/lib/thrift_client/abstract_thrift_client.rb:164:in `send_rpc'
    from /workspace/vendor/plugins/thrift_client/lib/thrift_client/abstract_thrift_client.rb:63:in `proxy'
    from /workspace/vendor/plugins/thrift_client/lib/thrift_client/abstract_thrift_client.rb:154:in `proxy'
    from /workspace/vendor/plugins/thrift_client/lib/thrift_client/abstract_thrift_client.rb:53:in `handled_proxy'
    from /workspace/vendor/plugins/thrift_client/lib/thrift_client/abstract_thrift_client.rb:150:in `handled_proxy'
    from /workspace/vendor/plugins/thrift_client/lib/thrift_client/abstract_thrift_client.rb:23:in `remove'
    from /workspace/vendor/plugins/cassandra/lib/cassandra/0.7/protocol.rb:12:in `_remove'
    from /workspace/vendor/plugins/cassandra/lib/cassandra/cassandra.rb:146:in `remove'
    from (irb):1

Cassandra performance

Cassandra is considered to be very fast. I have made little benchmark using ruby 1.9.2 (not release, but almost)
I have NewKeyspace keyspace and this is the value that Standard2 column has:

[default@NewKeyspace] get Standard2['jsmith']['first']  
=> (column=first, value=John, timestamp=1282036446068000)

I was actually able to get this value using cassandra gem:

ruby-1.9.2-head > client.get(:Standard2, 'jsmith') 
 => {"first"=>"John"} 

And here is the performance:

ruby-1.9.2-head > Benchmark.measure { 900.times {client.get(:Standard2, 'jsmith') }}
 =>   0.750000   0.050000   0.800000 (  1.183909)

Is it ok? Am I doing something wrong? 900 requests per second isn't too much (considering that this value should be cached and it's just key-value storage)
I am running Ubuntu 10.04, My laptop isn't super powerfull (2x 1.8 Centrino Duo with 2.5 Gb or RAM), but I think that it should work faster.

Upgrading gem overwrites test data folder - document?

I'd done something completely stupid, and left my data in the test folder. When I upgraded the gem, the test folder got overwritten, and I lost my data.

Not sure if it's worth dealing with - but some sort of warning or note in the instructions about this probably wouldn't hurt. "Don't use the test folder for your data, as it will get overwritten when you update the gem."

Using gem on a client with non-localhost IP fails

In moving from gem 0.6 to 0.7.2 my clients were no longer talking to the correct server ip.

It's possible that my problem is that I should have added something to the config files during the upgrade that I missed. I did a diff on them between versions and didn't see anything different though.

I tracked the problem to this method in cassandra.rb:

def all_nodes
   ips = ::JSON.parse(@client.get_string_property('token map')).values
   port = @servers.first.split(':').last
   ips.map{|ip| "#{ip}:#{port}" }
end

As far as I know I don't have a token map defined, nor do I know how to define it. The client! method uses this all_nodes and overwrites the server attribute with the result of it.

cassandra 0.4.0 BatchMutation has been dropped

Judging from the changelog on the latest release (which was a few hours ago), BatchMutation was merged into batch_insert.

I've poked a few pieces of cassandra/cassandra.rb and found that replacing CassandraThrift.BatchMutation.new roughly with @client.batch_insert seems to work.

I may pull a patch together, but thought it was worth reporting in the meantime.

Time Out Exceptions

Hi,

I'm not sure if this is a problem with the Cassandra gem, the Thrift gem, Thrift, or Cassanda, but I'll start at the top and work down ;-)

My script is as follows:

require 'rubygems'
require 'cassandra'
require 'simple_uuid'
include SimpleUUID

client = Cassandra.new 'MyKeyspace', '127.0.0.1:9160'
client.clear_keyspace!

def random_string length = 20
  chars = 'abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789'
  string = ''
  length.times do
    string << chars[rand(chars.size)]
  end
  string
end

count = 0
last_uuid = nil
while true
  count += 1
  print '.' if count % 1000 == 0
  client.get : MyData, last_uuid unless last_uuid.nil?
  current_uuid = UUID.new.to_guid
  client.insert : MyData, current_uuid, {
    'data_0' => random_string,
    # snip
    'data_9' => random_string
  }
  last_uuid = current_uuid
end

After about a minute:
/lib/ruby/gems/1.9.1/gems/thrift-0.2.0.2/lib/thrift/transport/socket.rb:108:in `read': Socket: Timed out reading 4096 bytes from 127.0.0.1:9160 (Thrift::TransportException)

The exception is not raised when I omit the data columns.

I am using Cassandra 0.6.1 and the Cassandra gem 0.8.2.

Any help much appreciated.

Single cassandra node on dedicated machine can't be found

When cassanda gem tryies to find other cassandras though all_nodes it'll return 127.0.0.1 and won't work. That happes because single cassandra will think it's primary seed as 127.0.0.1. Putting in Seed hostname or ip address of interface does't work.

The problem arives only using single node from machine other than where cassandra installed. When two or more cassandras gossip they tell each other ip addresses of external interface of each other, so all_nodes will return valid result.

Cassandra question

Please, can you tell how to get first 100 values from some column family? Everything I tried didn't work (column family is standard, not super). Thanks.

Bug in lib/cassandra.rb - ruby 1.9.2-head (1 month old)

Hi There,

I've found a little problem in cassandra.rb:
unless Cassandra.methods.include?("VERSION")

you should pass a symbol to include?, like this:
unless Cassandra.methods.include?(:VERSION)
or
unless Cassandra.respond_to?(VERSION)

otherwise 0.6 is always included for me.

best,

Tobi

Regularly get "Unexpected state errors"

When writing to Cassandra, we regularly see "Unexpected State." The confusing thing is that this message is not consistent, after a number of failed inserts the writer will revert to normal behaviour and insert normally. No clear reason for the message is given.

Not sure if this is the result of cassandra or thrift.

A stack trace is as follows:


[ERROR] 2011-01-17 17:07:29 (Alex::Writer) :: Unexpected state
[ERROR] 2011-01-17 17:07:29 (Alex::Writer) :: /usr/local/lib/ruby/gems/1.9.1/gems/thrift_client-0.6.0/lib/thrift_client/event_machine.rb:86:in blocking_read' /usr/local/lib/ruby/gems/1.9.1/gems/thrift_client-0.6.0/lib/thrift_client/event_machine.rb:39:inread'
/usr/local/lib/ruby/gems/1.9.1/gems/thrift-0.5.0/lib/thrift/transport/base_transport.rb:52:in read_all' /usr/local/lib/ruby/gems/1.9.1/gems/thrift-0.5.0/lib/thrift/transport/framed_transport.rb:78:inread_frame'
/usr/local/lib/ruby/gems/1.9.1/gems/thrift-0.5.0/lib/thrift/transport/framed_transport.rb:49:in read' /usr/local/lib/ruby/gems/1.9.1/gems/thrift-0.5.0/lib/thrift/transport/base_transport.rb:52:inread_all'
/usr/local/lib/ruby/gems/1.9.1/gems/thrift-0.5.0/lib/thrift/protocol/binary_protocol.rb:186:in read_i32' /usr/local/lib/ruby/gems/1.9.1/gems/thrift-0.5.0/lib/thrift/protocol/binary_protocol.rb:111:inread_message_begin'
/usr/local/lib/ruby/gems/1.9.1/gems/thrift-0.5.0/lib/thrift/client.rb:45:in receive_message' /usr/local/lib/ruby/gems/1.9.1/gems/cassandra-0.9.0/vendor/0.7/gen-rb/cassandra.rb:358:inrecv_describe_keyspace'
/usr/local/lib/ruby/gems/1.9.1/gems/cassandra-0.9.0/vendor/0.7/gen-rb/cassandra.rb:350:in describe_keyspace' /usr/local/lib/ruby/gems/1.9.1/gems/thrift_client-0.6.0/lib/thrift_client/abstract_thrift_client.rb:115:inhandled_proxy'
/usr/local/lib/ruby/gems/1.9.1/gems/thrift_client-0.6.0/lib/thrift_client/abstract_thrift_client.rb:57:in describe_keyspace' /usr/local/lib/ruby/gems/1.9.1/gems/cassandra-0.9.0/lib/cassandra/0.7/cassandra.rb:31:inschema'
/usr/local/lib/ruby/gems/1.9.1/gems/cassandra-0.9.0/lib/cassandra/0.7/columns.rb:19:in column_family_property' /usr/local/lib/ruby/gems/1.9.1/gems/cassandra-0.9.0/lib/cassandra/columns.rb:20:incolumn_name_class_for_key'
/usr/local/lib/ruby/gems/1.9.1/gems/cassandra-0.9.0/lib/cassandra/0.7/columns.rb:11:in column_name_class' /usr/local/lib/ruby/gems/1.9.1/gems/cassandra-0.9.0/lib/cassandra/helpers.rb:20:inextract_and_validate_params'
/usr/local/lib/ruby/gems/1.9.1/gems/cassandra-0.9.0/lib/cassandra/cassandra.rb:113:in `insert'

gem version

Hi!

Using gem install, the installed version is 0.8.2, but the last version is 0.10.0.
Why is it so?

Thanks for the answer

Regards,

Sebastien

Broken with thrift 0.2.5 on ruby 1.9.1

Thrift does not compile without alterations to struct.c relating to strlcpy. With this file fixed, Thrift 0.2.5 (from latest thrift git) does not appear to work with cassandra:

james@hometree:~/cassandra$ irb
irb(main):001:0> require 'thrift'
=> true
irb(main):002:0> require 'cassandra'
ArgumentError: wrong number of arguments (4 for 2)
        from /usr/local/lib/ruby/gems/1.9.1/gems/cassandra-0.8.1/vendor/gen-rb/cassandra_types.rb:32:in `'
        from /usr/local/lib/ruby/gems/1.9.1/gems/cassandra-0.8.1/vendor/gen-rb/cassandra_types.rb:26:in `'
        from /usr/local/lib/ruby/gems/1.9.1/gems/cassandra-0.8.1/vendor/gen-rb/cassandra_types.rb:8:in `'
        from /usr/local/lib/ruby/gems/1.9.1/gems/cassandra-0.8.1/vendor/gen-rb/cassandra.rb:8:in `require'
        from /usr/local/lib/ruby/gems/1.9.1/gems/cassandra-0.8.1/vendor/gen-rb/cassandra.rb:8:in `'
        from /usr/local/lib/ruby/gems/1.9.1/gems/cassandra-0.8.1/lib/cassandra.rb:9:in `require'
        from /usr/local/lib/ruby/gems/1.9.1/gems/cassandra-0.8.1/lib/cassandra.rb:9:in `'
        from (irb):2:in `require'
        from (irb):2
        from /usr/local/bin/irb:12:in `'

james@hometree:~/cassandra$ ruby -v
ruby 1.9.1p378 (2010-01-10 revision 26273) [i686-linux]

No tests for 0.7

Hi,

there are no tests available for cassandra/0.7.
I'd offer to contribute tests for the whole 0.7 branch stuff but I prefer RSpec. Is this okay?

Regards

Can't get or insert value using Cassandra 0.7 beta

Here is the ruby code I used:

require 'rubygems'
require 'cassandra/0.7'
include SimpleUUID
new_keyspace = Cassandra.new('NewKeyspace')
user = {'screen_name' => 'buttonscat'}
new_keyspace.insert('Standard2', 'jdoe', user)

As a result I get following error: http://pastie.org/1097589. (I really have NewKeyspace and Standard2 column family. I have created them manually and I could work with them through cassandra-cli). I created gem from the github master branch repository and have installed it.

JRuby support

Evan pushed a commit to thrift-rb this weekend that enables support for JRuby. With that in place, I am able to package and install cassandra gem under JRuby if I swap out 'json' for 'json-jruby'. I tried a couple of quick changes ("if defined?(JRUBY_VERSION) 'json-jruby' else 'jruby'") to the Echoe spec to enable automatic support for JRuby. However, nothing worked to satisfaction (i.e. package and install under both JRuby and MRI). I think the most straight-forward method maybe to create two separate specs for the two versions. Anyone have any other ideas?

0.7 count_columns argument error

It seems regardless of the parameters I supply it always complains about the wrong number of arguments

>> CASSANDRA.count_columns :Foo, "bar"
    ArgumentError: wrong number of arguments (3 for 4)
    from /app/releases/20090716234923/vendor/plugins/thrift_client-0.4.3/lib/thrift_client/abstract_thrift_client.rb:64:in 'get_count'
    from /app/releases/20090716234923/vendor/plugins/thrift_client-0.4.3/lib/thrift_client/abstract_thrift_client.rb:64:in 'send'
    from /app/releases/20090716234923/vendor/plugins/thrift_client-0.4.3/lib/thrift_client/abstract_thrift_client.rb:64:in 'send_rpc'
    from /app/releases/20090716234923/vendor/plugins/thrift_client-0.4.3/lib/thrift_client/abstract_thrift_client.rb:161:in 'send_rpc'
    from /app/releases/20090716234923/vendor/plugins/thrift_client-0.4.3/lib/thrift_client/abstract_thrift_client.rb:60:in 'proxy'
    from /app/releases/20090716234923/vendor/plugins/thrift_client-0.4.3/lib/thrift_client/abstract_thrift_client.rb:151:in 'proxy'
    from /app/releases/20090716234923/vendor/plugins/thrift_client-0.4.3/lib/thrift_client/abstract_thrift_client.rb:53:in 'handled_proxy'
    from /app/releases/20090716234923/vendor/plugins/thrift_client-0.4.3/lib/thrift_client/abstract_thrift_client.rb:147:in 'handled_proxy'
    from /app/releases/20090716234923/vendor/plugins/thrift_client-0.4.3/lib/thrift_client/abstract_thrift_client.rb:23:in 'get_count'
    from /app/releases/20090716234923/vendor/plugins/cassandra/lib/cassandra/0.7/protocol.rb:16:in '_count_columns'
    from /app/releases/20090716234923/vendor/plugins/cassandra/lib/cassandra/cassandra.rb:156:in 'count_columns'
    from (irb):84

>> CASSANDRA.count_columns :Foo, "bar", "baz"
    ArgumentError: wrong number of arguments (3 for 4)
    from /app/releases/20090716234923/vendor/plugins/thrift_client-0.4.3/lib/thrift_client/abstract_thrift_client.rb:64:in 'get_count'
    from /app/releases/20090716234923/vendor/plugins/thrift_client-0.4.3/lib/thrift_client/abstract_thrift_client.rb:64:in 'send'
    from /app/releases/20090716234923/vendor/plugins/thrift_client-0.4.3/lib/thrift_client/abstract_thrift_client.rb:64:in 'send_rpc'
    from /app/releases/20090716234923/vendor/plugins/thrift_client-0.4.3/lib/thrift_client/abstract_thrift_client.rb:161:in 'send_rpc'
    from /app/releases/20090716234923/vendor/plugins/thrift_client-0.4.3/lib/thrift_client/abstract_thrift_client.rb:60:in 'proxy'
    from /app/releases/20090716234923/vendor/plugins/thrift_client-0.4.3/lib/thrift_client/abstract_thrift_client.rb:151:in 'proxy'
    from /app/releases/20090716234923/vendor/plugins/thrift_client-0.4.3/lib/thrift_client/abstract_thrift_client.rb:53:in 'handled_proxy'
    from /app/releases/20090716234923/vendor/plugins/thrift_client-0.4.3/lib/thrift_client/abstract_thrift_client.rb:147:in 'handled_proxy'
    from /app/releases/20090716234923/vendor/plugins/thrift_client-0.4.3/lib/thrift_client/abstract_thrift_client.rb:23:in 'get_count'
    from /app/releases/20090716234923/vendor/plugins/cassandra/lib/cassandra/0.7/protocol.rb:16:in '_count_columns'
    from /app/releases/20090716234923/vendor/plugins/cassandra/lib/cassandra/cassandra.rb:156:in 'count_columns'
    from (irb):84

Required field 'timestamp' was not found in serialized data!

Hi,
from time to time I get and error: "Required field 'timestamp' was not found in serialized data!".
It's happen randomly and I don't have any idea why.

I try to insert data in that way:
client = Cassandra.new('Test', '127.0.0.1:9160')
client.insert(:Cmessages, "ad26857a063b54659f3d7626b152864d698167c5" , {
body: "some utf8 string ĄŚĘŁÓąęśćół",
entry_url: "http://url.com/someurl",
posted_on: Date.today.to_s(:db)}.stringify_keys
)
and sometimes it's works.

schema:




org.apache.cassandra.locator.RackUnawareStrategy
1
org.apache.cassandra.locator.EndPointSnitch

backtrace:
Required field 'timestamp' was not found in serialized data! Struct: Column(name:62 6F 64 79, value:73 6F 6D 65 20 75 74 66 38 20 73 74 72 69 6E 67 20 C4 84 C5 9A C4 98 C5 81 C3 93 C4, timestamp:0)
.../thrift-0.2.0.4/lib/thrift/client.rb:65:in handle_exception' .../thrift-0.2.0.4/lib/thrift/client.rb:46:inreceive_message'
.../cassandra-0.8.2/vendor/gen-rb/cassandra.rb:219:in recv_batch_mutate' .../cassandra-0.8.2/vendor/gen-rb/cassandra.rb:211:inbatch_mutate'
.../thrift_client-0.4.3/lib/thrift_client/abstract_thrift_client.rb:64:in send_rpc' .../thrift_client-0.4.3/lib/thrift_client/abstract_thrift_client.rb:161:insend_rpc'
.../thrift_client-0.4.3/lib/thrift_client/abstract_thrift_client.rb:60:in proxy' .../thrift_client-0.4.3/lib/thrift_client/abstract_thrift_client.rb:151:inproxy'
.../thrift_client-0.4.3/lib/thrift_client/abstract_thrift_client.rb:53:in handled_proxy' .../thrift_client-0.4.3/lib/thrift_client/abstract_thrift_client.rb:147:inhandled_proxy'
.../thrift_client-0.4.3/lib/thrift_client/abstract_thrift_client.rb:23:in batch_mutate' .../cassandra-0.8.2/lib/cassandra/protocol.rb:8:in_mutate'
.../cassandra-0.8.2/lib/cassandra/cassandra.rb:118:in `insert'

Could You help me?

Add 0.7 optional ttl

0.7 adds the ability to optional include a TTL option when inserting columns. This should be pretty trivial to include

Helper module is confused by key ranges

I have a SuperColumnFamily listed like this:

  <ColumnFamily Name="AccessLog"
                ColumnType="Super"
                CompareWith="TimeUUIDType"
                CompareSubcolumnsWith="UTF8Type"
                KeysCached="0"
                />

Using get_range( :AccessLog, { :start = "20100827092532" }) gives the following error:

/Library/Ruby/Gems/1.8/gems/simple_uuid-0.1.1/lib/simple_uuid.rb:35:in `initialize': Expected "20100827092532" to cast to a SimpleUUID::UUID (invalid bytecount) (TypeError)

Looks to me like extract_and_validate_params is assuming that :start and :finish options always refer to the supercolumn structure, not the key structure.

LoadError: no such file to load -- cassandra/0.6/columns

Hi,

the current master branch is broken:

require "cassandra"

causes the following error:

LoadError: no such file to load -- cassandra/0.6/columns
from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in gem_original_require' from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:inrequire'
from /Library/Ruby/Gems/1.8/gems/cassandra-0.9.0/lib/cassandra/../cassandra.rb:27
from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in gem_original_require' from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:inrequire'
from /Library/Ruby/Gems/1.8/gems/cassandra-0.9.0/lib/cassandra/0.6.rb:7
from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in gem_original_require' from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:inrequire'
from /Library/Ruby/Gems/1.8/gems/cassandra-0.9.0/lib/cassandra.rb:12
from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:36:in gem_original_require' from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:36:inrequire'
from (irb):1

The problem is that the Manifest file is not up-to-date. I've updated the Manifest file in http://github.com/flippingbits/cassandra/commit/91b157130821a36c989b12aab4cbb8f57d8b2c05.

Should I send a pull request?

Regards

Symbols are not supported as column names

Currently only strings are supported as column names.

The following code

client.insert(:Users, "5", { :screen_name => "buttonscat"})

will raise this error

can't convert Symbol into String
/Library/Ruby/Gems/1.8/gems/cassandra-0.9.0/lib/cassandra/0.7/columns.rb:10:in initialize' /Library/Ruby/Gems/1.8/gems/cassandra-0.9.0/lib/cassandra/0.7/columns.rb:10:innew'
/Library/Ruby/Gems/1.8/gems/cassandra-0.9.0/lib/cassandra/0.7/columns.rb:10:in _standard_insert_mutation' /Library/Ruby/Gems/1.8/gems/cassandra-0.9.0/lib/cassandra/cassandra.rb:123:ininsert'
/Library/Ruby/Gems/1.8/gems/uuid-2.2.0/lib/uuid.rb:140:in collect' /Library/Ruby/Gems/1.8/gems/cassandra-0.9.0/lib/cassandra/cassandra.rb:123:ineach'
/Library/Ruby/Gems/1.8/gems/cassandra-0.9.0/lib/cassandra/cassandra.rb:123:in collect' /Library/Ruby/Gems/1.8/gems/cassandra-0.9.0/lib/cassandra/cassandra.rb:123:ininsert'

I've already fixed this in my local version. What do you think? Should symbols also be supported?
I'd like to send a pull request.

Kind regards

add_column_family not documented

Hello,

The function add_column_family is not documented.
Could you tell how to use it?

Thanks a lot in advance

Sebastien Druon

Provide timestamp column access

I'd like to be able to access the timestamp value as it is somewhat equivalent to Rails' updated_at field.

When I use Cassandra gem, I get this:

>>     c = Cassandra.new('Onespot', 'removed:9160')
>>     c.get(:ImageInfo, '0c8f0d9a9a64bb050d75e803d2d2cf7739c34fff')
=> {"02912452fc37dde56faf7474994b05f40594255c"=>"1", "selected"=>"02912452fc37dde56faf7474994b05f40594255c"}

But Cassandra's CLI gives me access:

cassandra> get Onespot.ImageInfo['0c8f0d9a9a64bb050d75e803d2d2cf7739c34fff']
=> (column=selected, value=02912452fc37dde56faf7474994b05f40594255c, timestamp=1267583251726377)
=> (column=02912452fc37dde56faf7474994b05f40594255c, value=1, timestamp=1267583251726377)
Returned 2 results.

I'd like to see an API that surfaces this info if possible.

Cannot connect to a single node from localhost

Hi,

with this code :
require 'rubygems'
require 'cassandra'
cassandra = Cassandra.new('Twitter', '127.0.0.1:9160')
cassandra.clear_keyspace!()

I got this message :

cassandra = Cassandra.new('Proxi', '127.0.0.1:9160')
ThriftClient::NoServersAvailable: No live servers in ["127.0.0.1:9160"] since Sat May 22 16:47:04 +0200 2010.

It works if I connect remotely to the server with the same script....

Telnet en 127.0.0.1:9160 works

Any idea ?

When I use the conn.get_columns(:CF, "key"), It throws the Exception

the keySpace is Examine
the CF is
I have doing:
conn.insert(:Ranks, "tmprank", {"1" => ... , "2"=>... "3" => ....})
conn.get_columns(:Ranks, "tmprank")
It throw

CassandraThrift::InvalidRequestException: CassandraThrift::InvalidRequestException
from /opt/ruby/lib/ruby/gems/1.8/gems/cassandra-0.8.1/lib/../vendor/gen-rb/cassandra.rb:62:in recv_get_slice' from /opt/ruby/lib/ruby/gems/1.8/gems/cassandra-0.8.1/lib/../vendor/gen-rb/cassandra.rb:52:inget_slice'
from /opt/ruby/lib/ruby/gems/1.8/gems/thrift_client-0.4.1/lib/thrift_client/abstract_thrift_client.rb:60:in send' from /opt/ruby/lib/ruby/gems/1.8/gems/thrift_client-0.4.1/lib/thrift_client/abstract_thrift_client.rb:60:insend_rpc'
from /opt/ruby/lib/ruby/gems/1.8/gems/thrift_client-0.4.1/lib/thrift_client/abstract_thrift_client.rb:156:in send_rpc' from /opt/ruby/lib/ruby/gems/1.8/gems/thrift_client-0.4.1/lib/thrift_client/abstract_thrift_client.rb:56:inproxy'
from /opt/ruby/lib/ruby/gems/1.8/gems/thrift_client-0.4.1/lib/thrift_client/abstract_thrift_client.rb:146:in proxy' from /opt/ruby/lib/ruby/gems/1.8/gems/thrift_client-0.4.1/lib/thrift_client/abstract_thrift_client.rb:49:inhandled_proxy'
from /opt/ruby/lib/ruby/gems/1.8/gems/thrift_client-0.4.1/lib/thrift_client/abstract_thrift_client.rb:142:in handled_proxy' from /opt/ruby/lib/ruby/gems/1.8/gems/thrift_client-0.4.1/lib/thrift_client/abstract_thrift_client.rb:23:inget_slice'
from /opt/ruby/lib/ruby/gems/1.8/gems/cassandra-0.8.1/lib/cassandra/protocol.rb:30:in _get_columns' from /opt/ruby/lib/ruby/gems/1.8/gems/cassandra-0.8.1/lib/cassandra/cassandra.rb:175:inget_columns'
from (irb):16

my env is
cassandra server 0.6 rc1
ruby gems
cassandra 0.8.1
thrift 0.2.0
thrift_client 0.4.1
And How can I get_range to get keys with LongType?
When I set it to LongType
I get_range will be []
But touch the cassandra, I feel good.
Thx to this lib.

Provide a close hook

Thrift_client has a public disconnect! method but Cassandra does not provide a close or disconnect method to wrap it. You can do this:

c = Cassandra.new(...)
c.client.disconnect!

But that's full of dangers (doesn't set @client to nil, creates the connection first if it doesn't exist, etc)

Can't insert nil values

Have a column family with super columns. Trying to create columns with tweet ids as the key, and nil as the value. I get an error on .insert.

"Required field value is unset!"

Exception is raised from the CassandraThrift Column class's validate method
at Line 42 in vendor/gen-rb/cassandra_types.rb

Cassandra 0.7 API does not work with thrift 0.2

I pull out fauna/cassandra gem 0.10.0 from github.

I then tried to get a value from cassandra as such.

irb(main):002:0> require 'cassandra/0.7'
=> true
irb(main):003:0> client = Cassandra.new('Keyspace1', '127.0.0.1:9160')
=> #<Cassandra:70286805872140, @keyspace="Keyspace1", @Schema={}, @servers=["127.0.0.1:9160"]>
irb(main):004:0> client.insert(:Standard1, "5", {'screen_name' => "buttonscat"})
=> nil
irb(main):006:0> client.get(:Standard1, "5", 'screen_name')
NoMethodError: undefined method multiget' for #<ThriftClient:0x7fd9d82e5270> from /home/jpartogi/.rvm/gems/ruby-1.8.7-p302/gems/cassandra-0.10.0/lib/cassandra/0.7/protocol.rb:53:in_multiget'
from /home/jpartogi/.rvm/gems/ruby-1.8.7-p302/gems/cassandra-0.10.0/lib/cassandra/cassandra.rb:198:in multi_get' from /home/jpartogi/.rvm/gems/ruby-1.8.7-p302/gems/cassandra-0.10.0/lib/cassandra/cassandra.rb:189:inget'
from (irb):6
from :0
irb(main):007:0>

It turns out that the gem is still relying on thrift < 0.2.5 as can be seen on cassandra.rb.

Cassandra#exists? throws error

I'm just trying to verify if Cassandra has a particular key in the keyspace.

>> require 'cassandra'
>> c = Cassandra.new 'Onespot', 'localhost:9160'
>> c.exists?(:UrlInfo, 'foo')

Thrift::ProtocolException: Required field start is unset!
from /opt/ruby-enterprise-1.8.7-2009.10/lib/ruby/gems/1.8/gems/cassandra-0.8.2/lib/../vendor/gen-rb/cassandra_types.rb:304:in `validate'
from /opt/ruby-enterprise-1.8.7-2009.10/lib/ruby/gems/1.8/gems/thrift-0.2.0.2/lib/thrift/client.rb:35:in `write'
from /opt/ruby-enterprise-1.8.7-2009.10/lib/ruby/gems/1.8/gems/thrift-0.2.0.2/lib/thrift/client.rb:35:in `send_message'
from /opt/ruby-enterprise-1.8.7-2009.10/lib/ruby/gems/1.8/gems/cassandra-0.8.2/lib/../vendor/gen-rb/cassandra.rb:92:in `send_multiget_slice'
from /opt/ruby-enterprise-1.8.7-2009.10/lib/ruby/gems/1.8/gems/cassandra-0.8.2/lib/../vendor/gen-rb/cassandra.rb:87:in `multiget_slice'
from /opt/ruby-enterprise-1.8.7-2009.10/lib/ruby/gems/1.8/gems/thrift_client-0.4.3/lib/thrift_client/abstract_thrift_client.rb:64:in `send'
from /opt/ruby-enterprise-1.8.7-2009.10/lib/ruby/gems/1.8/gems/thrift_client-0.4.3/lib/thrift_client/abstract_thrift_client.rb:64:in `send_rpc'
from /opt/ruby-enterprise-1.8.7-2009.10/lib/ruby/gems/1.8/gems/thrift_client-0.4.3/lib/thrift_client/abstract_thrift_client.rb:161:in `send_rpc'
from /opt/ruby-enterprise-1.8.7-2009.10/lib/ruby/gems/1.8/gems/thrift_client-0.4.3/lib/thrift_client/abstract_thrift_client.rb:60:in `proxy'
from /opt/ruby-enterprise-1.8.7-2009.10/lib/ruby/gems/1.8/gems/thrift_client-0.4.3/lib/thrift_client/abstract_thrift_client.rb:151:in `proxy'
from /opt/ruby-enterprise-1.8.7-2009.10/lib/ruby/gems/1.8/gems/thrift_client-0.4.3/lib/thrift_client/abstract_thrift_client.rb:53:in `handled_proxy'
from /opt/ruby-enterprise-1.8.7-2009.10/lib/ruby/gems/1.8/gems/thrift_client-0.4.3/lib/thrift_client/abstract_thrift_client.rb:147:in `handled_proxy'
from /opt/ruby-enterprise-1.8.7-2009.10/lib/ruby/gems/1.8/gems/thrift_client-0.4.3/lib/thrift_client/abstract_thrift_client.rb:23:in `multiget_slice'
from /opt/ruby-enterprise-1.8.7-2009.10/lib/ruby/gems/1.8/gems/cassandra-0.8.2/lib/cassandra/protocol.rb:69:in `_multiget'
from /opt/ruby-enterprise-1.8.7-2009.10/lib/ruby/gems/1.8/gems/cassandra-0.8.2/lib/cassandra/cassandra.rb:216:in `exists?'

Gem now requires Cassandra 0.6-beta

batch_mutate is only in Cassandra 0.6. Since 0.6 hasn't even been generally released yet, I think it would be nice to use the 0.5 API for a while where possible. Here's the API wiki page so you can verify any other API changes: http://wiki.apache.org/cassandra/API

qanat.4.log:Hoptoad: Thrift::ApplicationException: Invalid method name: 'batch_mutate'
qanat.4.log-/home/onespot/.bundle/ruby/1.9.1/gems/thrift-0.0.810255.1/lib/thrift/client.rb:58:in `handle_exception'
qanat.4.log-/home/onespot/.bundle/ruby/1.9.1/gems/thrift-0.0.810255.1/lib/thrift/client.rb:46:in `receive_message'
qanat.4.log:/home/onespot/.bundle/ruby/1.9.1/gems/cassandra-0.7.6/vendor/gen-rb/cassandra.rb:219:in `recv_batch_mutate'
qanat.4.log:/home/onespot/.bundle/ruby/1.9.1/gems/cassandra-0.7.6/vendor/gen-rb/cassandra.rb:211:in `batch_mutate'
qanat.4.log-/home/onespot/.bundle/ruby/1.9.1/gems/thrift_client-0.4.1/lib/thrift_client/abstract_thrift_client.rb:60:in `send_rpc'
qanat.4.log-/home/onespot/.bundle/ruby/1.9.1/gems/thrift_client-0.4.1/lib/thrift_client/abstract_thrift_client.rb:156:in `send_rpc'
qanat.4.log-/home/onespot/.bundle/ruby/1.9.1/gems/thrift_client-0.4.1/lib/thrift_client/abstract_thrift_client.rb:56:in `proxy'
qanat.4.log-/home/onespot/.bundle/ruby/1.9.1/gems/thrift_client-0.4.1/lib/thrift_client/abstract_thrift_client.rb:146:in `proxy'
qanat.4.log-/home/onespot/.bundle/ruby/1.9.1/gems/thrift_client-0.4.1/lib/thrift_client/abstract_thrift_client.rb:49:in `handled_proxy'
qanat.4.log-/home/onespot/.bundle/ruby/1.9.1/gems/thrift_client-0.4.1/lib/thrift_client/abstract_thrift_client.rb:142:in `handled_proxy'
qanat.4.log:/home/onespot/.bundle/ruby/1.9.1/gems/thrift_client-0.4.1/lib/thrift_client/abstract_thrift_client.rb:23:in `batch_mutate'
qanat.4.log-/home/onespot/.bundle/ruby/1.9.1/gems/cassandra-0.7.6/lib/cassandra/protocol.rb:8:in `_mutate'
qanat.4.log-/home/onespot/.bundle/ruby/1.9.1/gems/cassandra-0.7.6/lib/cassandra/cassandra.rb:110:in `insert'

Best practices for load balancing?

Question rather than a bug: what's the recommended approach for using this gem and load-balancing requests against a cassandra cluster for reads/writes?

Going through the source, it looks like all the connection magic is delegated to thrift_client, which in turn simply connects to a single server by default and sends all requests there (unless server_max_requests is set, at which point it reconnects to next server after issuing that number of requests?)

With auto-discovery on, we pass in the array of servers into thrift-client, but I don't see any shuffle logic, etc. Does this mean we're always connecting to the same instance by default?

Thoughts on using a load-balancer instead of built-in logic? Such as HAProxy? Some docs would be helpful on this.

Creating indexes

Don't you know how can I create native secondary indexes for Cassandra 0.7?

Cassandra example don't work

I started Cassandra 0.6 using standard instructions on cassandra web site (haven't used cassandra_helper script to do this). After this I installed cassandra gem and here is what I typed in irb:
require 'cassandra'
client = Cassandra.new('Twitter', '127.0.0.1:9160')
client.insert(:Users, "5", {'screen_name' => "buttonscat"})
I got :
Cassandra::AccessError: Keyspace "Twitter" not found. Available: ["Keyspace1", "system"]
Should I somehow create keyspace before using it? I thought that cassandra can dinamicly create such things.

ruby type support

hi,

doing
client.insert(:Standard2, "bob", {"nom" => "bob", "age" => 41})
get
gems/thrift-0.2.0.4/lib/thrift/protocol/binary_protocol.rb:106:in write_string': undefined methodlength' for 41:Fixnum (NoMethodError)
from /home/Tophe/.rvm/gems/ruby-1.9.2-p0@rails3/gems/thrift-0.2.0.4/lib/thrift/client.rb:35:in write' from /home/Tophe/.rvm/gems/ruby-1.9.2-p0@rails3/gems/thrift-0.2.0.4/lib/thrift/client.rb:35:insend_message'
from /data/work/cassendra/cassandra/vendor/0.6/gen-rb/cassandra.rb:215:in send_batch_mutate' from /data/work/cassendra/cassandra/vendor/0.6/gen-rb/cassandra.rb:210:inbatch_mutate'
from /home/Tophe/.rvm/gems/ruby-1.9.2-p0@rails3/gems/thrift_client-0.5.0/lib/thrift_client/abstract_thrift_client.rb:115:in handled_proxy' from /home/Tophe/.rvm/gems/ruby-1.9.2-p0@rails3/gems/thrift_client-0.5.0/lib/thrift_client/abstract_thrift_client.rb:57:inbatch_mutate'
from /data/work/cassendra/cassandra/lib/cassandra/0.6/protocol.rb:8:in _mutate' from /data/work/cassendra/cassandra/lib/cassandra/cassandra.rb:130:ininsert'
from tx_cassandra.rb:25:in `

'
When I read a long value, it also convert it to string, does that mean cassandra-ruby only support string type ?

Gem not working with cassandra-0.7.0-beta3: CassandraThrift::Cassandra::Client::TransportException

Seems like something broke along the way...

How to reproduce:

"show keyspaces" in cassandra-cli shows the default keyspace:

connect localhost/9160

Connected to: "Test Cluster" on localhost/9160

[default@unknown] show keyspaces

Keyspace: system:

Replication Factor: 1

Column Families:

Trying to get all keyspaces with ruby means doesn't work:

irb(main):001:0> require 'rubygems'

=> true

irb(main):002:0> require 'cassandra'

=> true

irb(main):003:0> client = Cassandra.new 'system', '127.0.0.1:9160'

=> #<Cassandra:-610502768, @keyspace="system", @Schema={}, @servers=["127.0.0.1:9160"]>
irb(main):004:0> client.keyspaces

CassandraThrift::Cassandra::Client::TransportException: CassandraThrift::Cassandra::Client::TransportException
from /var/lib/gems/1.8/gems/thrift-0.2.0.4/lib/thrift/transport/socket.rb:119:in 'read'

from /var/lib/gems/1.8/gems/thrift-0.2.0.4/lib/thrift/transport/buffered_transport.rb:50:in 'read'

from /var/lib/gems/1.8/gems/thrift-0.2.0.4/lib/thrift/transport/base_transport.rb:52:in 'read_all'

from /var/lib/gems/1.8/gems/thrift-0.2.0.4/lib/thrift/protocol/binary_protocol.rb:186:in 'read_i32'

from /var/lib/gems/1.8/gems/thrift-0.2.0.4/lib/thrift/protocol/binary_protocol.rb:111:in
'read_message_begin'

from /var/lib/gems/1.8/gems/thrift-0.2.0.4/lib/thrift/client.rb:45:in 'receive_message'

from /var/lib/gems/1.8/gems/cassandra-0.8.2/lib/../vendor/gen-rb/cassandra.rb:236:in 'recv_get_string_property'

from /var/lib/gems/1.8/gems/cassandra-0.8.2/lib/../vendor/gen-rb/cassandra.rb:228:in 'get_string_property'

from /var/lib/gems/1.8/gems/thrift_client-0.5.0/lib/thrift_client/abstract_thrift_client.rb:115:in 'send'

from /var/lib/gems/1.8/gems/thrift_client-0.5.0/lib/thrift_client/abstract_thrift_client.rb:115:in 'handled_proxy'

from /var/lib/gems/1.8/gems/thrift_client-0.5.0/lib/thrift_client/abstract_thrift_client.rb:57:in 'get_string_property'

from /var/lib/gems/1.8/gems/cassandra-0.8.2/lib/cassandra/cassandra.rb:302:in 'all_nodes'

from /var/lib/gems/1.8/gems/cassandra-0.8.2/lib/cassandra/cassandra.rb:285:in 'reconnect!'

from /var/lib/gems/1.8/gems/cassandra-0.8.2/lib/cassandra/cassandra.rb:280:in 'client'

from /var/lib/gems/1.8/gems/cassandra-0.8.2/lib/cassandra/cassandra.rb:86:in 'keyspaces'

The exact same ruby code from above works with cassandra-0.6.6.


Ruby version:

ruby -v
ruby 1.8.7 (2010-06-23 patchlevel 299) [i686-linux]

OS:

cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=10.10
DISTRIB_CODENAME=maverick
DISTRIB_DESCRIPTION="Ubuntu 10.10"

Gem Version:

gem list cassandra

LOCAL GEMS

cassandra (0.8.2)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.