2

我正在运行一个单节点 Cassandra 实例(用于开发目的),并希望在其中插入一个整数行。我的 Keyspace 和 columnfamily 已经在 Cassandra 上创建了。

我正在使用 Cassandra 1.0 和 Hector 1.0.5(Jar 版本)。我的代码如下:

Cluster cluster = HFactory.getOrCreateCluster("Test Cluster", "10.40.14.93:9160");

Keyspace keyspaceOperator = HFactory.createKeyspace("mykeyspace", cluster)

Mutator intM = HFactory.createMutator(keyspaceOperator, IntegerSerializer.get());

for each elem in my list {

 intM.insert(doc.document_id , 
            "mycolfamily",
            me.prettyprint.hector.api.factory.HFactory.createColumn("numAdults", doc.numAdults))
}

我在客户端上收到 TimedOutException,在 Cassandra 日志中,我看到以下内容:

ERROR [MutationStage:357] 2012-07-20 08:15:02,106 AbstractCassandraDaemon.java (line  139) Fatal exception in thread Thread[MutationStage:357,5,main]
java.lang.RuntimeException: java.lang.NumberFormatException: For input string: ""
        at org.apache.cassandra.service.StorageProxy$DroppableRunnable.run(StorageProxy.java:1228)
        at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
        at java.lang.Thread.run(Thread.java:662)
Caused by: java.lang.NumberFormatException: For input string: ""
        at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
        at java.lang.Long.parseLong(Long.java:410)
        at java.lang.Long.parseLong(Long.java:468)
        at org.apache.solr.schema.TrieField.createField(TrieField.java:508)
        at org.apache.solr.schema.FieldType.createFields(FieldType.java:292)
        at org.apache.solr.schema.SchemaField.createFields(SchemaField.java:106)
        at com.datastax.bdp.cassandra.index.solr.SolrSecondaryIndex.addFieldToDocument(SolrSecondaryIndex.java:382)
        at com.datastax.bdp.cassandra.index.solr.SolrSecondaryIndex.populateDocument(SolrSecondaryIndex.java:280)
        at com.datastax.bdp.cassandra.index.solr.SolrSecondaryIndex.applyIndexUpdates(SolrSecondaryIndex.java:164)
        at org.apache.cassandra.db.index.SecondaryIndexManager.applyIndexUpdates(SecondaryIndexManager.java:419)
        at org.apache.cassandra.db.Table.apply(Table.java:448)
        at org.apache.cassandra.db.RowMutation.apply(RowMutation.java:256)
        at org.apache.cassandra.service.StorageProxy$6.runMayThrow(StorageProxy.java:415)
        at org.apache.cassandra.service.StorageProxy$DroppableRunnable.run(StorageProxy.java:1224)
        ... 3 more
ERROR [MutationStage:357] 2012-07-20 08:15:02,106 AbstractCassandraDaemon.java (line 139) Fatal exception in thread Thread[MutationStage:357,5,main]
java.lang.RuntimeException: java.lang.NumberFormatException: For input string: ""
        at org.apache.cassandra.service.StorageProxy$DroppableRunnable.run(StorageProxy.java:1228)
        at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
        at java.lang.Thread.run(Thread.java:662)
Caused by: java.lang.NumberFormatException: For input string: ""
        at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
        at java.lang.Long.parseLong(Long.java:410)
        at java.lang.Long.parseLong(Long.java:468)
        at org.apache.solr.schema.TrieField.createField(TrieField.java:508)
        at org.apache.solr.schema.FieldType.createFields(FieldType.java:292)
        at org.apache.solr.schema.SchemaField.createFields(SchemaField.java:106)
        at com.datastax.bdp.cassandra.index.solr.SolrSecondaryIndex.addFieldToDocument(SolrSecondaryIndex.java:382)
        at com.datastax.bdp.cassandra.index.solr.SolrSecondaryIndex.populateDocument(SolrSecondaryIndex.java:280)
        at com.datastax.bdp.cassandra.index.solr.SolrSecondaryIndex.applyIndexUpdates(SolrSecondaryIndex.java:164)
        at org.apache.cassandra.db.index.SecondaryIndexManager.applyIndexUpdates(SecondaryIndexManager.java:419)
        at org.apache.cassandra.db.Table.apply(Table.java:448)
        at org.apache.cassandra.db.RowMutation.apply(RowMutation.java:256)
        at org.apache.cassandra.service.StorageProxy$6.runMayThrow(StorageProxy.java:415)
        at org.apache.cassandra.service.StorageProxy$DroppableRunnable.run(StorageProxy.java:1224)

}

我正在试用包含 Cassandra、Hadoop、Solr 等的 Datastax Enterprise (DSE)。我已经通过 Solr 配置创建了我的 Cassandra CF(您可以将 Solr 配置和模式 xmls 发布到 Datastax 实例以创建 Keyspace 和 CF - 它的一个功能DSE)

有人可以帮忙吗?

4

1 回答 1

1

尝试将显式序列化程序添加到您的 createColumn 调用...像这样:

me.prettyprint.hector.api.factory.HFactory.createColumn("numAdults", doc.numAdults, StringSerializer.get(), IntegerSerializer.get()))

另外,另一方面,我看到您正在循环中进行插入。在循环内执行 intM.addInsertion ,然后在完成后执行 intM.execute() 效率更高。

于 2012-07-20T21:26:34.967 回答