具有令牌范围的java AllRowsReader类
这是使用Astyanax配方中的AllRowsReader类的一个示例:
reader = new AllRowsReader.Builder<>(keyspace, columnFamily)
.withPageSize(1000)
.withConcurrencyLevel(10)
.withPartitioner(null)
.withConsistencyLevel(ConsistencyLevel.CL_ONE)
.withIncludeEmptyRows(false)
.withTokenRange(startToken, endToken)
.forEachRow(new Function<Row<String, String>, Boolean>() {
@Override
public Boolean apply(@Nullable Row<String, String> row) {
startToken = keyspace.getPartitioner().getTokenForKey(row.getRawKey());
// some other statements
return true;
}
})
.build();
reader.call();
在哪里
startToken = keyspace.getPartitioner().getMinToken();
lastToken = keyspace.getPartitioner().getMaxToken();
如果运行AllRowsReader而不使用“和TokenRange(startToken,endToken)”,那么一切正常。但是使用“withTokenRange(startToken,endToken)”并不是在读取列族期间获取所有行
AllRowsReader的源代码如下:
if (this.concurrencyLevel != null || startToken != null|| endToken != null) {
List<TokenRange> tokens = partitioner.splitTokenRange(
startToken == null ? partitioner.getMinToken() : startToken,
endToken == null ? partitioner.getMinToken() : endToken,
this.concurrencyLevel == null ? 1 : this.concurrencyLevel);
for (TokenRange range : tokens) {
subtasks.add(makeTokenRangeTask(range.getStartToken(), range.getEndToken()));
}
}
后来,分裂者。getMinToken()恢复为maxToken。所以我不明白我的方法有什么不同?为什么AllRowsReader有minToken/maxToken的作品与AllRowsReader没有它们的作品不同
如果操作被终止,我将使用最后一个startToken再次执行它(因此它必须是一个移位)。但在本例中,我看到一些行是以前提取的。这也让我困惑
p.S.Astyanax自动确定Murruit3Partitioner
谢谢你的帮助
# 1 楼答案
德米特里, 将令牌范围视为一个环,当圆完成时,开始将等于结束。这就是为什么在astyanax代码中设置了与min和max相同的标记
我希望这能澄清你的答案。如果你有疑问,请告诉我