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


相关推荐

  • EC20开发流程[通俗易懂]

    EC20开发流程[通俗易懂]EC20开发流程一、环境二、编译工具的使用三、准备工作四、编写代码五、烧录程序一、环境1、虚拟机ubuntu16.042、ql-ol-sdk对应的编译工具二、编译工具的使用1、将ql-ol-sdk.tar压缩包解压到虚拟机中的路径(最好是U盘挂载后,直接从U盘中解压过去),之后再在终端中ql-ol-sdk/ql-ol-crosstool$sourceql-ol-crosstool-e…

    2022年10月22日
    0
  • 1、java语言概述

    1、java语言概述文章目录Java基础知识图解软件开发软件开发人机交互方式命令行常用的DOS命令常用快捷键java语言java版本历史迭代Java技术体系平台Java在各领域的应用Java语言运行机制及运行过程Java语言的特点跨平台性Java两种核心机制核心机制—Java虚拟机核心机制—垃圾回收Java语言的环境搭建什么是JDK,JRE下载并安装JDK配置环境变量开发HelloWorld开发HelloWorld注意:注释(Comment)文档注释Java基础知识图解软件开发软件开发软件,即一系列按照特定顺序组织的

    2022年7月7日
    23
  • MyEclipse SVN插件的两种安装方法

    MyEclipse SVN插件的两种安装方法MyEclipse的功能十分强大,MyEclipse这款软件是在Eclipse的基础上加上自己的插件开发而成的企业级集成开发环境,在日常的工作中,主要用于Java、JavaEE以及一些移动应用的开发,同时MyEclipse还支持很多插件,接下来就教大家如何安装SVN插件。  在线安装  1、打开myeclipse,help—》MyEclipseConfiguration

    2022年7月21日
    8
  • 【STM32】HAL库 STM32CubeMX教程六—-定时器中断

    【STM32】HAL库 STM32CubeMX教程六—-定时器中断前言:今天我们来学习定时器,32的定时器有着非常丰富的功能,输入捕获/输出比较,PWM,中断等等。是我们学习STM32最频繁使用到的外设之一,所以一定要掌握好,这节我们讲解定时器中断,本系列教程将对应外设原理,HAL库与STM32CubeMX结合在一起讲解,使您可以更快速的学会各个模块的使用所用工具:1、芯片:STM32F407ZET6/STM32F103ZET62、ST…

    2022年5月27日
    98
  • 什么是互质_数组转集合list

    什么是互质_数组转集合list给定 n 个正整数,将它们分组,使得每组中任意两个数互质。至少要分成多少个组?输入格式第一行是一个正整数 n。第二行是 n 个不大于10000的正整数。输出格式一个正整数,即最少需要的组数。数据范围1≤n≤10输入样例:614 20 33 117 143 175输出样例:3#include<bits/stdc++.h>using namespace std;const int N = 1e2 + 10;int a[N],g[N][N];int n;int

    2022年8月9日
    5
  • activity和task_startactivity无效

    activity和task_startactivity无效我现在需要在点击listview的某个item的时候启动一个activity,因为我的listview不在activity中,所以为了简便我直接用context来调用activity,如下:Intentintent=newIntent(view.getContext(),BlogDetail.class);intent.putExtra(“blog_id”,blog.getId());…

    2022年10月6日
    0

发表回复

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

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