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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 大数运算C语言实现

    大数运算C语言实现大数乘法利用字符数组进行大数乘法的位运算#include<stdio.h>#include<math.h>#include<string.h>voidprint_cheng(chars1[],chars2[]);voidmain(){chars1[1000],s2[1000];while(scanf(“%s%s”,s1,s2))pr…

    2022年10月7日
    3
  • esxi安装ghost win7_【教程】硬盘下Ghost 系统安装教程

    esxi安装ghost win7_【教程】硬盘下Ghost 系统安装教程使用本方法可在没有光驱、光盘、启动U盘等任何系统安装设备的情况下安装Ghost版XP、Win7、Win8/8.1、Win1032位或64位系统!(原版系统不适用)操作步骤:注意:本安装方法适用于你的电脑能正常启动至桌面,或能启动系统的安全模式,也就是说不管原电脑的系统有任何问题,只要能进桌面,就能重装系统!(EFI+GPT除外)(1)请提前下载GHOST备份还原工具(下称硬盘安装器)与系统GHO…

    2022年6月25日
    157
  • swagger2 注解说明 ( @ApiImplicitParams )

    swagger2 注解说明 ( @ApiImplicitParams )Api 用在请求的类上 表示对类的说明 tags 说明该类的作用 可以在 UI 界面上看到的注解 value 该参数没什么意义 在 UI 界面上也看到 所以不需要配置 ApiOperation 用在请求的方法上 说明方法的用途 作用 value 说明方法的用途 作用 notes 方法的备注说明 ApiImplicitP 用在请求的方

    2025年11月27日
    4
  • 搜狐视频P2P技术揭秘 – 架构篇[通俗易懂]

    搜狐视频P2P技术揭秘 – 架构篇[通俗易懂]本文介绍了搜狐视频P2P的整体架构,服务组成,业务数据等。

    2022年6月19日
    28
  • Linux 下一个 Mysql error 2002 错误解决

    Linux 下一个 Mysql error 2002 错误解决

    2022年1月13日
    86
  • JavaScript和Java的区别[通俗易懂]

    JavaScript和Java的区别[通俗易懂]  虽然JavaScript中有Java,但他们之间的关系就如同印度和印度尼西亚一样——没有什么关系。只是JavaScript中的某些语法和Java类似而已。出身不同  Java和JavaScript是由不同公司发布的不同的产品,Java是由Sun公司发布编程语言,而JavaScript是由Netscape公司发布的脚本语言。变量不同1.变量定义时的区别  定义变量时Java和JavaScript有区别。Java是强类型的语言,它要求每个变量必须在定义时明确指出这个变量是什么类型的;而JavaS

    2022年7月9日
    26

发表回复

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

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