【问题标题】:Apache Beam: Why does it write to Spanner twice on REPORT_FAILURES mode?Apache Beam:为什么它在 REPORT_FAILURES 模式下两次写入 Spanner?
【发布时间】:2019-02-27 23:33:24
【问题描述】:

我在看SpannerIO的时候发现了有趣的写操作代码,想了解一下原因。

在写入(WriteToSpannerFn) 和REPORT_FAILURES 失败模式时,它似乎试图写入两次失败的突变。
我认为这是为了记录每个突变的异常。这是一个正确的假设,是否有任何解决方法?
下面,为了简单起见,我删除了一些行。

public void processElement(ProcessContext c) {
  Iterable<MutationGroup> mutations = c.element();
  boolean tryIndividual = false;

  try {
    Iterable<Mutation> batch = Iterables.concat(mutations);
    spannerAccessor.getDatabaseClient().writeAtLeastOnce(batch);
  } catch (SpannerException e) {
    if (failureMode == FailureMode.REPORT_FAILURES) {
      tryIndividual = true;
    } else {
      ...
    }
  }
  if (tryIndividual) {
    for (MutationGroup mg : mutations) {
      try {
        spannerAccessor.getDatabaseClient().writeAtLeastOnce(mg);
      } catch (SpannerException e) {
        LOG.warn("Failed to submit the mutation group", e);
        c.output(failedTag, mg);
      }
    }
  }
}

【问题讨论】:

    标签: google-cloud-platform apache-beam google-cloud-spanner


    【解决方案1】:

    因此,为了提高效率,SpannerIO.write() 连接器尝试在单个事务中写入一批 Mutation,而不是将每个 Mutation 单独写入数据库。

    如果批处理中只有一个 Mutations 失败,那么整个事务就会失败,因此在 REPORT_FAILURES 模式下,会单独重新尝试这些 Mutations,以找出哪些 Mutation(s) 是有问题的......

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-10-06
      • 1970-01-01
      • 1970-01-01
      • 2018-12-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-12-24
      相关资源
      最近更新 更多