java backoff_Java BackOff类代码示例

java backoff_Java BackOff类代码示例importorg.apache.beam.sdk.util.BackOff;//导入依赖的package包/类/***WritesabatchofmutationstoCloudDatastore.**Ifacommitfails,itwillberetriedupto{@link#MAX_RETRIES}times.All*mutations…

大家好,又见面了,我是你们的朋友全栈君。

import org.apache.beam.sdk.util.BackOff; //导入依赖的package包/类

/**

* Writes a batch of mutations to Cloud Datastore.

*

*

If a commit fails, it will be retried up to {@link #MAX_RETRIES} times. All

* mutations in the batch will be committed again, even if the commit was partially

* successful. If the retry limit is exceeded, the last exception from Cloud Datastore will be

* thrown.

*

* @throws DatastoreException if the commit fails or IOException or InterruptedException if

* backing off between retries fails.

*/

private void flushBatch() throws DatastoreException, IOException, InterruptedException {

LOG.debug(“Writing batch of {} mutations”, mutations.size());

Sleeper sleeper = Sleeper.DEFAULT;

BackOff backoff = BUNDLE_WRITE_BACKOFF.backoff();

while (true) {

// Batch upsert entities.

CommitRequest.Builder commitRequest = CommitRequest.newBuilder();

commitRequest.addAllMutations(mutations);

commitRequest.setMode(CommitRequest.Mode.NON_TRANSACTIONAL);

long startTime = System.currentTimeMillis(), endTime;

if (throttler.throttleRequest(startTime)) {

LOG.info(“Delaying request due to previous failures”);

throttledSeconds.inc(WriteBatcherImpl.DATASTORE_BATCH_TARGET_LATENCY_MS / 1000);

sleeper.sleep(WriteBatcherImpl.DATASTORE_BATCH_TARGET_LATENCY_MS);

continue;

}

try {

datastore.commit(commitRequest.build());

endTime = System.currentTimeMillis();

writeBatcher.addRequestLatency(endTime, endTime – startTime, mutations.size());

throttler.successfulRequest(startTime);

rpcSuccesses.inc();

// Break if the commit threw no exception.

break;

} catch (DatastoreException exception) {

if (exception.getCode() == Code.DEADLINE_EXCEEDED) {

/* Most errors are not related to request size, and should not change our expectation of

* the latency of successful requests. DEADLINE_EXCEEDED can be taken into

* consideration, though. */

endTime = System.currentTimeMillis();

writeBatcher.addRequestLatency(endTime, endTime – startTime, mutations.size());

}

// Only log the code and message for potentially-transient errors. The entire exception

// will be propagated upon the last retry.

LOG.error(“Error writing batch of {} mutations to Datastore ({}): {}”, mutations.size(),

exception.getCode(), exception.getMessage());

rpcErrors.inc();

if (NON_RETRYABLE_ERRORS.contains(exception.getCode())) {

throw exception;

}

if (!BackOffUtils.next(sleeper, backoff)) {

LOG.error(“Aborting after {} retries.”, MAX_RETRIES);

throw exception;

}

}

}

LOG.debug(“Successfully wrote {} mutations”, mutations.size());

mutations.clear();

mutationsSize = 0;

}

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/147509.html原文链接:https://javaforall.net

赞 (0)
全栈程序员-站长的头像全栈程序员-站长

相关推荐

  • pycharm安装后无法运行_pycharm代码运行不了

    pycharm安装后无法运行_pycharm代码运行不了问题:pycharm安装后不能执行python脚本的问题原因:pycharm没有设置解析器解决方法:打开pycharm->File->Settings->ProjectInterpreter->设置未你的python路径,我的是:C:\Python27\python.exe,你们根据各自python安装路径修改一下即可

    2022年8月26日
  • Maven报错:The packaging for this project did not assign a file to the build artifact[通俗易懂]

    Maven报错:The packaging for this project did not assign a file to the build artifact[通俗易懂]一、问题发生    我想使用IDEA的Maven管理工具将项目安装到本地仓库,于是选择了Plugins下的install:install去执行,如下图所示:结果出现了如下报错信信息:[ERROR]Failedtoexecutegoalorg.apache.maven.plugins:maven-install-…

    2022年5月15日
  • 匹配滤波(四种滤波器的幅频特性)

    匹配滤波(matchedfiltering)是最佳滤波的一种。当输入信号具有某一特殊波形时,其输出达到最大。在形式上,一个匹配滤波器由以按时间反序排列的输入信号构成。且滤波器的振幅特性与信号的振幅谱一致。因此,对信号的匹配滤波相当于对信号进行自相关运算。配滤波器是一种非常重要的滤波器,广泛应用与通信、雷达等系统中。从上面的理论推导可以看到,当输出信噪比为最大值的时候,滤波器的传递函数与输入信号的频谱函数满足特定的关系,式2.10就反映了这个关系。满足这种关系的线性滤波器,称之为匹配滤波…

    2022年4月18日
  • linux apache2配置_apache2.4安装教程

    linux apache2配置_apache2.4安装教程一、安装:ubuntu及debian下的apahce有点特别,如果使用apt-get方式安装(apt-getinstallapache2)则安装目录默认在/etc/apache2默认log在/var/log/apache2/(这个鸟地方让我找了好久)二、配置文件说明/etc/apache2/apache2.conf此为apache2的主配置文件具体可

    2022年9月18日
  • 提问的艺术(转帖)

    提问的艺术(转帖) 一、为什么要探讨提问的艺术呢?首先我们要搞清楚什么是问题,为什么要提问,为什么要强调提问的艺术?所谓问题指的是,所有造成我们焦虑、争议的、不能自我答复和解决的一些思考和事情,而且在当时并没有适当答案可以解决。在这个网络时代,没有人是全能的,谁都会在必要的时候为了寻求帮助和寻找答案而提问。而所谓艺术,指的是通过某种表现手法,使人产生喜爱感觉。谁都需要自己的提问,可以在最短、最快

    2022年6月23日
  • 频谱分析仪原理学习

    频谱分析仪原理学习 虽是电子专业出身,但在学生期间用频谱仪的次数比较少,连使用都不顺畅更加不会想到去研究它的原理。但现在的工作主要就是检测接收机,每天和频谱仪接收机各种设备打交道,有必要也很乐意的研究下各个设备的工作原理。讲解频谱仪原理的书籍有很多,读的第一本是师傅给我的安捷伦的《频谱分析原理》接着又自己看了《R&S的频谱分析原理》,相较于安捷伦R&S 更加注重从理论分析,个人…

    2022年8月11日

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号