I am accessing Couchbase views frequently (every minute - run through the thread) with Java 2.1 SDK with Stale parameter as FALSE. Sometime I could see the indexing got stuck for long time. Should I remove the stale Parameter from code or reduce the frequent access the views? BTW there is not bulk insertion / update for every minute. I have attached the screen shot

- 544
- 1
- 6
- 15
2 Answers
First of all, I think you should decide that your query is really need consistency.
Because stale=false
makes Couchbase rebuild the index all the time whenever request comes.
When clients use the false value in the stale parameter, it instructs Couchbase that it wants views to be rebuilt before serving the request, just in case there is any change or addition of documents in the bucket. However, keep in mind that this will delay the serve request, since Couchbase needs to rebuild the index before responding to the request. You can use this option if you require up-to-date information all the time when documents are being fetched from the bucket using views. For example, if you want to find the maximum amount of sales on a particular day from the documents that contain sales by each store. In this scenario, we need to account for all documents created in the bucket, including the one that is in the RAM but yet to spill onto the disk.
Index updates may be stacked if multiple clients request the view be updated before the information is returned ( stale=false ). Multiple clients updating and querying the index data can then get the updated document and version of the view each time. For stale=update_after queries, there is no stacking, since all updates occur after the query has been accessed.

- 2,135
- 2
- 18
- 20
Depending on the way you actually use the data (and more specifically - how often new data is written into couchbase), perhaps it would be better to turn the 'stale' flag off (as suggested by CodeDreamer in another answer) AND in addition, ensure that the view is recalculated after every insertion (as opposed to before very pull).
you could achieve that by artificially querying the data with stale=true after every insertion (but only then). The net result would be a mostly-consistent query results, especially if you have few writes, which fetches relatively fast (because in most cases, the view was already indexed).

- 7,543
- 6
- 45
- 79
-
ok, but sometimes the indexing is hanging on for long time, so could not access the data with client SDK's – Sivailango Dec 15 '16 at 11:08