我正在使用Accumulo 1.6.2,但看到一个问题,看来TableOperations.createTable
可能无一例外地返回,但表仍未准备好。
例如下面的代码:
String tableName = "foo";
TableOperations operations = connector.tableOperations();
if(!operations.exists(tableName))
{
operations.createTable(tableName);
}
//Make a bunch of mutations that write to the table
BatchWriter batchWriter = connector.createBatchWriter(tableName, someConfig);
batchWriter.addMutations(mutations);
batchWriter.close();
使用上述代码运行单元测试时,有时会出现异常,指示表
foo
不存在。但是,该代码刚刚创建了表foo
。我唯一能想到的是,在
createTable()
返回之后的某个时间窗口中,该表可能仍然不存在。Javadoc没有解释该行为。我还阅读了Orielly的Accumulo书的早期发行版,但也没有说。
这里的正确模式是什么?我可以添加如下内容:
//Make table
while(!operations.exists(tableName){}
//Do stuff with table
但是,这似乎是一件非常丑陋且容易出错的事情。我希望这里有更好的模式。
最佳答案
创建表应该是同步操作。上面的示例不会出现异常。
如果您可以提供特定的异常,则可能暗示需要修复的错误。
关于java - Accumulo TableOperations.createTable是否同步?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31058903/