【发布时间】: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