N1QL Inconsistent results

I’m seeing inconsistent selects when using n1ql

Running the following query, something very similar to it, since I removed some identifying information from type

Select Meta(b).id from DefaultBucket b where uri= “http://integrationtest.test” and userIdentifier = “99999999-9999-9999-9999-999999999999” and type = “Test.Testing.Test.Tests.TestEntity”

Sometimes it works, and sometimes it doesn’t. Feels like a race condition of some sort, only because running the test without a debugger and it usually fails, sometimes multiple times in the same test. Running it with the debugger and it seems to mostly pass.

The query works in CBQ, and I can see a document that matches the data I am selecting on.

I am basically doing an upsert, then a remove, followed by another select. Its failing to remove the object correctly.

@aaronmell

I do know that there is a delay before indexes are updated after you modify data. It’s not like SQL, which is an atomic, transacted process. That’s probably why you aren’t noticing the problem in debug mode, since stepping through is slowing your read down.

If you are performing the query using IQueryRequest (instead of a string), then you have some options that control this consistency. The cost is that it can delay the query result. See the ScanConsistency, ScanVector, and ScanWait methods.

For example, ScanConsistency of RequestPlus will require that all statements up to the moment you run the query must be posted to the index. You can use ScanWait to put a timeout on this update.

1 Like