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


相关推荐

  • Idea激活码最新教程2022.3.2版本,永久有效激活码,亲测可用,记得收藏

    Idea激活码最新教程2022.3.2版本,永久有效激活码,亲测可用,记得收藏Idea 激活码教程永久有效 2022 3 2 激活码教程 Windows 版永久激活 持续更新 Idea 激活码 2022 3 2 成功激活

    2025年5月26日
    8
  • jvm jstat 命令使用

    jvm jstat 命令使用jstat的用法用以判断JVM是否存在内存问题呢?如何判断JVM垃圾回收是否正常?一般的top指令基本上满足不了这样的需求,因为它主要监控的是总体的系统资源,很难定位到java应用程序。Jstat是JDK自带的一个轻量级小工具。全称“JavaVirtualMachinestatisticsmonitoringtool”,它位于java的bin目录下,主要利用JVM内建

    2025年10月30日
    5
  • Android Studio入门级教程(详细)【小白必看】[通俗易懂]

    Android Studio入门级教程(详细)【小白必看】[通俗易懂]AndroidStudio如何使用之前的文章已经讲解了AndroidStudio的安装和配置过程请参考:本文主要讲解一下AndroidStudio使用方法步骤:1.建立项目首先点击new——newproject新建项目选择想要创建的Android的模板,建议选择emptyactivity(空模板),然后nextName:给你的项目起一个名字API…

    2022年5月29日
    49
  • Windows ping TCP端口工具之tcping「建议收藏」

    Windows ping TCP端口工具之tcping「建议收藏」ping这个小工具大家都非常熟悉,但是他不能ping端口,当我们需要知道目的地址的某端口是否开放时,这时需要用到这个tcping小工具了,Windows没有自带这个小工具,需要自己下载下来,放到指定目录里面。下载地址:点击打开链接X64下载链接放到C:\Windows\System32这个文件夹下现在在测试一下…

    2022年6月23日
    152
  • csv文件格式说明[通俗易懂]

    csv文件格式说明[通俗易懂]csv文件应用很广泛,历史也很悠久。有很多种类型的csv格式,常用的是rfc4180定义的格式。csv文件包含一行或多行记录,每行记录中包含一个或多个字段。记录与记录之间使用换行符分隔,最后一个记

    2022年8月6日
    8
  • kfold交叉验证k越大_内部交叉验证

    kfold交叉验证k越大_内部交叉验证交叉验证的原理放在后面,先看函数。设X是一个9*3的矩阵,即9个样本,3个特征,y是一个9维列向量,即9个标签。现在我要进行3折交叉验证。执行kFold=KFold(n_splits=3):其中KFold是一个类,n_split=3表示,当执行KFold的split函数后,数据集被分成三份,两份训练集和一份验证集。执行index=kFold.split(X=X):index是一个生成器…

    2026年2月2日
    3

发表回复

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

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