简体   繁体   中英

Couchbase View Consistency

The following code guarantees that any given document will be saved in a durable manner to the active node in a Couchbase cluster, as well as replicated to 1 additional node:

cas, err := myBucket.UpsertDura(docToStore, valueToStore, 1, 1)

Given that Couchbase Views are eventually consistent, it would seem that I have 2 options in terms of guaranteeing consistency when invoking a view after writing a document (ensuring that the document appears in the view):

Option 1

Change the replicateTo value in the above code to equal the total number of additional nodes (minus the active node) in the cluster, ensuring that each node contains a copy of the document:

cas, err := myBucket.UpsertDura(docToStore, valueToStore, 3, 4)

Option 2

Use the standard Upsert function to save the document, but invoke the View with stale-mode set to after-update

_, err := bucket.Upsert(myID, &myDoc, 0)

vq := gocb.NewViewQuery("doc", "view").Stale(gocb.StaleMode(1))
err = bucket.ExecuteViewQuery(vq)

Are there any alternatives to achieve this in the most performant manner possible? Essentially I would like for the document the appear in all relative views immediately after saving.

you need to set the stale mode to false. If stale=ok is set, Couchbase will not refresh the view even if it is stale. The benefit of this is a an improved query latency. If stale=update_after is set, Couchbase will update the view after the stale result is returned. If stale=false is set, Couchbase will refresh the view and return you most updated results.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM