java backoff_Java BackOff类代码示例
大家好,又见面了,我是你们的朋友全栈君。
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.cn/147509.html原文链接:https://javaforall.cn
相关文章
- java代码大全及详解_Java练级攻略[通俗易懂]
- java一个字符几个字节_Java 语言中一个字符占几个字节?
- java递归和迭代_Java中的迭代与递归
- java 取当前时间年月日_Java获取当前时间年月日的方法[通俗易懂]
- 快递鸟Java SDK的功能介绍、API介绍和示例代码
- 【Java AWT 图形界面编程】Dialog 对话框 ( 简介 | 模式对话框 | 非模式对话框 | Dialog 构造函数 | Dialog 代码示例 | 向 Dialog 对话框添加布局组件 )
- 【Java AWT 图形界面编程】FileDialog 对话框 ( 打开文件 | 保存文件 | 构造函数 | 获取文件路径 | 获取文件名称 | 代码示例 )
- 【Java AWT 图形界面编程】事件处理机制 ② ( Frame 窗口事件监听器 WindowListener | 代码示例 )
- 【创作赢红包】【Java AWT 图形界面编程】菜单组件 ② ( 菜单组件示例要点说明 | 菜单组件示例代码 )
- HDFS的Java客户端操作代码(查看HDFS下所有的文件或目录)详解大数据
- java读取properties文件代码详解编程语言
- java操作oracle常用的示例代码详解编程语言
- Java中的定时器Timer使用示例代码详解编程语言
- Java学习笔记之十七Java中普通代码块,构造代码块,静态代码块区别及代码示例分析详解编程语言
- Java与Oracle联手构建数据库新世界(java和oracle)
- Linux下部署Java项目实践(linux部署java项目)
- 互操作Java与Redis缓存互操作实践(redis缓存与java)
- 如何在Linux系统下成功安装Java?(linux下安装java)
- java用户名密码验证示例代码分享