8

私はCassandra-0.8.2で作業しています。私はHectorの最新バージョンで作業しています。私のJavaバージョンは1.6.0_26です。

私はCassandra&Hectorにとても慣れていません。

私がやろうとしていること:1。別のサーバーで稼働中のcassandraのインスタンスに接続します。私はそれがb/cを実行していることを知っています。ターミナルを介して、このCassandraインスタンスを実行しているサーバーにSSHで接続し、完全な機能でCLIを実行できます。2.次に、キースペースに接続して列ファミリーを作成し、Hectorを介してその列ファミリーに値を追加します。

私の問題は、このサーバーで実行されているCassandraのインスタンスが、ローカルではないコマンドを取得するように構成されていない可能性があることだと思います。次のステップは、作業中のCPUにCassandraのローカルインスタンスを追加し、これをローカルで実行することだと思います。どう思いますか?

これが私のJavaコードです:

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

私のエラーは次のとおりです。

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

よろしくお願いします。

4

2 に答える 2

8

あなたが得ている例外は、

why:Keyspace apples does not exist

コードでは、この行は実際にはキースペースを作成しませんが、

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

ここで説明するように、これはキースペースを定義するために必要なコードです。

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);
于 2011-08-05T02:57:08.600 に答える
3

また、ウィキのスタートガイドもあります。これは役立つかもしれません。

于 2011-08-05T16:46:26.213 に答える