jasonmk / datastax_rails

A Ruby-on-Rails interface to Datastax Enterprise. Replaces the majority of ActiveRecord functionality.
MIT License
23 stars 9 forks source link

Thrift::ProtocolException: Invalid value of field compression! #18

Closed trushkevich closed 10 years ago

trushkevich commented 10 years ago

Ruby 2.1.1. Rails 4.1.0. This is a continuation of https://github.com/jasonmk/datastax_rails/issues/17.

I commented out this to see what happens next:

/home/antoha/.rvm/gems/ruby-2.1.1/gems/datastax_rails-1.2.3/lib/datastax_rails/attribute_assignment.rb

module DatastaxRails
  module AttributeAssignment
    extend ActiveSupport::Concern
    if Rails.version =~ /^3.*/
      include ActiveModel::MassAssignmentSecurity
    elsif Rails.version =~ /^4.*/
      # include ActiveModel::DeprecatedMassAssignmentSecurity
      include ActiveModel::ForbiddenAttributesProtection
    end

in this case "rake ds:migrate" causes

rake aborted! Thrift::ProtocolException: Invalid value of field compression! /home/antoha/.rvm/gems/ruby-2.1.1/gems/cassandra-cql-1.2.2/vendor/1.2/gen-rb/cassandra.rb:2769:in 'validate' /home/antoha/.rvm/gems/ruby-2.1.1/gems/thrift-0.8.0/lib/thrift/client.rb:35:in 'write' /home/antoha/.rvm/gems/ruby-2.1.1/gems/thrift-0.8.0/lib/thrift/client.rb:35:in 'send_message' /home/antoha/.rvm/gems/ruby-2.1.1/gems/cassandra-cql-1.2.2/vendor/1.2/gen-rb/cassandra.rb:626:in 'send_execute_cql3_query' /home/antoha/.rvm/gems/ruby-2.1.1/gems/cassandra-cql-1.2.2/vendor/1.2/gen-rb/cassandra.rb:621:in 'execute_cql3_query' /home/antoha/.rvm/gems/ruby-2.1.1/gems/thrift_client-0.8.4/lib/thrift_client/abstract_thrift_client.rb:165:in 'block in handled_proxy' /home/antoha/.rvm/gems/ruby-2.1.1/gems/thrift_client-0.8.4/lib/thrift_client/abstract_thrift_client.rb:146:in 'ensure_socket_alignment' /home/antoha/.rvm/gems/ruby-2.1.1/gems/thrift_client-0.8.4/lib/thrift_client/abstract_thrift_client.rb:165:in 'handled_proxy' /home/antoha/.rvm/gems/ruby-2.1.1/gems/thrift_client-0.8.4/lib/thrift_client/abstract_thrift_client.rb:53:in 'execute_cql3_query' /home/antoha/.rvm/gems/ruby-2.1.1/gems/cassandra-cql-1.2.2/lib/cassandra-cql/database.rb:117:in 'execute_cql_query' /home/antoha/.rvm/gems/ruby-2.1.1/gems/datastax_rails-1.2.3/lib/datastax_rails/cql/base.rb:25:in 'execute' /home/antoha/.rvm/gems/ruby-2.1.1/gems/datastax_rails-1.2.3/lib/datastax_rails/schema/cassandra.rb:135:in 'column_family_exists?' /home/antoha/.rvm/gems/ruby-2.1.1/gems/datastax_rails-1.2.3/lib/datastax_rails/schema/migrator.rb:71:in 'check_schema_migrations' /home/antoha/.rvm/gems/ruby-2.1.1/gems/datastax_rails-1.2.3/lib/datastax_rails/schema/migrator.rb:13:in 'initialize' /home/antoha/.rvm/gems/ruby-2.1.1/gems/datastax_rails-1.2.3/lib/datastax_rails/tasks/ds.rake:6:in 'new' /home/antoha/.rvm/gems/ruby-2.1.1/gems/datastax_rails-1.2.3/lib/datastax_rails/tasks/ds.rake:6:in 'block (2 levels) in [top (required)]' /home/antoha/.rvm/gems/ruby-2.1.1/bin/ruby_executable_hooks:15:in 'eval' /home/antoha/.rvm/gems/ruby-2.1.1/bin/ruby_executable_hooks:15:in '[main]' Tasks: TOP =] ds:migrate =] ds:configure

