I’m running
Enterprise Edition 7.2.3 build 6705 locally in a container. Is it possible to create a scope and its collections in the same N1QL query? Neither Java SDK nor the Couchbase UI let me do this:
The creation and propagation of artifacts (buckets, scopes, collections, indexes etc) is not synchronous. So while you have made a request to “CREATE SCOPE default.store”, that scope may not exist an instant later. It’s even possible for one node to know about a just-created-scope, while the creation of the scope has not been propagated to another node.
You’ll run into a lot of this when writing tests, and be motivated to write various waitUntilxyz() utility methods.
If that’s the case, what does it mean when a CompletableFuture returned from async().query() completes? Here, in this example, each operation takes ~45ms yet the CREATE COLLECTION statements still fail every few runs:
This seems like an eternity in CPU time for a mere request to create something asynchronously, considering we’re dealing with one node on localhost with the entirety of its data sitting on top of tmpfs.
It means the request has been sent to the server and the server accepted the request (i.e. there were no syntax errors in it). It doesn’t mean that the server has completed creating the scope/collection.
Here, in this example, each operation takes ~45ms yet the CREATE COLLECTION statements still fail every few runs
Yes. So you’d best make yourself a “waitUntilScopeExists(scopeName)” and and a “waitUntilCollectionExists(scopeName, collectionName)”.
SELECT * from system:scopes where name = ?
SELECT * from system:keyspaces where scope = ? and name = ?
However - when you start testing with multiple nodes - you’ll find that even though an artifact was created on one node, it may not yet be propagated to all nodes.
Oh, I see… So in order to wait for that to happen, I should poll Couchbase using these queries until they return documents with datastore_id for every entry in system:datastores, right?