[英]Couchbase concurrent timeout exception : Java SDK
I am working with java in a maven project. 我在maven项目中使用java。 I was using couchbase 2.3.1 but in trying to resolve this issue I rolled back to 2.2.8 to no avail. 我正在使用couchbase 2.3.1,但在尝试解决此问题时,我回滚到2.2.8无济于事。
The issue I get is that while I do get date through to my couchbase cluster I am seeing alot of this: 我得到的问题是,当我确实到达我的couchbase集群时,我看到了很多这样的事情:
java.lang.RuntimeException: java.util.concurrent.TimeoutException
at com.couchbase.client.java.util.Blocking.blockForSingle(Blocking.java:75)
at com.couchbase.client.java.CouchbaseBucket.upsert(CouchbaseBucket.java:359)
at com.couchbase.client.java.CouchbaseBucket.upsert(CouchbaseBucket.java:354)
Below are the settings for my couchbase environment: 以下是我的couchbase环境的设置:
CouchbaseEnvironment: {sslEnabled=false, sslKeystoreFile='null', sslKeystorePassword='null', queryEnabled=false, queryPort=8093, bootstrapHttpEnabled=true, bootstrapCarrierEnabled=true, bootstrapHttpDirectPort=8091, bootstrapHttpSslPort=18091, bootstrapCarrierDirectPort=11210, bootstrapCarrierSslPort=11207, ioPoolSize=24, computationPoolSize=24, responseBufferSize=16384, requestBufferSize=16384, kvServiceEndpoints=1, viewServiceEndpoints=1, queryServiceEndpoints=1, searchServiceEndpoints=1, ioPool=NioEventLoopGroup, coreScheduler=CoreScheduler, eventBus=DefaultEventBus, packageNameAndVersion=couchbase-java-client/2.2.8 (git: 2.2.8, core: 1.2.9), dcpEnabled=false, retryStrategy=BestEffort, maxRequestLifetime=75000, retryDelay=ExponentialDelay{growBy 1.0 MICROSECONDS, powers of 2; lower=100, upper=100000}, reconnectDelay=ExponentialDelay{growBy 1.0 MILLISECONDS, powers of 2; lower=32, upper=4096}, observeIntervalDelay=ExponentialDelay{growBy 1.0 MICROSECONDS, powers of 2; lower=10, upper=100000}, keepAliveInterval=30000, autoreleaseAfter=2000, bufferPoolingEnabled=true, tcpNodelayEnabled=true, mutationTokensEnabled=false, socketConnectTimeout=1000, dcpConnectionBufferSize=20971520, dcpConnectionBufferAckThreshold=0.2, dcpConnectionName=dcp/core-io, callbacksOnIoPool=false, queryTimeout=75000, viewTimeout=75000, kvTimeout=2500, connectTimeout=5000, disconnectTimeout=25000, dnsSrvEnabled=false}
Im not really too sure what to look at here. 我真的不太清楚这里要看什么。 As far as I can tell there should be a decent enough connection between the server where the app is running and the couchbase cluster. 据我所知,应用程序运行的服务器和couchbase集群之间应该有足够的连接。 Any help or direction on this would be helpful. 任何帮助或方向都会有所帮助。 Here is a snippet from where the error is being thrown. 这是一个抛出错误的片段。
LockableItem<InnerVertex> lv = this.getInnerVertex(id);
lv.lock();
try {
String content;
try {
content = mapper.writeValueAsString(lv.item);
} catch (JsonProcessingException e) {
LOG.warning(e.getMessage());
return;
}
RawJsonDocument d = RawJsonDocument.create(VertexId.toKey(id), content);
bucket.upsert(d);
} finally {
lv.unlock();
}
I was searching for the answer. 我在寻找答案。 I got there are many solutions all are talking about exception. 我得到了很多解决方案都在讨论异常。 I also checked the jar code, it is called that it is timeout exception. 我还检查了jar代码,它被称为超时异常。
The error occured from the following section of couchbase: https://github.com/couchbase/couchbase-java-client/blob/master/src/main/java/com/couchbase/client/java/util/Blocking.java#L71 从couchbase的以下部分发生错误: https : //github.com/couchbase/couchbase-java-client/blob/master/src/main/java/com/couchbase/client/java/util/Blocking.java# L71
public static <T> T blockForSingle(final Observable<? extends T> observable, final long timeout,
final TimeUnit tu) {
final CountDownLatch latch = new CountDownLatch(1);
TrackingSubscriber<T> subscriber = new TrackingSubscriber<T>(latch);
observable.subscribe(subscriber);
try {
if (!latch.await(timeout, tu)) { // From here, this error occurs.
throw new RuntimeException(new TimeoutException());
}
}
If the timeout kicks in, a TimeoutException nested in a RuntimeException is thrown to be fully compatible with the Observable.timeout(long, TimeUnit) behavior. 如果超时启动,则抛出嵌套在RuntimeException中的TimeoutException,以与Observable.timeout(long,TimeUnit)行为完全兼容。
http://docs.couchbase.com/sdk-api/couchbase-java-client-2.2.0/com/couchbase/client/java/util/Blocking.html http://docs.couchbase.com/sdk-api/couchbase-java-client-2.2.0/com/couchbase/client/java/util/Blocking.html
Your couchbase environment connectionTimeout is 5000ms
or 5sec, which is the default value of connection timeout. 您的couchbase环境connectionTimeout是5000ms
毫秒或5秒,这是连接超时的默认值。
You need to increase this value to 10000ms or greater
. 您需要将此值增加到10000ms or greater
。 Your problem will be solved. 你的问题将得到解决。
//this tunes the SDK (to customize connection timeout)
CouchbaseEnvironment env = DefaultCouchbaseEnvironment.builder()
.connectTimeout(10000) //10000ms = 10s, default is 5s
.build();
Simonbasle has given a full solution in this tutorial: Simonbasle在本教程中提供了完整的解决方案:
From the short log, it looks like the SDK is able to connect to the node, but takes a little much time to open the bucket. 在短日志中,看起来SDK能够连接到节点,但需要花费一些时间来打开存储桶。 How good is the network link between the two machines? 两台机器之间的网络连接有多好? Is this a VM/cloud machine? 这是VM /云计算机吗?
What you can try to do is increase the connect timeout: 您可以尝试做的是增加连接超时:
public class NoSQLTest {
public static void main(String[] args) {
try {
//this tunes the SDK (to customize connection timeout)
CouchbaseEnvironment env = DefaultCouchbaseEnvironment.builder()
.connectTimeout(10000) //10000ms = 10s, default is 5s
.build();
System.out.println("Create connection");
//use the env during cluster creation to apply
Cluster cluster = CouchbaseCluster.create(env, "10.115.224.94");
System.out.println("Try to openBucket");
Bucket bucket = cluster.openBucket("beer-sample"); //you can also force a greater timeout here (cluster.openBucket("beer-sample", 10, TimeUnit.SECONDS))
System.out.println("disconnect");
cluster.disconnect();
}
catch (Exception e) {
e.printStackTrace();
}
}
}
As a side note, you should always reuse the CouchbaseEnvironment, CouchbaseCluster and Bucket instances once created (usually by making them public static somewhere, or a Spring singleton, etc...). 作为旁注,您应该始终重复使用CouchbaseEnvironment,CouchbaseCluster和Bucket实例(通常通过将它们设置为某个地方的公共静态,或Spring单例等等)。 These are thread safe and should be shared (and they are expensive to create anyway). 这些是线程安全的,应该共享(并且无论如何它们都很昂贵)。
Thanks for the question and and @SkyWalker's Answer. 感谢您提出的问题以及@ SkyWalker的答案。 They helped when I encountered this annoying timeout. 当我遇到这个烦人的超时时,他们帮了忙。
For Spring Data Couchbase 2, adding the following to application.properties solved it 对于Spring Data Couchbase 2,将以下内容添加到application.properties解决了它
spring.couchbase.env.timeouts.connect=20000
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.