From 4731f97ea16032515632e3a8b5dae7374437537e Mon Sep 17 00:00:00 2001 From: bowenlan-amzn Date: Thu, 7 Sep 2023 15:59:55 -0700 Subject: [PATCH] Fix auto managed index always have -2 seqNo bug Signed-off-by: bowenlan-amzn --- .../ManagedIndexCoordinator.kt | 2 +- .../indexpolicy/TransportIndexPolicyAction.kt | 2 +- .../coordinator/ManagedIndexCoordinatorIT.kt | 2 + worksheets/ism/delete.http | 41 ++++++++++++++++++- 4 files changed, 43 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/ManagedIndexCoordinator.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/ManagedIndexCoordinator.kt index 86779a579..ad7c460c7 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/ManagedIndexCoordinator.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/ManagedIndexCoordinator.kt @@ -455,7 +455,7 @@ class ManagedIndexCoordinator( .source( SearchSourceBuilder().query( QueryBuilders.existsQuery(ISM_TEMPLATE_FIELD) - ).size(MAX_HITS) + ).size(MAX_HITS).seqNoAndPrimaryTerm(true) ) .indices(INDEX_MANAGEMENT_INDEX) .preference(Preference.PRIMARY_FIRST.type()) diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/indexpolicy/TransportIndexPolicyAction.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/indexpolicy/TransportIndexPolicyAction.kt index a2f483cbb..75a916281 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/indexpolicy/TransportIndexPolicyAction.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/indexpolicy/TransportIndexPolicyAction.kt @@ -178,7 +178,7 @@ class TransportIndexPolicyAction @Inject constructor( .source( SearchSourceBuilder().query( QueryBuilders.existsQuery(ISM_TEMPLATE_FIELD) - ).size(MAX_HITS) + ).size(MAX_HITS).seqNoAndPrimaryTerm(true) ) .indices(IndexManagementPlugin.INDEX_MANAGEMENT_INDEX) .preference(Preference.PRIMARY_FIRST.type()) diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/coordinator/ManagedIndexCoordinatorIT.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/coordinator/ManagedIndexCoordinatorIT.kt index b78a827f9..4f7f4e7da 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/coordinator/ManagedIndexCoordinatorIT.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/coordinator/ManagedIndexCoordinatorIT.kt @@ -36,6 +36,8 @@ class ManagedIndexCoordinatorIT : IndexStateManagementRestTestCase() { assertEquals("Has incorrect policy_id", policyID, managedIndexConfig!!.policyID) assertEquals("Has incorrect index", index, managedIndexConfig.index) assertEquals("Has incorrect name", index, managedIndexConfig.name) + assertEquals("Has incorrect seq no", policy.seqNo, managedIndexConfig.policySeqNo) + assertEquals("Has incorrect primary term", policy.primaryTerm, managedIndexConfig.policyPrimaryTerm) } } diff --git a/worksheets/ism/delete.http b/worksheets/ism/delete.http index b2f3290ed..e9fbc2b12 100644 --- a/worksheets/ism/delete.http +++ b/worksheets/ism/delete.http @@ -18,16 +18,53 @@ Content-Type: application/json } ], "ism_template": { - "index_patterns": ["testdelete"], + "index_patterns": ["testdelete2"], "priority": 100 } } } -### delete index +### +DELETE localhost:9200/_opendistro/_ism/policies/exampledelete + +### PUT http://localhost:9200/testdelete Content-Type: application/json +### +DELETE http://localhost:9200/testdelete +Content-Type: application/json + +### add policy api call +POST localhost:9200/_plugins/_ism/add/testdelete +Content-Type: application/json + +{ + "policy_id": "exampledelete" +} + ### explain api call GET localhost:9200/_plugins/_ism/explain/testdelete?validate_action=true Accept: application/json + +### get policy call +GET localhost:9200/.opendistro-ism-config/_doc/exampledelete + +### get managed index call +GET localhost:9200/.opendistro-ism-config/_search +Content-Type: application/json + +{ + "seq_no_primary_term": true, + "query": { + "term": { + "managed_index.index": { + "value": "testdelete2" + } + } + } +} + +### +PUT http://localhost:9200/testdelete2 +Content-Type: application/json \ No newline at end of file