Using Node.js I have two unit tests (mocha) using a single live CBv4 instance.
The 1st test inserts a document.
The 2nd test reads all documents.
In between test runs I flush the bucket I’m inserting and reading from.
The issue I’m seeing is both tests pass, but the read test returns zero documents - should be one document.
The read seems to complete before the insert is “commited” or something like that as there is one document in the bucket from the insert.
Does this seem like normal behavior?
I know NoSQL is eventually read consistent but I though on a single instance it would be just a few milli seconds or so.
My read is a simple N1QL query:
let query = N1qlQuery.fromString('select meta(rsm).id as doc_id, meta(rsm).cas, email, id from rsm WHERE type = "user"');
In my case if I add a 500ms timeout in the read test the test passes.
At this point in time I’m new to Couchbase so I’m not sure if this is typical server behaviour, but I was assuming eventually read consistent (using N1QL) would be a few milli seconds at most.
OK reading up some more (sorry should have before I posted this) I am trying to work with the scan consistency.
Trying both REQUEST_PLUS and STATEMENT_PLUS the read test just times out - even after 10 seconds.
let query = N1qlQuery.fromString('select meta(rsm).id as doc_id, meta(rsm).cas, email, id from rsm WHERE type = "user"').consistency(N1qlQuery.Consistency.REQUEST_PLUS);
let query = N1qlQuery.fromString('select meta(rsm).id as doc_id, meta(rsm).cas, email, id from rsm WHERE type = "user"').consistency(2);
I’ll keep digging and see if I can’t get consistent write then read results and post my results here.
Any suggestions welcomed as well.
OK things are working fine for me using this N1QL query right after an insert.
Can also use the value 2 instead of N1qlQuery.Consistency.REQUEST_PLUS (but I think explicitly writing it out is better).
I’m using a single instance CBv4 with the official Docker image.
I’ve found that if I flush the test bucket, it’s best to drop and re-create the N1QL GSI index - else things can ‘sieze’ up.
Here in development, I’ve been dropping buckets, creating them, flushing them, creating GSI indexes - not keeping the indexes in “sync” with the buckets can seem to freeze the indexing up.
When that happens I just blow away the Docker container and create a new one.
In production I don’t think I’d ever use flush on a bucket, thus it shouldn’t be a problem.
My workflow at the moment is to use the provide couchbase Mock object for testing (fast) then, occasionally/regularly run the same tests on the live CBv4 instance.
I like the CB consistency model and it’s great to be able to selectively set for some N1QL queries.
Anyways, it’s all good.