gpt4 book ai didi

elasticsearch - 为什么lucene的段是不可变的

转载 作者:行者123 更新时间:2023-12-05 02:02:10 25 4
gpt4 key购买 nike

众所周知,在elasticsearch中更新或删除文档内容时,segment不会立即删除,而是重新创建。

在那之后,我们知道段是通过一个时间表合并的。

我知道它之所以这样工作是因为它很贵。

但我不知道段不可变且不立即合并的确切原因。

即使我搜索了文档,也找不到确切的原因,但是如果有人知道这件事,请发表评论。

谢谢。

最佳答案

段不可变有很多好处,例如

  1. 它可以很容易地在多线程环境中使用,因为内容是不可更改的,当您拥有可变内容时,您不必担心共享状态和竞争条件以及很多复杂性。
  2. 它可以有效地缓存,因为缓存快速变化的数据集会破坏缓存的目的。

请引用以下来自官方 ES 文档的内容,了解为什么 lucene segments are cache friendly

Lucene is designed to leverage the underlying OS for caching in-memorydata structures. Lucene segments are stored in individual files.Because segments are immutable, these files never change. This makesthem very cache friendly, and the underlying OS will happily keep hotsegments resident in memory for faster access. These segments includeboth the inverted index (for fulltext search) and doc values (foraggregations).

另请参阅 benefits of immutable data了解更多详情。

关于elasticsearch - 为什么lucene的段是不可变的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66025045/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com