N1QL queries timing out when run in java sdk

I am having a similar issue on 2.1.0.

java.util.concurrent.TimeoutException: null
at com.couchbase.client.java.util.Blocking.blockForSingle(Blocking.java:93)
at com.couchbase.client.java.CouchbaseBucket.query(CouchbaseBucket.java:547)
at com.couchbase.client.java.CouchbaseBucket.query(CouchbaseBucket.java:490)
at com.apple.ist.salesplatform.dao.CouchbaseService.search(CouchbaseService.java:126)
at com.apple.ist.salesplatform.dao.EntityDao.search(EntityDao.java:88)

public int search(final String q) {
System.setProperty(“com.couchbase.queryEnabled”, “true”);
System.setProperty(“com.couchbase.client.queryEnabled”, “true”);
final QueryResult queryResult = bucket.query(Query.simple(q));
return queryResult.allRows().size();
}

I am doing a performance testing for N1ql as a query solution. It works great in console as N1ql engine. I was able to make it run once without any problems with java sdk. By mistake, i ran a query which would return millions of records (select * from default) , I killed the server . Ever since, I have tried everything, this Blocking.blockForSingle doesn’t go away.

System details : Couchbase Server 3.0.2, MAC OS Yosemite, JDK 7 (and JDK 6)

IS there a workaround to it for now?
Can i directly query N1QL engine via REST service (without using java sdk). I need rest endpoint to do performance testing through Jmeter.

@msingh yes you can query N1QL engine through REST (that’s actually what the SDK is doing). See the language reference. 2.1.1 (by building a jar manually from master branch) should be in a better shape as well concerning the blocking problem…

Hi, I am facing this problem when I give System.setProperty("com.couchbase.queryEnabled", "true"); or through .queryEnabled(true);. How do I ensure that my N1QL engine is up and running?

Mar 01, 2016 10:08:54 PM com.couchbase.client.core.endpoint.AbstractEndpoint$2 operationComplete
WARNING: [null][QueryEndpoint]: Could not connect to endpoint, retrying with delay 1024 MILLISECONDS:
java.net.ConnectException: Connection refused: remotedb1-8415.slc01.xxx.xxx.com/10.65.243.21:8093
        at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
        at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:717)
        at com.couchbase.client.deps.io.netty.channel.socket.nio.NioSocketChannel.doFinishConnect(NioSocketChannel.java:208)
        at com.couchbase.client.deps.io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.finishConnect(AbstractNioChannel.java:281)
        at com.couchbase.client.deps.io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:528)
        at com.couchbase.client.deps.io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:468)
        at com.couchbase.client.deps.io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:382)
        at com.couchbase.client.deps.io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:354)
        at com.couchbase.client.deps.io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:116)
        at com.couchbase.client.deps.io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:137) at java.lang.Thread.run(Thread.java:745)

First, don’t use queryEnabled manually, just use a recent version and it will automatically discover the service. This means it will then also check on which nodes N1QL is active on the cluster and don’t try to connect to every one. This environment setting was there only during N1QL preview to manually enable it and is now deprecated (will be removed in next minor version).

That issue got solved. But another one popped up.

Exception in thread "main" com.couchbase.client.core.ServiceNotAvailableException: The Query service is not enabled or no node in the cluster supports it.
        at com.couchbase.client.core.RequestHandler.checkFeaturesForRequest(RequestHandler.java:226)
        at com.couchbase.client.core.RequestHandler.onEvent(RequestHandler.java:181)
        at com.couchbase.client.core.RequestHandler.onEvent(RequestHandler.java:73)
        at com.couchbase.client.deps.com.lmax.disruptor.BatchEventProcessor.run(BatchEventProcessor.java:128)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at com.couchbase.client.deps.io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:137)
        at java.lang.Thread.run(Thread.java:745)

This is why I asked how to check if N1QL is engine running? How should I enable it?

When you add a node to the cluster you can choose to enable the N1QL service (on EE), on CE it will always be enabled when you add a new node. Keep in mind this only works on 4.0 or later since this is where N1QL got added as a feature.

Couchbase 4.0? I am using Version: 2.2.0 community edition (build-837). I cannot use N1QL’s features in my Java SDK now?

No, 2.2.0 doesn’t have support for N1QL on the server side. You need to upgrade to 4.0 or 4.1 to use it.

Yeah okay. Thanks. Will update the version.

I updated it. Still when I click About in the webUI, it is showing the same version number.

It shows 2.2 but N1QL works?

