BigTable ReadModifyWriteRow支持映射功能



我知道BigTable支持使用ReadModifyWriteRow请求的操作appendincrement,但我想知道是否有支持或替代方法来使用更通用的映射函数,其中来自单元格的值可以在某种闭包内访问和修改?例如,按位AND处理单元格中的长值:

Function<Long, Long> modifyFunc = f -> f & 10L;
ReadModifyWriteRow
.create("tableName", "rowKey")
.apply("family", "qualifier", modifyFunc);

Bigtable不支持这样的映射,因此您可以尝试以下选项。这只适用于单个集群实例,因为它需要一致性。

你可以添加一个列来跟踪行版本(除了现有的行版本),然后你可以读取数据和版本,在内存中修改它,然后用版本和新值做一个checkAndMutate。像这样:

Row row = dataClient.readRow(tableId, rowkey);
ArrayList<RowCell> cells = row.getCells();
// Get the value and timestamp/version from the cell you are targetting.
RowCell cell = cells.get(...);
long version = cell.getTimestamp();
ByteString value = cell.getValue();
// Do your mapping to the new value.
ByteString newValue = ...;
Mutation mutation =
Mutation.create().setCell(COLUMN_FAMILY_NAME, COLUMN_NAME, timestamp, newValue);
// Filter on a column that tracks the version to do validation.
Filter filter =
FILTERS
.chain()
.filter(FILTERS.family().exactMatch(COLUMN_FAMILY_NAME))
.filter(FILTERS.qualifier().exactMatch(VERSION_COLUMN))
.filter(FILTERS.value().exactMatch(version));
ConditionalRowMutation conditionalRowMutation =
ConditionalRowMutation.create(tableId, rowkey).condition(filter).then(mutation);
boolean success = dataClient.checkAndMutateRow(conditionalRowMutation);

最新更新