2011-08-04 2 views
8

저는 Cassandra-0.8.2와 협력하고 있습니다. 내가 헥터 &의 최신 버전 함께 일하고 내 자바 버전 1.6.0_26Hector & Cassandra의 기본 정보

내가 카산드라 & 헥터 아주 새로운 해요입니다.

내가하려는 일 : 1. 다른 서버에서 실행중인 &의 cassandra 인스턴스를 연결하십시오. 나는이 Cassandra 인스턴스를 실행하는 서버에 터미널을 통해 ssh 연결할 수 있고 모든 기능을 갖춘 CLI를 실행할 수 있습니다. 2. 키 공간에 연결하려면 & 열 패밀리를 작성한 다음 Hector를 통해 해당 열 패밀리에 값을 추가하십시오.

내 문제는이 서버에서 실행중인 Cassandra 인스턴스가 로컬이 아닌 명령을 가져 오도록 구성되지 않았을 수 있다고 생각합니다. 내 다음 단계는 내가하고있는 CPU에 Cassandra의 로컬 인스턴스를 추가하여 로컬에서이 작업을 수행하는 것입니다. 어떻게 생각해?

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 

당신의 도움에 미리 감사합니다

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")); 
} 
} 

내 오류는 다음과 같습니다

여기 내 자바 코드입니다.

코드에서
why:Keyspace apples does not exist 

,이 라인은 실제로 키 스페이스를 작성하지 않습니다 당신은 점점 예외는

+0

'Keyspace apples does not exist'를 보았습니까? – Mat

답변

8

,

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

바와 같이 here을 설명, 이것은 당신이 정의하는 데 필요한 코드입니다 귀하의 키 스페이스

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

답변 해 주셔서 감사합니다. 내 문제는이 코드를 실행하려고 할 때 replicationFactor가 정의되지 않은 것 같다는 것입니다. 필자는 https : //github.com/rantav/hector/wiki/Getting-started-%285-minutes%29에 제공된 이름으로 바뀌 었으며, 적절한 이름 변수가 변경되었습니다. "replicationFactor"가 정의되지 않은 이유는 무엇입니까? 이 수업으로 가져올 다른 것은 없습니다. – Henry

+0

컴파일러 오류가 발생하고 있습니까? 당신은 line int replicationfactor = 1을 추가 할 수 있습니까? – sbridges

+0

감사합니다. 내 문제를 알아 냈습니다! – Henry