Here is a problem that has been troubling me for a few days now. It pertains to both N1QL and the Java sdk, so I apologize if it has more relevance in the other location. I will just provide all the details I know to provide in both to be as certain as possible.
-I am able to run queries in the tutorial and with curl, however, they timeout when done with the sdk.
-I call with (in the 2.1.0-dp sdk) :
Query theQuery = Query.simple(query);
QueryResult queryResult = bucket.query(theQuery);
-The âqueryâ parameter is a String and I have tried the values of âCREATE PRIMARY INDEX ON defaultâ and âSELECT * FROM defaultâ
-This problem developed when moving from dp3 to dp4.
-It occurs with both the 2.0 and the developer preview of the 2.1 java sdk.
-The timeout exception is thrown in blockForSingle of Blocking.java.
-It is the âreturnExceptionâ caught at âonNextâ and is a âjava.util.concurrent.TimeoutExceptionâ, and the cause stated is ârx.exceptions.OnErrorThrowables$OnNextValue: OnError while emitting onNext value: com.couchbase.client.java.query.DefaultAsyncQueryResult.classâ
With the âSELECT * FROM defaultâ query the cbq-engine logs "level=âINFOâ _msg=âNumber of entries fetched from the index 9"â
Just wondering if there is something I am doing incorrectly or if there are new developments waiting for the two to work together.
I think loscouwâs example would be easiest. I made the decision to work this into a larger product and much of the logic is broken between methods. He follows similar logic.
This is some of what I do have, though. The place I am querying from is as follows
Jan 21, 2015 4:02:53 PM com.couchbase.client.core.endpoint.AbstractEndpoint$2 operationComplete
WARNING: [null][QueryEndpoint]: Could not connect to endpoint, retrying with delay 4096ms:
java.net.ConnectException: Connection refused: couchbasehost/[ip]:8093
at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
at sun.nio.ch.SocketChannelImpl.finishConnect(Unknown Source)
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(Unknown Source)
I have checked everything, the engine is up and running, no firewall beetween client and server.
I made a wireshark capture and the server can give back a json.
Itâs hard to say, but this is a exception from the JVM which indicates that the remote host refuses the connection. Can you check that the hostname is also properly reachable as the SDK uses it? At this point there is not much the SDK can âdoâ, when the JVM is saying the remote host refuses the connection.
You were right about the query engine being off. I apologize, I rushed that one. After turning it on I still receive the timeout, but itâs hard to find a problem in the logs under âcom.couchbaseâ. The levels are all FINE and FINEST, so I have to adjust my settings to allow for some spam. I do receive the data from the server. I get a series of:
Would you mind sharing the full logs and code? You can also send them over as a private message here (or through some other channel) if you donât want to make them public.
Just a suggestion on your code @somexp: toMap can be a bit expensive since it will make a deep copy of the JsonObject then transform each JsonObject in the tree into a Map, each JsonArray into a List.
If you just want to iterate over each key/value to inject them into a new JSON object, you can use JsonObject.getNames() to get the keysetâŠ
And if thereâs multiple rows, for each row your code will overwrite any previous existing enty in result that has the same key, giving you in the end either the last row content or a mix of last rows⊠is that on purpose?
Concerning both your queries @loscouw and @somexp, Iâve tried similar queries without problem, albeit on the beer-sample bucket. Are you sure your classpath is clean and corresponds to core-io-1.1.0-dp.jar, java-client-2.1.0-dp.jar and rxjava-1.0.4.jar ?
Maybe we can work with a common document space, if you have the possibility to load beer-sample bucket?
Queries Iâve tried are
CREATE PRIMARY INDEX ON `beer-sample` â returns an error saying the index already exists, expected
SELECT * FROM `beer-sample` â 7303 results
SELECT name FROM `beer-sample` LIMIT 100 â 100 results of just beer or brewery names
Code:
public class SomexpLoscouwMain {
public static void main(String[] args) {
CouchbaseEnvironment env = DefaultCouchbaseEnvironment.builder()
.queryEnabled(true)
.build();
Cluster cluster = CouchbaseCluster.create(env, "127.0.0.1");
Bucket bucket = cluster.openBucket("beer-sample","");
//String query = "SELECT * FROM `beer-sample`";
//String query = "CREATE PRIMARY INDEX ON `beer-sample`";
String query = "SELECT name FROM `beer-sample` LIMIT 100";
Query cbquery= Query.simple(query);
QueryResult result = bucket.query(cbquery);
if(result.finalSuccess())
{
Iterator<QueryRow> rows =result.rows();
int rowCount = 0;
while (rows.hasNext())
{
QueryRow row= rows.next();
System.out.println(row.value());
rowCount++;
}
System.err.println("Rows printed: " + rowCount);
}
else {
for (JsonObject error : result.errors()) {
System.err.println(error);
}
}
}
}
I ran it locally, so in a Windows environment this time, with the couchbase server and query engine on the same machine as this program runs.
The results are as follows:
C:\programs\Java\jdk1.7.0_67\bin\java -Didea.launcher.portâŠ
Jan 22, 2015 12:19:44 PM com.couchbase.client.core.CouchbaseCore
INFO: CoreEnvironment: {sslEnabled=false, sslKeystoreFile=ânullâ, sslKeystorePassword=ânullâ, queryEnabled=true, queryPort=8093, bootstrapHttpEnabled=true, bootstrapCarrierEnabled=true, bootstrapHttpDirectPort=8091, bootstrapHttpSslPort=18091, bootstrapCarrierDirectPort=11210, bootstrapCarrierSslPort=11207, ioPoolSize=4, computationPoolSize=4, responseBufferSize=16384, requestBufferSize=16384, kvServiceEndpoints=1, viewServiceEndpoints=1, queryServiceEndpoints=1, ioPool=NioEventLoopGroup, coreScheduler=CoreScheduler, packageNameAndVersion=couchbase-java-client/2.1.0-dp (git: 2.1.0-dp), dcpEnabled=false}
Jan 22, 2015 12:19:45 PM com.couchbase.client.core.node.CouchbaseNode$5 call
INFO: Connected to Node 127.0.0.1
Jan 22, 2015 12:19:45 PM com.couchbase.client.core.config.DefaultConfigurationProvider$6 call
INFO: Opened bucket beer-sample
Exception in thread âmainâ java.lang.RuntimeException: java.util.concurrent.TimeoutException
at com.couchbase.client.java.util.Blocking.blockForSingle(Blocking.java:93)
at com.couchbase.client.java.query.DefaultQueryResult.(DefaultQueryResult.java:53)
at com.couchbase.client.java.CouchbaseBucket$4.call(CouchbaseBucket.java:550)
at com.couchbase.client.java.CouchbaseBucket$4.call(CouchbaseBucket.java:546)
at rx.internal.operators.OperatorMap$1.onNext(OperatorMap.java:55)
at rx.internal.operators.OperatorMerge$MergeSubscriber.handleScalarSynchronousObservableWithoutRequestLimits(OperatorMerge.java:225)
at rx.internal.operators.OperatorMerge$MergeSubscriber.handleScalarSynchronousObservable(OperatorMerge.java:214)
at rx.internal.operators.OperatorMerge$MergeSubscriber.onNext(OperatorMerge.java:149)
at rx.internal.operators.OperatorMerge$MergeSubscriber.onNext(OperatorMerge.java:93)
at rx.internal.operators.OperatorMap$1.onNext(OperatorMap.java:55)
at rx.internal.operators.NotificationLite.accept(NotificationLite.java:150)
at rx.internal.operators.OperatorObserveOn$ObserveOnSubscriber.pollQueue(OperatorObserveOn.java:189)
at rx.internal.operators.OperatorObserveOn$ObserveOnSubscriber.access$000(OperatorObserveOn.java:65)
at rx.internal.operators.OperatorObserveOn$ObserveOnSubscriber$2.call(OperatorObserveOn.java:153)
at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:47)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:178)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:292)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.util.concurrent.TimeoutException
⊠22 more
Caused by: rx.exceptions.OnErrorThrowable$OnNextValue: OnError while emitting onNext value: com.couchbase.client.java.query.DefaultAsyncQueryResult.class
at rx.exceptions.OnErrorThrowable.addValueAsLastCause(OnErrorThrowable.java:98)
at rx.internal.operators.OperatorMap$1.onNext(OperatorMap.java:58)
⊠17 more
ok good news, using the same setup (running it all locally but on a windows machine) I was able to reproduce the problem⊠seems there is a race condition when there is a little latency. Will try and commit a fix asap, to be part of a dp2 for Java SDK 2.1.0âŠ
tracked in Loading... and fixed on master! @somexp@loscouw if you have the possibility of building from master and validating the fix works for you, please do
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)