No. N1QL is not working. I just downloaded the 4.5.0-DP version from the website and installed it. Still when I click the About in the webUI, it is showing Version: 2.2.0 community edition (build-837). I don’t know if I am seeing something wrong!

On which OS are you on? Looks like the upgrade didn’t work. You need to uninstall the old server and install the new one in a 1-node scenario.

Running on Windows 7. It was mentioned in the installer that it would automatically remove the older version, take back up and install the new version.

Okay, I have very limited experience with the windows installer. Can you try removing the server completely manually and then install the new version?

If that is the only possible solution, then I would do it after the office hours. All these things to read 25M documents from the DB. Only if I could read the documents as batches, I wouldn’t need to use N1QL at all.

I’m facing the same timeout issue as well on couchbase server 4.1; java-client 2.3.1; core-io 1.3.1; So far in my testing the first few queries work fine and then after about 20 minutes I start getting all timeouts. This started happening after going from java-client 2.2.2 to 2.3.1.

here is my logs as you can see the issue is happening in the same method others have mentioned blockForSingle is there any suggestions on how to avoid what sounds like a race condition?

java.lang.Thread.run(Thread.java:745)
org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:533)
org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:598)
org.eclipse.jetty.server.nio.BlockingChannelConnector$BlockingChannelEndPoint.run(BlockingChannelConnector.java:293)
org.eclipse.jetty.server.BlockingHttpConnection.handle(BlockingHttpConnection.java:50)
org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:218)
org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:582)
org.eclipse.jetty.server.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:919)
org.eclipse.jetty.server.HttpConnection.handleRequest(HttpConnection.java:441)
org.eclipse.jetty.server.Server.handle(Server.java:349)
org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:110)
org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:149)
org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:117)
org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:875)
org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:186)
org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:409)
org.ops4j.pax.web.service.jetty.internal.HttpServiceContext.doHandle(HttpServiceContext.java:117)
org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:941)
org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:227)
org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:483)
org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:119)
org.ops4j.pax.web.service.jetty.internal.HttpServiceServletHandler.doHandle(HttpServiceServletHandler.java:70)
org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:480)
org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:547)
org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:201)
javax.servlet.http.HttpServlet.service(HttpServlet.java:693)
org.apache.cxf.transport.servlet.AbstractHTTPServlet.doGet(AbstractHTTPServlet.java:150)
org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:225)
org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringServlet.java:130)
org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:194)
org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:214)
org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:237)
org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)
org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:262)
org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(ServiceInvokerInterceptor.java:94)
org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerInterceptor.java:58)
org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:89)
org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:168)
org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:96)
org.apache.cxf.service.invoker.AbstractInvoker.performInvocation(AbstractInvoker.java:180)
java.lang.reflect.Method.invoke(Method.java:498)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
sun.reflect.GeneratedMethodAccessor898.invoke(Unknown Source)
xxx.xxx.xxx.mymethod(myclass.java:106)
xxxx.xxx.xxx.mymethod(myclass.java:38)
com.sun.proxy.$Proxy169.mymethod(Unknown Source)
org.apache.aries.proxy.impl.ProxyHandler.invoke(ProxyHandler.java:78)
org.apache.aries.proxy.impl.DefaultWrapper.invoke(DefaultWrapper.java:31)
org.apache.aries.proxy.impl.ProxyHandler$1.invoke(ProxyHandler.java:50)
java.lang.reflect.Method.invoke(Method.java:498)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
sun.reflect.GeneratedMethodAccessor899.invoke(Unknown Source)
xxxx.xx.xxx.mymethod(myclass.java:53)
xxx.xxx.xxx.mymethod(myclass.java:72)
xxx.xx.xxx.mymethod(myclass.java:91)
com.couchbase.client.java.CouchbaseBucket.query(CouchbaseBucket.java:577)
com.couchbase.client.java.CouchbaseBucket.query(CouchbaseBucket.java:652)
com.couchbase.client.java.util.Blocking.blockForSingle(Blocking.java:70)
java.util.concurrent.CountDownLatch.await(CountDownLatch.java:277)
java.util.concurrent.locks.AbstractQueuedSynchronizer.tryAcquireSharedNanos(AbstractQueuedSynchronizer.java:1328)
java.util.concurrent.locks.AbstractQueuedSynchronizer.doAcquireSharedNanos(AbstractQueuedSynchronizer.java:1037)
java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:215)
sun.misc.Unsafe.park(Native Method)

i am facing this same issue. Did you get any solution for this?

Hello @parasdiwan,

Yes i resolved this one I downgraded to version 2.2.7 of the SDK and this resolved it for me. Please let me know if this works for you. I left more details in the other message thread which you may find of interest.