Cassandra-cql:创建密钥空间时获取TransportException

时间:2013-02-21 12:00:13

标签: cassandra cql

我是cassandra-cql的新手,在使用以下代码创建键空间时遇到问题。 我的目的是创建一个用于测试的密钥空间,然后在测试后将其删除。我经常得到例外。有时创建了键空间,但有时却没有。

我在某个地方搜索并试图增加connect_timeout但它没有帮助。 你能告诉我应该做什么吗?

**CassandraCQL::Thrift::Client::TransportException:** 
org/jruby/RubyBasicObject.java:1679:in `__send__'
org/jruby/RubyKernel.java:2085:in `send'

def self.create_keyspace(keyspace)
  db = CassandraCQL::Database.new($cassandra_host, {}, {:connect_timeout => 10000})
  db.execute("CREATE KEYSPACE #{keyspace} WITH strategy_class = 'SimpleStrategy' AND strategy_options:replication_factor = 3")
  db.disconnect!()
end

def self.remove_keyspace(keyspace)
  db = CassandraCQL::Database.new($cassandra_host)
  db.execute("DROP KEYSPACE #{keyspace}")
  db.disconnect!()
end

系统日志:

INFO [MigrationStage:1] 2013-02-22 11:01:56,526 Migration.java (line 119) Applying migration 996e0020-7ca4-11e2-0000-f7e85c70fcbe Add keyspace: clients, rep strategy:SimpleStrategy{}, durable_writes: true
INFO [MigrationStage:1] 2013-02-22 11:01:56,527 ColumnFamilyStore.java (line 704) Enqueuing flush of Memtable-Migrations@1366812340(86128/107660 serialized/live bytes, 1 ops)
INFO [FlushWriter:5] 2013-02-22 11:01:56,528 Memtable.java (line 246) Writing Memtable-Migrations@1366812340(86128/107660 serialized/live bytes, 1 ops)
INFO [MigrationStage:1] 2013-02-22 11:01:56,531 ColumnFamilyStore.java (line 704) Enqueuing flush of Memtable-Schema@382426421(82194/102742 serialized/live bytes, 12 ops)
INFO [FlushWriter:5] 2013-02-22 11:01:56,543 Memtable.java (line 283) Completed flushing /opt/cirrus/data/cassandra/data/system/Migrations-hc-2514-Data.db (86192 bytes)
INFO [FlushWriter:5] 2013-02-22 11:01:56,545 Memtable.java (line 246) Writing Memtable-Schema@382426421(82194/102742 serialized/live bytes, 12 ops)
INFO [CompactionExecutor:11] 2013-02-22 11:01:56,545 CompactionTask.java (line 113) Compacting [SSTableReader(path='/opt/cirrus/data/cassandra/data/system/Migrations-hc-2511-Data.db'), SSTableReader(path='/opt/cirrus/data/cassandra/data/system/Migrations-hc-2513-Data.db'), SSTableReader(path='/opt/cirrus/data/cassandra/data/system/Migrations-hc-2514-Data.db'), SSTableReader(path='/opt/cirrus/data/cassandra/data/system/Migrations-hc-2512-Data.db')]
INFO [FlushWriter:5] 2013-02-22 11:01:56,564 Memtable.java (line 283) Completed flushing /opt/cirrus/data/cassandra/data/system/Schema-hc-2514-Data.db (82426 bytes)
INFO [CompactionExecutor:12] 2013-02-22 11:01:56,565 CompactionTask.java (line 113) Compacting [SSTableReader(path='/opt/cirrus/data/cassandra/data/system/Schema-hc-2512-Data.db'), SSTableReader(path='/opt/cirrus/data/cassandra/data/system/Schema-hc-2511-Data.db'), SSTableReader(path='/opt/cirrus/data/cassandra/data/system/Schema-hc-2513-Data.db'), SSTableReader(path='/opt/cirrus/data/cassandra/data/system/Schema-hc-2514-Data.db')]

以下功能的临时解决方法:

def self.create_keyspace(keyspace, timeout)
  return if Environment.keyspace_exist?(keyspace)
  while !Environment.keyspace_exist?(keyspace) && timeout >= 0
    begin
      sleep(3)
      timeout = timeout - 3
      @cassandra_db_conn.execute("CREATE KEYSPACE #{keyspace} WITH strategy_class = 'SimpleStrategy' AND strategy_options:replication_factor = 3")
    rescue
      puts "*** WARNING: Error when creating '#{keyspace}' keyspace"
    end
  end
  raise "*** ERROR: The '#{keyspace}' keyspace could not be created in '#{timeout}' second" if timeout < 0
end

结果显示有2次获得异常。

*** WARNING: Error when creating 'clients' keyspace
*** WARNING: Error when creating 'clients' keyspace
1 scenario (1 passed)
11 steps (11 passed)
0m10.729s

0 个答案:

没有答案