最近在做刪除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索引被刪除,導致滾動過程沒有最後完成。