将SSTableSimpleUnsortedWriter与all-key-columns表一起使用

时间:2015-10-14 20:02:54

标签: cassandra

我有一张表:

CREATE TABLE example (
  id TEXT,
  time TIMESTAMP,
  value TEXT,
  PRIMARY KEY (id, time, value));

在代码中有类似的内容:

cmpType = CompositeType.getInstance(AsciiType.instance,
                                    TimestampType.instance,
                                    AsciiType.instance);

SSTableSimpleUnsortedWriter writer = new SSTableSimpleUnsortedWriter(outputDir,
        new Murmur3Partitioner(), keyspace, table, cmpType, null, sstSize);

void write(String id, Date time, String value) {
    long timestamp = System.currentTimeMillis() * 1000;
    writer.newRow(bytes(id));
    writer.addColumn(
            cmpType.builder()
                   .add(TimestampType.instance.decompose(time))
                   .add(bytes(value))
                   .build(),
            bytes(""), timestamp);
}

但我不知道如何在这种情况下正确使用addColumn。当我尝试使用sstableloader将此类代码的结果上传到Cassandra时,我得到:

java.util.concurrent.ExecutionException: org.apache.cassandra.streaming.StreamException: Stream failed
    at com.google.common.util.concurrent.AbstractFuture$Sync.getValue(AbstractFuture.java:299)
    at com.google.common.util.concurrent.AbstractFuture$Sync.get(AbstractFuture.java:286)
    at com.google.common.util.concurrent.AbstractFuture.get(AbstractFuture.java:116)
    at org.apache.cassandra.tools.BulkLoader.main(BulkLoader.java:122)
Caused by: org.apache.cassandra.streaming.StreamException: Stream failed
    at org.apache.cassandra.streaming.management.StreamEventJMXNotifier.onFailure(StreamEventJMXNotifier.java:85)
    at com.google.common.util.concurrent.Futures$4.run(Futures.java:1172)
    at com.google.common.util.concurrent.MoreExecutors$SameThreadExecutorService.execute(MoreExecutors.java:297)
    at com.google.common.util.concurrent.ExecutionList.executeListener(ExecutionList.java:156)
    at com.google.common.util.concurrent.ExecutionList.execute(ExecutionList.java:145)
    at com.google.common.util.concurrent.AbstractFuture.setException(AbstractFuture.java:202)
    at org.apache.cassandra.streaming.StreamResultFuture.maybeComplete(StreamResultFuture.java:208)
    at org.apache.cassandra.streaming.StreamResultFuture.handleSessionComplete(StreamResultFuture.java:184)
    at org.apache.cassandra.streaming.StreamSession.closeSession(StreamSession.java:412)
    at org.apache.cassandra.streaming.StreamSession.sessionFailed(StreamSession.java:617)
    at org.apache.cassandra.streaming.StreamSession.messageReceived(StreamSession.java:472)
    at org.apache.cassandra.streaming.ConnectionHandler$IncomingMessageHandler.run(ConnectionHandler.java:256)
    at java.lang.Thread.run(Thread.java:745)

1 个答案:

答案 0 :(得分:0)

解决方案是为列添加一些名称以获取最后一个未使用的值:

writer.addColumn(
        cmpType.builder()
               .add(TimestampType.instance.decompose(time))
               .add(bytes(value))
               .add(bytes("empty"))
               .build(),
        bytes(""), timestamp);