简体   繁体   English

Couchbase视图一致性

[英]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: 以下代码确保将任何给定文档以持久方式保存到Couchbase群集中的活动节点,并复制到1个其他节点:

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): 鉴于Couchbase Views最终是一致的,看来在编写文档后调用视图时(确保文档出现在视图中),我有2种选择来保证一致性:

Option 1 选项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: 更改上面代码中的replicateTo值,使其等于集群中其他节点的总数(减去活动节点),确保每个节点都包含文档的副本:

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

Option 2 选项2

Use the standard Upsert function to save the document, but invoke the View with stale-mode set to after-update 使用标准的Upsert函数保存文档,但是使用stale-mode设置为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. 您需要将陈旧模式设置为false。 If stale=ok is set, Couchbase will not refresh the view even if it is stale. 如果设置了stale = ok,则即使视图已过时,Couchbase也不会刷新视图。 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. 如果设置了stale = update_after,则Couchbase将在返回过时的结果后更新视图。 If stale=false is set, Couchbase will refresh the view and return you most updated results. 如果设置了stale = false,则Couchbase将刷新视图并返回最新的结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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