Couchbase视图一致性

huangapple go评论79阅读模式
英文:

Couchbase View Consistency

问题

以下代码确保任何给定的文档将以持久的方式保存到Couchbase集群中的活动节点,并复制到1个附加节点:

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

考虑到Couchbase视图是最终一致性的,似乎在写入文档后保证调用视图时有两个选项(确保文档出现在视图中):

选项1

将上述代码中的replicateTo值更改为等于集群中附加节点的总数(减去活动节点),确保每个节点都包含文档的副本:

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

选项2

使用标准的Upsert函数保存文档,但在调用视图时将stale-mode设置为after-update

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

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

是否有其他方法以最高效的方式实现这一目标?基本上,我希望在保存后立即在所有相关视图中显示文档。

英文:

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.

答案1

得分: 1

你需要将stale模式设置为false。如果设置为stale=ok,即使视图过期,Couchbase也不会刷新视图。这样做的好处是可以提高查询的延迟。如果设置为stale=update_after,Couchbase会在返回过期结果后更新视图。如果设置为stale=false,Couchbase会刷新视图并返回最新的结果。

英文:

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.

huangapple
  • 本文由 发表于 2016年2月11日 20:11:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/35339033.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定