ES中的“删除索引”命令如何工作?
在正在运行的ES群集上使用“删除索引”命令时是否存在任何风险?
该命令会占用过多的CPU或内存吗?
最佳答案
删除索引通常非常快,并且当Elasticsearch发送删除索引请求的成功响应时,Elasticsearch实际上并不会删除所有文档。
Elasticsearch主要更新cluster state(保留在集群的所有节点上)以将索引标记为已删除,并且在更新索引以及路由表,元数据等其他内容时完成了繁重的工作。
this是Elaticsearch源代码中的主要方法,可以帮助您理解上面提到的内容以及delete索引的内部结构。
链接以上的一些重要代码段
RoutingTable.Builder routingTableBuilder = RoutingTable.builder(currentState.routingTable());
Metadata.Builder metadataBuilder = Metadata.builder(meta);
ClusterBlocks.Builder clusterBlocksBuilder = ClusterBlocks.builder().blocks(currentState.blocks());
final IndexGraveyard.Builder graveyardBuilder = IndexGraveyard.builder(metadataBuilder.indexGraveyard());
final int previousGraveyardSize = graveyardBuilder.tombstones().size();
for (final Index index : indices) {
String indexName = index.getName();
logger.info("{} deleting index", index);
routingTableBuilder.remove(indexName);
clusterBlocksBuilder.removeIndexBlocks(indexName);
metadataBuilder.remove(indexName);
}
// add tombstones to the cluster state for each deleted index
final IndexGraveyard currentGraveyard = graveyardBuilder.addTombstones(indices).build(settings);
metadataBuilder.indexGraveyard(currentGraveyard); // the new graveyard set on the metadata
logger.trace("{} tombstones purged from the cluster state. Previous tombstone size: {}. Current tombstone size: {}.",
graveyardBuilder.getNumPurged(), previousGraveyardSize, currentGraveyard.getTombstones().size());
提出您的问题,在正在运行的ES群集上使用“删除索引”命令时是否存在任何风险?该命令会占用过多的CPU或内存吗?
除非您有一个巨大的集群状态,并且没有提到在运行中的Elasticsearch集群上使用
delete index
请求,否则实际上没有删除索引的发生,并且这只会更新各种状态和标志,这不会占用太多CPU。您还可以在
org.elasticsearch.cluster.metadata.MetadataDeleteIndexService
中启用跟踪日志,并按照上面的代码片段中的说明查看集群的大小。
关于performance - 'delete index'命令在ES内部如何工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61291353/