JBalaguero
JBalaguero

Reputation: 201

Couchbase query does not see documents add recently

I'm performing a test with CouchBase 4.0 and java sdk 2.2. I'm inserting 10 documents whose keys always start by "190".

After inserting these 10 documents I query them with:

cb.restore("190", cache);
Thread.sleep(100);
cb.restore("190", cache);

The query within the 'restore' method is:

Statement st = Select.select("meta(c).id, c.*").from(this.bucketName + " c").where(Expression.x("meta(c).id").like(Expression.s(callId + "_%")));
N1qlQueryResult result = bucket.query(st);

The first call to restore returns 0 documents:

Query 'SELECT meta(c).id, c.* FROM cache c WHERE meta(c).id LIKE "190_%"' --> Size = 0

The second call (100ms later) returns the 10 documents:

Query 'SELECT meta(c).id, c.* FROM cache c WHERE meta(c).id LIKE "190_%"' --> Size = 10

I tried adding PersistTo.MASTER in the 'insert' statement, but it neither works.

It seems that the 'insert' is not persisted immediately.

Any help would be really appreciated.

Joan.

Upvotes: 2

Views: 293

Answers (1)

FuzzyAmi
FuzzyAmi

Reputation: 8109

You're using N1QL to query the data - and N1QL is only eventually consistent (by default), so it only shows up after the indices are recalculated. This isn't related to whether or not the data is persisted (meaning: written from RAM to disc).

You can try to change the scan_consitency level from its default - NOT_BOUNDED - to get consistent results, but that would take longer to return.

read more here

java scan_consitency options

Upvotes: 4

Related Questions