Thanks @ingenthr.
When performing an online upgrade from Couchbase Server 6.0.3 to Couchbase Server 6.5, active Couchbase Java SDK 2.x applications may give exception 4040: No such prepared statement .
Client-side workarounds for the Couchbase Java SDK 2.x:
Restart the application server after the server upgrade. This implicitly clears the client cache, leading it to prepare statements again.
Change the client code. If the client receives exception 4040 , clean the cache using invalidateQueryCache() and retry. (This only works for Java.)
Server-side workarounds:
Upgrade the first node — this can be a Data service node, or any other node.
Increase the prepared statement cache size. In the Query Workbench, go to SettingsGeneralQuery SettingsAdvanced Query Settings and set Prepared Limit to 66560 .
Make sure that encoded_plan will be honored. Also in SettingsGeneralQuery SettingsAdvanced Query Settings , set N1QL Feature Controller to 8 .
These settings persist, and will be used as other query service nodes are upgraded.
Also, the new Java sdk will be released in a few days. That will auto retry on receiving 4040.
To provide better compatibility with cluster upgrades and with query prepared statements on Couchbase Server 6.5 and later, the SDK now transparently retries the 4040 response code in a similar way to with related error codes.
We also set the limit to 66560 and N1QL Feature Controller to 8 and restarted Sync-gateway. And we still see the issue.
Is there any other solution to fix this?