This code in /home/antoha/.rvm/gems/ruby-2.1.1/gems/cassandra-cql-1.2.2/lib/cassandra-cql/database.rb:117:in `execute_cql_query' is being called twice:

    def execute_cql_query(cql, compression=CassandraCQL::Thrift::Compression::NONE)
      binding.pry
      if use_cql3?
        @connection.execute_cql3_query(cql, compression, CassandraCQL::Thrift::ConsistencyLevel::QUORUM) #TODO consistency level
      else
        @connection.execute_cql_query(cql, compression)
      end
    rescue CassandraCQL::Thrift::InvalidRequestException
      raise Error::InvalidRequestException.new($!.why)
    end

I checked in Pry: for the first time value of compression is 2 (integer) and for the second time - {:consistency=>2} and of course that's wrong value:

/home/antoha/.rvm/gems/ruby-2.1.1/gems/cassandra-cql-1.2.2/vendor/0.8/gen-rb/cassandra_types.rb

    module Compression
      GZIP = 1
      NONE = 2
      VALUE_MAP = {1 => "GZIP", 2 => "NONE"}
      VALID_VALUES = Set.new([GZIP, NONE]).freeze
    end

Previous line in backtrace is "/home/antoha/.rvm/gems/ruby-2.1.1/gems/datastax_rails-1.2.3/lib/datastax_rails/cql/base.rb:25:in `execute'":

      # Generates the CQL and calls Cassandra to execute it.
      # If you are using this outside of Rails, then DatastaxRails::Base.connection must have
      # already been set up (Rails does this for you).
      def execute
        cql = self.to_cql
        puts cql if ENV['DEBUG_CQL'] == 'true'
        DatastaxRails::Base.connection.execute_cql_query(cql, :consistency => CassandraCQL::Thrift::ConsistencyLevel.const_get(@consistency || 'QUORUM'))
      end
jasonmk commented 10 years ago

Right, I forgot that I had created a modified version of cassandra-cql. The actual one doesn't support consistency at all (everything is QUORUM), but I absolutely needed the ability to specify it. You can find the version I used here if you want: https://github.com/jasonmk/cassandra-cql. I've actually got a branch though where I'm moving off of cassandra-cql over to cql-rb. It uses the newer binary protocol (no more thrift!) and supports a lot more features, including consistency. I'm not sure when it will be ready though. The typing stuff needs to be completely re-written for it.

trushkevich commented 10 years ago

I've actually got a branch though where I'm moving off of cassandra-cql over to cql-rb. It uses the newer binary protocol (no more thrift!) and supports a lot more features, including consistency.

great!

I'm not sure when it will be ready though. The typing stuff needs to be completely re-written for it.

It's open-source and you work alone, so there's no surprise ;-)

As for your fork https://github.com/jasonmk/cassandra-cql I get the following error when I run "rake ds:migrate":

