Skip to content

Commit

Permalink
Fix auto managed index always have -2 seqNo bug
Browse files Browse the repository at this point in the history
Signed-off-by: bowenlan-amzn <[email protected]>
  • Loading branch information
bowenlan-amzn committed Sep 7, 2023
1 parent 8f7e744 commit cb06502
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ class ManagedIndexCoordinator(
findMatchingPolicy(lookupName, creationDate, policiesWithTemplates)
?.let { policy ->
logger.info("Index [$indexName] matched ISM policy template and will be managed by ${policy.id}")
logger.info("$policy")
updateManagedIndexReqs.add(
managedIndexConfigIndexRequest(
indexName,
Expand Down Expand Up @@ -455,13 +456,14 @@ 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())

return try {
val response: SearchResponse = client.suspendUntil { search(searchRequest, it) }
logger.info("get policies response $response")
parseFromSearchResponse(response = response, parse = Policy.Companion::parse)
} catch (ex: IndexNotFoundException) {
emptyList()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ class TransportAddPolicyAction @Inject constructor(
}

val bulkReq = BulkRequest().timeout(TimeValue.timeValueMillis(bulkReqTimeout))
log.info("policy $policy")
indicesToAdd.forEach { (uuid, name) ->
bulkReq.add(
managedIndexConfigIndexRequest(name, uuid, request.policyID, jobInterval, policy = policy.copy(user = this.user), jobJitter)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ class TransportExplainAction @Inject constructor(
.sort(sortBuilder)
.size(searchSize)
.query(queryBuilder)
.seqNoAndPrimaryTerm(true)

return SearchRequest()
.indices(INDEX_MANAGEMENT_INDEX)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import org.opensearch.common.xcontent.XContentType
import org.opensearch.commons.InjectSecurity
import org.opensearch.commons.authuser.User
import org.opensearch.commons.notifications.NotificationsPluginInterface
import org.opensearch.commons.utils.logger
import org.opensearch.core.action.support.DefaultShardOperationFailedException
import org.opensearch.core.common.bytes.BytesReference
import org.opensearch.core.concurrency.OpenSearchRejectedExecutionException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
41 changes: 39 additions & 2 deletions worksheets/ism/delete.http
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit cb06502

Please sign in to comment.