Couchbase indexing with Apache Storm



I am planning to use Couchbase with Apache Storm. Since Storm inserts data into Couchbase heavily(i.e. 2~3k updates or inserts per second), view’s indexing also keeps updated and restarted endlessly with the default auto-indexing settings. So querying with stale=false is always stopped by the runtime exception saying “failed to access the view”, and it seems like querying with stale=false is impossible in this case. Of course, with stale=ok, I can get a result but cannot make sure if the result includes the data I want to map/reduce or not since the indexing is not done yet.

So is there a way to get a correct result that is the same as the result when indexing is 100% in this case? Or a way to know what data was processed with stale=ok up to? For your information, Couchbase version is 2.2.0 community edition, and Java SDK version is 1.4.1

Thanks in advance!


While it may be too slow with stale=false to suit your needs, it shouldn’t give you “failed to access view”. That seems unusual. Do you have any errors in the log at the cluster?

The best way perhaps is stale=update_after or to have the auto-index do your update and just cycle the query times.

Also, note that 2.2.0 is pretty dated at this stage and 2.5.1 would be better, if you can upgrade. 3.0 (currently under development) is expected to have some improvements here as well. Stay tuned for that in the near future.


Thanks for your answer! I checked the log of my cluster again but there were no relevant errors. Here is part of the stack trace I had from Java SDK when the exception occured so would you please have a look at this and let me know why this happened?

java.lang.RuntimeException: Failed to access the view at com.couchbase.client.CouchbaseClient.query( ... Caused by: java.util.concurrent.ExecutionException: OperationException: GENERAL at com.couchbase.client.internal.HttpFuture.waitForAndCheckOperation( at com.couchbase.client.internal.HttpFuture.get( at com.couchbase.client.internal.HttpFuture.get( at com.couchbase.client.CouchbaseClient.query( ... 28 more Caused by: OperationException: GENERAL at com.couchbase.client.protocol.views.ViewOperationImpl.handleResponse( at com.couchbase.client.http.HttpResponseCallback.completed( at com.couchbase.client.http.HttpResponseCallback.completed( at org.apache.http.concurrent.BasicFuture.completed( at org.apache.http.nio.protocol.HttpAsyncRequester$RequestExecutionCallback.completed( at org.apache.http.concurrent.BasicFuture.completed( at org.apache.http.nio.protocol.BasicAsyncClientExchangeHandler.responseCompleted( at org.apache.http.nio.protocol.HttpAsyncRequestExecutor.processResponse( at org.apache.http.nio.protocol.HttpAsyncRequestExecutor.inputReady( at org.apache.http.impl.nio.DefaultNHttpClientConnection.consumeInput( at org.apache.http.impl.nio.DefaultHttpClientIODispatch.onInputReady( at org.apache.http.impl.nio.DefaultHttpClientIODispatch.onInputReady( at org.apache.http.impl.nio.reactor.AbstractIODispatch.inputReady( at org.apache.http.impl.nio.reactor.BaseIOReactor.readable( at org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvent( at org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvents( at org.apache.http.impl.nio.reactor.AbstractIOReactor.execute( at org.apache.http.impl.nio.reactor.BaseIOReactor.execute( at org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor$ at


Can you share the relevant codeparts? Also, it looks like the server is returning an error here. Were you doing rebalance/failover or the kind during the view query?


Thanks for your answer! I wasn’t doing nothing other than the querying job. Here is part of my code slightly edited. To make it clear, I am using a hashmap for each bucket connection, and since the indexing job is time-consuming so I extended the timeouts in the connection initialization. Hope this is helpful.

  1. initial connection parts
List hosts = new ArrayList(); for (String server : servers) { try { URI base = new URI(String.format("http://%s/pools", StringUtils.trim(server))); hosts.add(base); } catch (URISyntaxException e) { LOGGER.warn(e.getMessage()); continue; } } if (!hosts.isEmpty()) { if (!clientMap.containsKey(bucket)) { CouchbaseConnectionFactoryBuilder cfb = new CouchbaseConnectionFactoryBuilder(); cfb.setOpTimeout(1000 * 60 * 30); cfb.setOpQueueMaxBlockTime(5000); cfb.setViewTimeout(1000 * 60 * 60); CouchbaseClient client = new CouchbaseClient(cfb.buildCouchbaseConnection(hosts, bucket, password)); clientMap.put(bucket, client); } LOGGER.debug("[" + bucket + "] initialization was complete"); }
  1. query parts
String designDoc = "design"; String viewName = "view";

Query query = new Query();
ComplexKey.of(“d”, “a”, “2014”, “07”, “10”, “12”),
ComplexKey.of(“d”, “a”, “2014”, “07”, “10”, “12”, “\u0fff”)

for (int i = 0; i < SEARCH_RETRY_COUNT; i++) {
View view = clientMap.get(bucket).getView(designDoc, viewName);
try {
response = clientMap.get(bucket).query(view, query);
if (response != null) {
} catch (RuntimeException re) {
if (re.getMessage().contains(“Failed to access the view”)) {
try {
} catch (InterruptedException ie) {;
}"retry count = " + (i + 1));


Thanks, can you also set logging to FINEST and share that? It looks like we need to inspect the server response.


Since I’m using log4j, I tried to get more verbose log by setting TRACE level but there was nothing changed compared to the below log I’ve already posted. If I missed anything, please let me know.



no worries. Btw you can check here for more info on configuring logging properly with the couchbase client:

One thing I’d like to get if possible: can you set a breakpoint where it throws the GENERAL exception and print the details? If I’m not mistaken its a json parsing error because the server returns a body error msg. I plan to make this logged in the next SDK version but for now we have to take what is there. Would be awesome, thanks!


Thanks for the useful information! I applied the FINEST level and had the following error that kept repeating. Unfortunatley, I also set a breakpoint on the GENERAL exception line as you said but it didn’t work. In addition, I tested the same query with stale=ok, and it worked well so I guess it’s not just a server error. Any ideas or suggestions?

2014/07/14 20:55:30 com.couchbase.client.http.HttpResponseCallback retryOperation Retrying HTTP operation from node (10.32.124.***:8092), Request: GET /analytics-service/_design/query_referer/_view/rank?reduce=true&limit=20&stale=false&group_level=8&startkey=%5B%22d%22%2C%22a%22%5D&endkey=%5B%22d%22%2C%22a%22%2C%22%E0%BF%BF%22%5D HTTP/1.1 2014/07/14 20:55:30 com.couchbase.client.http.HttpResponseCallback completed Operation returned, but needs to be retried because of: HTTP/1.1 500 Internal Server Error


Yes, what I would suggest is:

when you run these queries, afterwards run cbcollectinfo (to collect cluster logs), create a MB ticket with that info. Please post the link here so I can follow up with the server team if they need more info on the client side. It could be something that we are already tracking but I don’t know yet.

Also helpful for me would be to set a breakpoint at com.couchbase.client.protocol.views.ViewOperationImpl#76 and in there print the “json” variable. So we can see whats in the actual body. Note that I already have the patch to print that automatically for the next release:


Thanks for your suggestions. Okay, I will do it later.

Also set a breakpoint at the line and got the result at this time. The “json” variable was just empty string("") , and I also got “400 bad request” but the request seemed to be correct. Then, I had the “Error parsing JSON” exception. Hope this is helpful.