For some test automation, I’m trying to use gocb to flush a bucket. However, since (as I understand it) flushing a bucket is an async operation, I need to do a polling loop to block until there are no longer any items left in the bucket.
I see in the Getting single bucket information docs, there is a REST api which includes the itemCount field, which looks like what I need to determine when the bucket flush has finished.
"itemCount": 0, <----------
Is there a way to call this API from gocb or otherwise find out the bucket item count?
There is not currently a method allowing you to fetch the total number of items within a bucket. The ideal method for detecting when the flush has completed is to insert a document prior to performing the flush, and then watch for the document being no longer found. We are however looking into provide a method to enable cluster-topology aware HTTP requests, which would allow you to fetch the statistics you mentioned.
Ok thanks for the heads up.
As a workaround I’m directly hitting the GET /pools/default/buckets/[bucket-name] endpoint and checking the itemCount – so far it seems reliable, but if you know of any reason why this would fail, then I can switch over to the insert/poll workaround.
FWIW… I’ve done this with a N1QL count query but maybe hitting REST is more reliable at some level I’m unaware of. In my (very tiny) test environment a flush of travel-sample resulted in 0 documents in <500ms.