【发布时间】:2021-07-06 21:59:20
【问题描述】:
我正在从 ES5.6 升级到 ES7。过去,我们克隆了 ES5 存储库并添加了自定义代码以使用指数退避重试。
public void doRetryWithExponentialBackoff(BasicCallback mainAttempt, ExceptionHandlingCallback onFailure) {
int failure = 0;
int maxFailure = 6;
while (true) {
try {
mainAttempt.execute();
return;
} catch (RuntimeException mainException) {
try {
failure += 1;
if (failure <= maxFailure) {
Thread.sleep(((int) Math.pow(2, failure)) * 1000);
} else {
onFailure.execute(mainException);
return;
}
} catch (InterruptedException interruptedException) {
throw new RuntimeException(interruptedException);
}
}
}
}
然而,我们不想再做一次,但同时我在 ES7 中找不到任何这样的功能。您对实施重试政策有何建议?
我还利用Pumba 进行混沌测试,而与应用程序 ES 相关的测试却惨遭失败。例如,如果我终止 ES 容器,或者在响应时间中添加延迟,那么应用程序就会崩溃。通过指数退避,我也打算处理这些情况。
编辑:我正在使用 spring 数据框架来访问 ES7
【问题讨论】:
标签: elasticsearch retry-logic exponential-backoff