2011-08-04 20 views
8

Cassandra-0.8.2 ile çalışıyorum. Hector'un & en son sürümüyle ile çalışıyorum Benim java versiyonu 1.6.0_26Hector & Cassandra Temelleri

Ben Cassandra & Hector çok yeni olduğum.

Yapmaya çalıştığım: 1. Farklı bir sunucuda bir & çalışan cassandra örneğine bağlanın. B/c koştuğunu biliyorum, terminalimi bu Cassandra örneğini çalıştıran sunucuya ssh ve CLI'yi tam işlevsellik ile çalıştırabilirim. 2. Daha sonra bir anahtar aralığına bağlanmak istiyorum & Bir sütun ailesi oluşturun ve ardından o sütun ailesine Hector aracılığıyla bir değer ekleyin.

Sorunum, bu sunucuda çalışan Cassandra örneğinin yerel olmayan komutlar için yapılandırılmamış olabileceğidir. Bir sonraki adımın, üzerinde çalışıyorum ve bunu yerel olarak yapmaya çalışıyorum cpu üzerinde Cassandra'nın yerel bir örneğini eklemek olacağını düşünüyorum. Ne düşünüyorsun?

16:22:19,852 INFO CassandraHostRetryService:37 - Downed Host Retry service started with queue size -1 and retry delay 10s 
16:22:20,136 INFO JmxMonitor:54 - Registering JMX me.prettyprint.cassandra.service_Test Cluster:ServiceType=hector,MonitorType=hector 
Exception in thread "main" me.prettyprint.hector.api.exceptions.HInvalidRequestException: InvalidRequestException(why:Keyspace apples does not exist) 
    at me.prettyprint.cassandra.connection.HThriftClient.getCassandra(HThriftClient.java:70) 
    at me.prettyprint.cassandra.connection.HConnectionManager.operateWithFailover(HConnectionManager.java:226) 
    at me.prettyprint.cassandra.service.KeyspaceServiceImpl.operateWithFailover(KeyspaceServiceImpl.java:131) 
    at me.prettyprint.cassandra.service.KeyspaceServiceImpl.batchMutate(KeyspaceServiceImpl.java:102) 
    at me.prettyprint.cassandra.service.KeyspaceServiceImpl.batchMutate(KeyspaceServiceImpl.java:108) 
    at me.prettyprint.cassandra.model.MutatorImpl$3.doInKeyspace(MutatorImpl.java:222) 
    at me.prettyprint.cassandra.model.MutatorImpl$3.doInKeyspace(MutatorImpl.java:219) 
    at me.prettyprint.cassandra.model.KeyspaceOperationCallback.doInKeyspaceAndMeasure(KeyspaceOperationCallback.java:20) 
    at me.prettyprint.cassandra.model.ExecutingKeyspace.doExecute(ExecutingKeyspace.java:85) 
    at me.prettyprint.cassandra.model.MutatorImpl.execute(MutatorImpl.java:219) 
    at me.prettyprint.cassandra.model.MutatorImpl.insert(MutatorImpl.java:59) 
    at org.cassandra.examples.MySample.main(MySample.java:25) 
Caused by: InvalidRequestException(why:Keyspace apples does not exist) 
    at org.apache.cassandra.thrift.Cassandra$set_keyspace_result.read(Cassandra.java:5302) 
    at org.apache.cassandra.thrift.Cassandra$Client.recv_set_keyspace(Cassandra.java:481) 
    at org.apache.cassandra.thrift.Cassandra$Client.set_keyspace(Cassandra.java:456) 
    at me.prettyprint.cassandra.connection.HThriftClient.getCassandra(HThriftClient.java:68) 
    ... 11 more 

Yardımlarınız için şimdiden teşekkürler:

import me.prettyprint.cassandra.serializers.StringSerializer; 
import me.prettyprint.cassandra.service.CassandraHostConfigurator; 
import me.prettyprint.hector.api.Cluster; 
import me.prettyprint.hector.api.Keyspace; 
import me.prettyprint.hector.api.ddl.ColumnFamilyDefinition; 
import me.prettyprint.hector.api.ddl.ComparatorType; 
import me.prettyprint.hector.api.factory.HFactory; 
import me.prettyprint.hector.api.mutation.Mutator; 

    public class MySample { 


     public static void main(String[] args) { 


      Cluster cluster = HFactory.getOrCreateCluster("Test Cluster", "xxx.xxx.x.41:9160"); 
      Keyspace keyspace = HFactory.createKeyspace("apples", cluster); 
      ColumnFamilyDefinition cf = HFactory.createColumnFamilyDefinition("apples","ColumnFamily2",ComparatorType.UTF8TYPE); 
      StringSerializer stringSerializer = StringSerializer.get(); 
      Mutator<String> mutator = HFactory.createMutator(keyspace, stringSerializer); 
      mutator.insert("jsmith", "Standard1", HFactory.createStringColumn("first", "John")); 
} 
} 

Benim HATA geçerli:

İşte benim Java kod.

Kodunuzda
why:Keyspace apples does not exist 

, bu hat aslında KEYSPACE yaratmaz alıyorsanız istisna değildir

+0

Keyspace elmaları yok mu? – Mat

cevap

8

,

Keyspace keyspace = HFactory.createKeyspace("apples", cluster); 

olarak here açıklanan bu tanımlamanızı gerektirecek koddur Anahtarınız:

ColumnFamilyDefinition cfDef = HFactory.createColumnFamilyDefinition("MyKeyspace", "ColumnFamilyName", ComparatorType.BYTESTYPE); 

KeyspaceDefinition newKeyspace = HFactory.createKeyspaceDefinition("MyKeyspace", ThriftKsDef.DEF_STRATEGY_CLASS, replicationFactor, Arrays.asList(cfDef)); 

// Add the schema to the cluster. 
// "true" as the second param means that Hector will block until all nodes see the change. 
cluster.addKeyspace(newKeyspace, true); 
+0

Cevabınız için teşekkür ederiz. Benim sorunum, bu kodu çalıştırmaya çalıştığımda replicationFactor undefined gibi görünüyor. Burada belirtilenleri tam olarak kopyaladım: https: //github.com/rantav/hector/wiki/Getting-started-%285-minutes%29, uygun ad değişkenleri değişti. "ReplicationFactor" un neden tanımlanmamış olduğu hakkında bir fikrin var mı? Bu sınıfa benim için başka bir şey yok. – Henry

+0

Bir derleyici hatası mı alıyorsunuz? int replicationfactor = 1 satırını ekleyebilir misiniz? – sbridges

+0

Teşekkürler Sorunumu çözdüm! – Henry