Google cloud platform apachebeam:为什么它在REPORT\u故障模式下两次写入扳手?
我在查看SpanRio时发现编写操作代码很有趣,我想了解其中的原因 在写入(Google cloud platform apachebeam:为什么它在REPORT\u故障模式下两次写入扳手?,google-cloud-platform,apache-beam,google-cloud-spanner,Google Cloud Platform,Apache Beam,Google Cloud Spanner,我在查看SpanRio时发现编写操作代码很有趣,我想了解其中的原因 在写入(writeToPanerfn)和报告失败失败模式下,它似乎尝试写入失败的突变两次。 我认为这是为了记录每个变异的异常。这是一个正确的假设吗?是否有解决办法? 下面,为了简单起见,我删除了一些行 public void processElement(ProcessContext c) { Iterable<MutationGroup> mutations = c.element(); boolean t
writeToPanerfn
)和报告失败
失败模式下,它似乎尝试写入失败的突变两次。我认为这是为了记录每个变异的异常。这是一个正确的假设吗?是否有解决办法?
下面,为了简单起见,我删除了一些行
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);
}
}
}
}
public void processElement(ProcessContext c){
Iterable突变=c.元素();
布尔tryIndividual=false;
试一试{
Iterable批次=Iterables.concat(突变);
span Raccessor.getDatabaseClient().writeAtLeastOnce(批处理);
}捕捉(扳手){
如果(failureMode==failureMode.报告故障){
tryIndividual=true;
}否则{
...
}
}
if(tryIndividual){
对于(突变组mg:突变){
试一试{
span raccessor.getDatabaseClient().writeAtLeastOnce(mg);
}捕捉(扳手){
LOG.warn(“未能提交突变组”,e);
c、 输出(失败的标记,毫克);
}
}
}
}
因此,为了提高效率,span.write()连接器尝试在单个事务中写入一批突变,而不是将每个突变单独写入数据库
如果批处理中只有一个突变失败,则整个事务失败,因此在REPORT_FAILURES(报告失败)模式下,将分别重新尝试这些突变,以找出哪些突变是有问题的