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)
上一篇 2022年6月30日 上午7:00
下一篇 2022年6月30日 上午7:00


相关推荐

  • c#二进制文件数据转换base64字符串文本代码

    c#二进制文件数据转换base64字符串文本代码usingSystem;usingSystem.Text;namespaceConsoleTest{internalclassProgram{privatestaticvoidMain(string[]args){stringaaa=…

    2025年5月24日
    3
  • CollectGarbage函数–JS清理垃圾,内存释放

    CollectGarbage函数–JS清理垃圾,内存释放首先看一个内存释放的实例 nbsp lt SCRIPTLANGUA JavaScript gt lt strTest 1 for vari 0 i lt 25 i strTest strTest alert strTest deletestrTes CollectGarba gt

    2026年3月20日
    2
  • 51单片机LED点阵实验(74HC595)

    51单片机LED点阵实验(74HC595)实验目的 用 8 8 的 LED 点阵显示一颗爱心 实验仪器 普中开发板 非广告 实验背景 出于一些原因 最近在看 Arduino 但仍觉得 51 好玩 遂 一边看 Arduino 一边整理 51 8 8 的 LED 点阵电路如图一所示 有两种方式 单片机上集成的电路方式为第二种 其中 行由 P0 口控制 列由 D7 D0 HC595 芯片控制 见下方 控制 图一首先考虑 如何先点亮一个灯 eg 让

    2026年3月17日
    1
  • 数据挖掘的方法有哪些?

    数据挖掘的方法有哪些?数据挖掘的方法有哪些?01数据挖掘方法分类介绍1.预测性——有监督学习2.描述性——无监督学习02数据挖掘方法论1.CRISP-DM方法论2.SEMMA方法论03数据挖掘建模框架的3个原则1.以成本-收益分析为单一分析框架2.以分析主体和客体为视角3.构建全模型生命周期工作模板数据挖掘是一个多学科交叉的产物,涉及统计学、数据库、机器学习、人工智能及模式识别等多种学科,如图1-4所示。01数据挖掘方法分类介绍数据挖掘方法按照来源进行分类显得过于庞杂,而且不便于理解和记忆。按照其目

    2022年6月28日
    22
  • 哥尼斯堡七桥问题解法_酒分之一实验室

    哥尼斯堡七桥问题解法_酒分之一实验室 JOJ1200Jugs题目链接:http://acm.jlu.edu.cn/joj/showproblem.php?pid=1200题目的意思是,有两个容器,容量分别为ca和cb,cacb,初始时两个容器都是空的,水无限量供应,问如何用这两个容器量出n单位的水放在容量为cb的那个容器中?这个题目给出的数

    2022年10月7日
    3
  • 史上最全的Android面试题集锦

    史上最全的Android面试题集锦Android基本知识点1、常规知识点1、Android类加载器在Android开发中,不管是插件化还是组件化,都是基于Android系统的类加载器ClassLoader来设计的。只不过Android平台上虚拟机运行的是Dex字节码,一种对class文件优化的产物,传统Class文件是一个Java源码文件会生成一个.class文件,而Android是把所有Class文件进行合并、优化,然后…

    2022年5月11日
    43

发表回复

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

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