【问题标题】:Cloud Bigtable: when I filter by column, are my modify requests atomic?Cloud Bigtable:当我按列过滤时,我的修改请求是原子的吗?
【发布时间】:2020-01-16 23:45:33
【问题描述】:

在我的 Cloud Bigtable 表中,我每秒有数百万个请求。我得到一个唯一的行键,然后我需要用原子突变修改行。

当我按列过滤以获取密钥时,每个请求都会是原子的吗?

col1_filter = row_filters.ColumnQualifierRegexFilter(b'customerId')
label1_filter = row_filters.ValueRegexFilter('')
chain1 = row_filters.RowFilterChain(filters=[col1_filter, label1_filter])

partial_rows = table.read_rows(filter_=chain1)

for data in partial_rows:
    row_cond = table.row(data.cell[row_key])
    row_cond.set_cell(u'data', b'customerId', b'value', state=True)
    row_cond.commit()

【问题讨论】:

    标签: python bigtable google-cloud-bigtable


    【解决方案1】:

    CheckAndMutateRow operations are atomic,但它是检查和变异 row 而不是行。因此,您进行此设置的方式不会创建原子操作。

    您需要使用行键和过滤器创建一个conditional row 对象,提供修改,然后提交。像这样:

    col1_filter = row_filters.ColumnQualifierRegexFilter(b'customerId')
    label1_filter = row_filters.ValueRegexFilter('')
    chain1 = row_filters.RowFilterChain(filters=[col1_filter, label1_filter])
    
    partial_rows = table.read_rows()
    
    for data in partial_rows:
        row_cond = table.row(data.cell[row_key], filter_=chain1) # Use filter here
        row_cond.set_cell(u'data', b'customerId', b'value', state=True)
        row_cond.commit()
    

    因此,您必须进行全表扫描并将过滤器应用于每一行。如果您正在应用该过滤器,那么您已经在进行全面扫描,因此不应该存在性能差异。对于 Cloud Bigtable 的最佳做法,您希望避免全表扫描。如果这是您需要运行的一次性程序,那很好,否则,如果您要定期执行此操作,您可能想找出一种不同的方法来执行此操作。

    请注意,我们是 updating the API,以便更清楚地了解不同类型的突变。

    【讨论】:

      猜你喜欢
      • 2019-01-17
      • 1970-01-01
      • 2017-03-02
      • 2013-02-16
      • 1970-01-01
      • 1970-01-01
      • 2021-04-03
      • 2013-02-24
      • 1970-01-01
      相关资源
      最近更新 更多