如何使用rowdeletingiterator

o3imoua4  于 2021-06-04  发布在  Hadoop
关注(0)|答案(1)|浏览(254)

我正试图用rowdeletingiterator删除accumulo表中的条目,但是当我随后扫描表时,这些条目并没有被删除。假设有一个 row_id 表中的条目 tableName 下面是我要做的:

Connection connection = new ZooKeeperInstance(instance, zookeepers).getConnector(username, new PasswordToken(password));
String tableName = "tableName";
connection.tableOperations().create(tableName);
connection.tableOperations().attachIterator(tableName, new IteratorSetting(1, RowDeletingIterator.class));

// Write record with row key "row_id"
String row_id = "row_id";
Text colf = new Text("");
Text colq = new Text("data");
ColumnVisibility colv = new ColumnVisibility("");
BatchWriter writer = connection.createBatchWriter(tableName, new BatchWriterConfig()
            .setMaxMemory(memBuf)
            .setMaxLatency(timeout, TimeUnit.MILLISECONDS)
            .setMaxWriteThreads(numThreads));
Mutation mutation = new Mutation(row_id);
mutation.put(colf, colq, colv, System.nanoTime(), new Value("stuff".getBytes()));
writer.addMutation(mutation);
writer.close();

... //More work takes place

// Delete the record with row key "row_id"
BatchWriter batchWriter = connection.createBatchWriter(tableName, new BatchWriterConfig()
            .setMaxMemory(memBuf)
            .setMaxLatency(timeout, TimeUnit.MILLISECONDS)
            .setMaxWriteThreads(numThreads));
Mutation mutation = new Mutation(row_id);
mutation.put(new Text(), new Text(), new ColumnVisibility(), RowDeletingIterator.DELETE_ROW_VALUE);
batchWriter.addMutation(mutation);
batchWriter.close();
0g0grzrc

0g0grzrc1#

原来问题出在 System.nanoTime() 第一次插入的部分。通过移除并使初始插入为:

mutation.put(colf, colq, colv, new Value("stuff".getBytes()));

这个 RowDeletingIterator 像应该的那样工作。

相关问题