rake aborted! CassandraCQL::Error::InvalidRequestException: Undefined name key_alias in selection clause /home/antoha/.rvm/gems/ruby-2.1.1/bundler/gems/cassandra-cql-8fb9e0eafdb4/lib/cassandra-cql/database.rb:126:in 'rescue in execute_cql_query' /home/antoha/.rvm/gems/ruby-2.1.1/bundler/gems/cassandra-cql-8fb9e0eafdb4/lib/cassandra-cql/database.rb:115:in 'execute_cql_query' /home/antoha/.rvm/gems/ruby-2.1.1/gems/datastax_rails-1.2.3/lib/datastax_rails/cql/base.rb:26:in 'execute' /home/antoha/.rvm/gems/ruby-2.1.1/gems/datastax_rails-1.2.3/lib/datastax_rails/schema/cassandra.rb:111:in 'check_key_name' /home/antoha/.rvm/gems/ruby-2.1.1/gems/datastax_rails-1.2.3/lib/datastax_rails/schema/migrator.rb:76:in 'check_schema_migrations' /home/antoha/.rvm/gems/ruby-2.1.1/gems/datastax_rails-1.2.3/lib/datastax_rails/schema/migrator.rb:13:in 'initialize' /home/antoha/.rvm/gems/ruby-2.1.1/gems/datastax_rails-1.2.3/lib/datastax_rails/tasks/ds.rake:6:in 'new' /home/antoha/.rvm/gems/ruby-2.1.1/gems/datastax_rails-1.2.3/lib/datastax_rails/tasks/ds.rake:6:in 'block (2 levels) in [top (required)]' /home/antoha/.rvm/gems/ruby-2.1.1/bin/ruby_executable_hooks:15:in 'eval' /home/antoha/.rvm/gems/ruby-2.1.1/bin/ruby_executable_hooks:15:in '[main]' CassandraCQL::Thrift::InvalidRequestException: Undefined name key_alias in selection clause /home/antoha/.rvm/gems/ruby-2.1.1/bundler/gems/cassandra-cql-8fb9e0eafdb4/vendor/1.2/gen-rb/cassandra.rb:631:in 'recv_execute_cql3_query' /home/antoha/.rvm/gems/ruby-2.1.1/bundler/gems/cassandra-cql-8fb9e0eafdb4/vendor/1.2/gen-rb/cassandra.rb:621:in 'execute_cql3_query' /home/antoha/.rvm/gems/ruby-2.1.1/gems/thrift_client-0.9.2/lib/thrift_client/abstract_thrift_client.rb:165:in 'block in handled_proxy' /home/antoha/.rvm/gems/ruby-2.1.1/gems/thrift_client-0.9.2/lib/thrift_client/abstract_thrift_client.rb:146:in 'ensure_socket_alignment' /home/antoha/.rvm/gems/ruby-2.1.1/gems/thrift_client-0.9.2/lib/thrift_client/abstract_thrift_client.rb:165:in 'handled_proxy' /home/antoha/.rvm/gems/ruby-2.1.1/gems/thrift_client-0.9.2/lib/thrift_client/abstract_thrift_client.rb:53:in 'execute_cql3_query' /home/antoha/.rvm/gems/ruby-2.1.1/bundler/gems/cassandra-cql-8fb9e0eafdb4/lib/cassandra-cql/database.rb:121:in 'execute_cql_query' /home/antoha/.rvm/gems/ruby-2.1.1/gems/datastax_rails-1.2.3/lib/datastax_rails/cql/base.rb:26:in 'execute' /home/antoha/.rvm/gems/ruby-2.1.1/gems/datastax_rails-1.2.3/lib/datastax_rails/schema/cassandra.rb:111:in 'check_key_name' /home/antoha/.rvm/gems/ruby-2.1.1/gems/datastax_rails-1.2.3/lib/datastax_rails/schema/migrator.rb:76:in 'check_schema_migrations' /home/antoha/.rvm/gems/ruby-2.1.1/gems/datastax_rails-1.2.3/lib/datastax_rails/schema/migrator.rb:13:in 'initialize' /home/antoha/.rvm/gems/ruby-2.1.1/gems/datastax_rails-1.2.3/lib/datastax_rails/tasks/ds.rake:6:in 'new' /home/antoha/.rvm/gems/ruby-2.1.1/gems/datastax_rails-1.2.3/lib/datastax_rails/tasks/ds.rake:6:in 'block (2 levels) in [top (required)]' /home/antoha/.rvm/gems/ruby-2.1.1/bin/ruby_executable_hooks:15:in 'eval' /home/antoha/.rvm/gems/ruby-2.1.1/bin/ruby_executable_hooks:15:in '[main]' Tasks: TOP =] ds:migrate =] ds:configure

Hmm.. but in rails console I can query cassandra successfully via the class which inherits from DatastaxRails::Base.

jasonmk commented 10 years ago

Again, version 2.0.0 should fix all of this as I've done away with the cassandra-cql gem all-together.