CB 5.0 - Does Java SDK recognize new GSI indexes? Or is it caching indexes?

CB CE v5.0.0
Java SDK: 2.5.2
Cluster: 3 Nodes (index, data, query on all nodes)

Symptom:
We have a feeling that our application did not recognize a recreated GSI index. After app-restart it worked fine.

What we did:

We have dropped and created (corrected) a GSI index in Couchbase Console while the application was still running.
The reason was, that for one field which was used in a N1QL query, there was no index found (because of a typo in the index definition). Thus another index was used which basically performed a Full table scan to find.

We drop and added the index again (same indexname, but small change in fields of the index definition). and ran the query again.
Here is what happened:

1.) In CB Console, the query was running fine and EXPLAIN was showing that the correct index was used.
2.) our application was still slow and seemed to not use the new index (we could see a huge spike of Ops/s in CB console because of the Full table scan).

We then restarted the application.
Suddenly it was fast as expected.

Question:
Is the Java SDK caching index information?
If yes, how long? Can this cache be cleared?
Or are we using Couchbase Environment wrong?
Currently to access CB we have a Singleton CouchbaseDAO which holds a single ref to DefaultCouchbaseEnvironment, Cluster and Bucket.

Any hints appreciated.

@synesty are you using prepared statemens? (adhoc = false). If so, the client is keeping a cache of the plan which then in turn would have to be cleared if things change on the server side. Each bucket has a method to clear the cache which you for example could trigger through JMX or so. Its not perfect right now and we are working in combination with the query server team to improve this drastically for future releases.

1 Like

Yes, we are using adhoc=false.
Ok I guess this explains it. We will keep that in mind when doing index changes while the app is running.

Thanks for your quick reply :slight_smile:

You mention JMX: Is there any documentation on how to enable and access the JMX features of Couchbase?
Using jconsole we currently do not see any MBeans for couchbase.

Could we instead also catch the exception and reconnect the client to the Cluster->Bucket again? Will that clear the cache too?

Ping! :slight_smile: @daschl
Where can I find documentation about enabling and accessing JMX stuff from Java?
Thanks

@synesty ah sorry for the delay… missed the question :slight_smile:

No the SDK doesn’t currently provide this out of the box, my idea was that you could use the bucket API to write your own mbean that triggers the call.

Ah ok I understand.
Is com.couchbase.client.java.Bucket.invalidateQueryCache() the method you are talking about?

Yes thats the method!

1 Like