弹性搜索中的 primary_term 到底是什么?

What exactly is the primary_term in elastic search?

阅读大量文档后,我了解到 primary_term 和 sequence_number 用于乐观并发控制,以防止旧版本的文档覆盖新版本。但是,我的问题是 primary_term 到底是什么?它与主分片相同吗?

来自docs

To ensure an older version of a document doesn’t overwrite a newer version, every operation performed to a document is assigned a sequence number by the primary shard that coordinates that change.

假设您的索引由 5 个主分片组成(这是版本 7 之前的默认设置)。索引和更新请求是针对主分片执行的。如果您有多个主分片,elasticsearch 能够 parallelize/distribute 将传入请求(例如大量批量请求)发送到多个分片以提高性能。

因此 primary_term 给出了关于主分片的信息(本例中的#1、#2、#3、#4 或#5)executed/coordinated change/update.

Q: Is it the same as the primary shard?

A: If you mean, is it the same as the number of primary shards, then yes, in case your index has only one primary shard, the values will be equal.

每次在故障转移期间不同的分片成为主要分片时,主要术语都会增加。这有助于解决在重新上线的旧初选上发生的变化与在新的初选上发生的变化(新胜利)。

These primary terms are incremental and change when a primary is promoted. They're persisted in the cluster state, thus representing a sort of “version” or “generation” of primaries that the cluster is on.

https://www.elastic.co/blog/elasticsearch-sequence-ids-6-0

简答

复制组的主要术语只是主分片更改次数的计数器。


更多:主词是Elasticsearch在复制组的主分片发生变化时区分新旧主分片的一种方式。