浅谈Elasticsearch数据写入流程的refresh和flush操作
这篇文章主要写Elasticsearch写入流程中底层的存储实现,主要涉及refresh和flush等操作。
从上图可以看到 ES中一个Index可能分为多个shard。实现上每个shard都是一个Lucence的Index,而每个Lucence Index内部是由多个Segment文件组成。
下面分别从 Lucene数据写入 和 Elasticsearch数据写入 两个视角来了解Elasticsearch写入数据底层到底都有哪些操作。
Lucene 数据写入
下面是一张Lucene写入模型图,
DocumentsWriter 处理写请求,并分配具体的线程 DocumentsWriterPerThread
DocumentsWriterPerThread 具有独立内存空间,对文档进行处理 DocumentsWriter 触发一些 flush 的操作。
DocumentsWriterPerThread 中的内存 In-memory buffer 会被 flush