【问题标题】:BigTable ReadModifyWriteRow Support for Mapping FunctionBigTable ReadModifyWriteRow 支持映射函数
【发布时间】:2021-12-14 00:57:02
【问题描述】:

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

Function<Long, Long> modifyFunc = f -> f & 10L;

ReadModifyWriteRow
  .create("tableName", "rowKey")
  .apply("family", "qualifier", modifyFunc);

【问题讨论】:

  • Bigtable 变异 API 不支持这种情况
  • @BillyJacobson 我想我应该重新表述这个问题 - 你有什么替代方法来解决这样的问题(原子读取 + 修改值),还是不可能?

标签: java hbase google-cloud-bigtable bigtable


【解决方案1】:

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);

【讨论】:

  • 啊,有趣。我想如果对特定行的写入频率足够低,理论上这可以放入一个循环中以确保它最终写入一条记录-查询+有条件地写入,直到其他有争议的写入停止。感谢您的建议
猜你喜欢
  • 1970-01-01
  • 2010-10-09
  • 2021-09-17
  • 2015-11-15
  • 1970-01-01
  • 2022-07-22
  • 2016-06-09
  • 2012-01-03
  • 2021-08-31
相关资源
最近更新 更多