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


相关推荐

  • touchstart和click 自动区分

    touchstart和click 自动区分varclickEvent=(function(){if(‘ontouchstart’indocument.documentElement===true)return’touchstart’;elsereturn’click’;})();转载于:https://www.cnblogs.com/gaidalou/p/9927885.html

    2022年6月19日
    28
  • cas jwt 单点登录

    cas jwt 单点登录单点登录是我比较喜欢的一个技术解决方案,一方面他能够提高产品使用的便利性,另一方面他分离了各个应用都需要的登录服务,对性能以及工作量都有好处。自从上次研究过JWT如何应用于会话管理,加之以前的项目中也一直在使用CAS这个比较流行的单点登录框架,所以就一直在琢磨如何能够把JWT跟单点登录结合起来一起使用,尽量能把两种技术的优势都集成到项目中来。本文介绍我从CAS思考得出的SSO的实现方案。**前…

    2022年5月21日
    43
  • Xlsx结合File-Saver实现前端页面表格导出Excel为文件

    Xlsx结合File-Saver实现前端页面表格导出Excel为文件系列文章目录提示:这里可以添加系列文章的所有文章的目录,目录需要自己手动添加例如:第一章Python机器学习入门之pandas的使用提示:写完文章后,目录可以自动生成,如何生成可参考右边的帮助文档文章目录系列文章目录前言一、pandas是什么?二、使用步骤1.引入库2.读入数据总结前言提示:这里可以添加本文要记录的大概内容:例如:随着人工智能的不断发展,机器学习这门技术也越来越重要,很多人都开启了学习机器学习,本文就介绍了机器学习的基础内容。提示:以下是本篇文章正文内容,下面案例

    2022年6月28日
    31
  • 【Spring Boot 20,孙鑫Java视频教程百度网盘

    【Spring Boot 20,孙鑫Java视频教程百度网盘=============================(一)引入依赖<?xmlversion=”1.0″encoding=”UTF-8″?><projectxmlns=”http://maven.apache.org/POM/4.0.0″xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”xsi:schemaLocation=”http://maven.apache.or

    2022年5月17日
    50
  • FilterDispatcher处理流程「建议收藏」

    FilterDispatcher处理流程「建议收藏」org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter前身是:org.apache.struts2.dispatcher.FilterDispatcher请求被web.xml中定义的过滤器拦截。3层过滤器处理:ActionContextCleanUp,其他过滤器(OtherFilters,SiteM…

    2022年8月16日
    8
  • 如何写软件项目技术标

    如何写软件项目技术标技术标作为一个初期评价软件供应商的重要标准之一,需要覆盖多方面的考虑因素,从需求的理解,到系统的设计,到项目的实施与管理,以及项目的验收与后期支持。那么我们如何来编写一个完整的技术标呢?第一,项目概述   项目情况的一个综合介绍,这是一个综述,通过这个综述说明项目的背景

    2022年5月11日
    64

发表回复

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

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