最近在做删除es过期数据的程序。debug发现的问题记录在这。
场景:
1 一个线程不断写入数据
2 一个线程不断滚动索引
3 一个线程不断通过别名删除过期数据和过期的索引(active索引不删除)
出现的问题
问题1 一个索引中的数据明明过期了,但就是删不掉。下面是索引信息
{
"fdfs1-active-000088" : {
"aliases" : {
"fdfs1-searchs" : { }
},
"mappings" : {
"fdfs1" : {
"_all" : {
"enabled" : false
},
"_source" : {
"enabled" : false
},
"properties" : {
"capturetime" : {
"type" : "date",
"store" : true
},
"group" : {
"type" : "keyword",
"index" : false,
"store" : true
},
"path" : {
"type" : "keyword",
"index" : false,
"store" : true
}
}
}
},
"settings" : {
"index" : {
"routing" : {
"allocation" : {
"require" : {
"_name" : "s21"
},
"total_shards_per_node" : "3"
}
},
"refresh_interval" : "1m",
"number_of_shards" : "3",
"translog" : {
"flush_threshold_size" : "1gb",
"sync_interval" : "30s",
"durability" : "async"
},
"blocks" : {
"write" : "true"
},
"provided_name" : "fdfs1-active-000088",
"creation_date" : "1577179779091",
"number_of_replicas" : "1",
"uuid" : "Hbb_eM-pRei2muI8nNNDPQ",
"version" : {
"created" : "6060199"
}
}
}
}
}
通过命令行删除,也不行
POST fdfs1-searchs/_delete_by_query
{
"query": {
"bool": {
"must": [
{"range": {
"capturetime": {
"gte": "2019-12-26T10:11:36.000Z",
"lte": "2017-03-08T10:11:36.000Z"
}
}}
]
}
}
}
这个我估计问题出在这里
"blocks" : {
"write" : "true"
},
也就是说索引不能更改。这个索引是滚动过的,因为最新的滚动索引已经是fdfs1-active-000151。
分析一下。
fdfs1-active-000088滚动,生成fdfs1-active-000089和fdfs1-inactive-000088;
fdfs1-inactive-000088做reallocate,shrink,merge,replica.
shrink结束后会把fdfs1-active-000088从fdfs1-searchs别名移出,把fdfs1-inactive-000088移入fdfs1-searchs。
问题:
shrink结束前fdfs1-inactive-000088被索引删除线程删除了。
fdfs1-active-000088没有被移出,但又不能修改。删除数据线程不断重复删除,就是删不掉。
问题2:
fdfs1-active-000119
fdfs1-active-000120
fdfs1-active-000126
有几个滚动过的索引没有删除掉。
这几个已经从fdfs1-searchs里面移出来了。删除数据线程不会关注它们。
{
"fdfs1-active-000120" : {
"aliases" : { },
"mappings" : {
"fdfs1" : {
"_all" : {
"enabled" : false
},
"_source" : {
"enabled" : false
},
"properties" : {
"capturetime" : {
"type" : "date",
"store" : true
},
"group" : {
"type" : "keyword",
"index" : false,
"store" : true
},
"path" : {
"type" : "keyword",
"index" : false,
"store" : true
}
}
}
},
"settings" : {
"index" : {
"routing" : {
"allocation" : {
"require" : {
"_name" : "s21"
},
"total_shards_per_node" : "3"
}
},
"refresh_interval" : "1m",
"number_of_shards" : "3",
"translog" : {
"flush_threshold_size" : "1gb",
"sync_interval" : "30s",
"durability" : "async"
},
"blocks" : {
"write" : "true"
},
"provided_name" : "fdfs1-active-000120",
"creation_date" : "1577187514315",
"number_of_replicas" : "1",
"uuid" : "YqLwVeKWQOeBez8NK1aPiQ",
"version" : {
"created" : "6060199"
}
}
}
}
}
分析:
删除索引是整个滚动过程的最后一件事。滚动过程都是检查inactive索引推动的。
问题:
active索引删除前,inactive索引被删除,导致滚动过程没有最后完成。