java – Couchbase:net.spy.memcached.internal.CheckedOperationTimeoutException
作者:互联网
我正在使用特定于应用程序的json对象加载本地Couchbase实例.
相关代码是:
CouchbaseClient getCouchbaseClient()
{
List<URI> uris = new LinkedList<URI>();
uris.add(URI.create("http://localhost:8091/pools"));
CouchbaseConnectionFactoryBuilder cfb = new CouchbaseConnectionFactoryBuilder();
cfb.setFailureMode(FailureMode.Retry);
cfb.setMaxReconnectDelay(1500); // to enqueue an operation
cfb.setOpTimeout(10000); // wait up to 10 seconds for an operation to succeed
cfb.setOpQueueMaxBlockTime(5000); // wait up to 5 seconds when trying to
// enqueue an operation
return new CouchbaseClient(cfb.buildCouchbaseConnection(uris, "my-app-bucket", ""));
}
存储条目的方法(我使用Bulk Load and Exponential Backoff的建议):
void continuosSet(CouchbaseClient cache, String key, int exp, Object value, int tries)
{
OperationFuture<Boolean> result = null;
OperationStatus status = null;
int backoffexp = 0;
do
{
if (backoffexp > tries)
{
throw new RuntimeException(MessageFormat.format("Could not perform a set after {0} tries.", tries));
}
result = cache.set(key, exp, value);
try
{
if (result.get())
{
break;
}
else
{
status = result.getStatus();
LOG.warn(MessageFormat.format("Set failed with status \"{0}\" ... retrying.", status.getMessage()));
if (backoffexp > 0)
{
double backoffMillis = Math.pow(2, backoffexp);
backoffMillis = Math.min(1000, backoffMillis); // 1 sec max
Thread.sleep((int) backoffMillis);
LOG.warn("Backing off, tries so far: " + tries);
}
backoffexp++;
}
}
catch (ExecutionException e)
{
LOG.error("ExecutionException while doing set: " + e.getMessage());
}
catch (InterruptedException e)
{
LOG.error("InterruptedException while doing set: " + e.getMessage());
}
}
while (status != null && status.getMessage() != null && status.getMessage().indexOf("Temporary failure") > -1);
}
当continueosSet方法调用大量对象来存储(单线程)时,例如
CouchbaseClient cache = getCouchbaseClient();
do
{
SerializableData data = queue.poll();
if (data != null)
{
final String key = data.getClass().getSimpleName() + data.getId();
continuosSet(cache, key, 0, gson.toJson(data, data.getClass()), 100);
...
它在result.get()操作中的continuosSet方法内生成CheckedOperationTimeoutException.
Caused by: net.spy.memcached.internal.CheckedOperationTimeoutException: Timed out waiting for operation - failing node: 127.0.0.1/127.0.0.1:11210
at net.spy.memcached.internal.OperationFuture.get(OperationFuture.java:160) ~[spymemcached-2.8.12.jar:2.8.12]
at net.spy.memcached.internal.OperationFuture.get(OperationFuture.java:133) ~[spymemcached-2.8.12.jar:2.8.12]
有人能否阐明如何克服并从这种情况中恢复过来?有关如何在Couchbase的Java客户端中批量加载有一个很好的技术/解决方法吗?我已经在PHP Couchbase客户端上探索了文档Performing a Bulk Set.
解决方法:
我怀疑你可能是在一个没有那么多内存的命令行中生成的JVM中运行它.如果是这种情况,您可能会遇到更长的GC暂停,这可能会导致您提及的超时.
我认为最好的办法是尝试一些事情.首先,将-Xmx参数提升到JVM以使用更多内存.查看超时是否发生或消失.如果是这样,那么我对记忆的怀疑是正确的.
如果这不起作用,请提高setOpTimeout()并查看是否会减少错误或使其消失.
此外,请确保您使用的是最新的客户端.
顺便说一下,我不认为这是直接批量加载相关的.这可能是由于批量加载过程中的大量资源消耗,但看起来常规退避必须正常工作,或者您从未遇到它.
标签:java,caching,nosql,couchbase,spymemcached 来源: https://codeday.me/bug/20190625/1283915.html