Skip to content

Commit

Permalink
Adds additional comments
Browse files Browse the repository at this point in the history
Signed-off-by: Clay Downs <[email protected]>
  • Loading branch information
downsrob committed Mar 5, 2022
1 parent ade5565 commit 5782256
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import org.opensearch.action.admin.cluster.state.ClusterStateRequest
import org.opensearch.action.admin.cluster.state.ClusterStateResponse
import org.opensearch.action.support.IndicesOptions
import org.opensearch.client.Client
import org.opensearch.cluster.metadata.IndexMetadata
import org.opensearch.cluster.service.ClusterService
import org.opensearch.common.unit.TimeValue
import org.opensearch.indexmanagement.opensearchapi.suspendUntil
Expand Down Expand Up @@ -38,18 +39,27 @@ class DefaultIndexMetadataService(val customUUIDSetting: String? = null) : Index

response.state.metadata.indices.forEach {
// TODO waiting to add document count until it is definitely needed
val uuid = if (customUUIDSetting != null) {
it.value.settings.get(customUUIDSetting, it.value.indexUUID)
} else {
it.value.indexUUID
}
val uuid = getCustomIndexUUID(it.value)
val indexMetadata = ISMIndexMetadata(uuid, it.value.creationDate, -1)
indexNameToMetadata[it.key] = indexMetadata
}

return indexNameToMetadata
}

/*
* If an extension wants Index Management to determine cluster state indices UUID based on a custom index setting if
* present of cluster state, the extension will override this customUUID setting. This allows an index to migrate off
* cluster and back while using this persistent uuid.
*/
fun getCustomIndexUUID(indexMetadata: IndexMetadata): String {
return if (customUUIDSetting != null) {
indexMetadata.settings.get(customUUIDSetting, indexMetadata.indexUUID)
} else {
indexMetadata.indexUUID
}
}

override suspend fun getMetadataForAllIndices(client: Client, clusterService: ClusterService): Map<String, ISMIndexMetadata> {
return getMetadata(listOf("*"), client, clusterService)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,10 +245,15 @@ object ManagedIndexRunner :
return
}

var indexMetadata = getIndexMetadata(managedIndexConfig.index)
// The index uuids not matching can happen when two jobs share a name but have different index types
if (indexMetadata == null || indexMetadata.indexUUID != managedIndexConfig.indexUuid) {
indexMetadata = null
// Check the cluster state for the index metadata
var clusterStateIndexMetadata = getIndexMetadata(managedIndexConfig.index)
val defaultIndexMetadataService = indexMetadataProvider.services[DEFAULT_INDEX_TYPE] as DefaultIndexMetadataService
val clusterStateIndexUUID = clusterStateIndexMetadata?.let { defaultIndexMetadataService.getCustomIndexUUID(it) }
// If the index metadata is null, the index is not in the cluster state. If the index metadata is not null, but
// the cluster state index uuid differs from the one in the managed index config then the config is referring
// to a different index which does not exist in the cluster. We need to check all of the extensions to confirm an index exists
if (clusterStateIndexMetadata == null || clusterStateIndexUUID != managedIndexConfig.indexUuid) {
clusterStateIndexMetadata = null
// If the cluster state/default index type didn't have an index with a matching name and uuid combination, try all other index types
val nonDefaultIndexTypes = indexMetadataProvider.services.keys.filter { it != DEFAULT_INDEX_TYPE }
val multiTypeIndexNameToMetaData =
Expand All @@ -262,7 +267,7 @@ object ManagedIndexRunner :
return
}
} else {
val clusterStateMetadata = indexMetadata.getManagedIndexMetadata()
val clusterStateMetadata = clusterStateIndexMetadata.getManagedIndexMetadata()
val metadataCheck = checkMetadata(clusterStateMetadata, managedIndexMetaData, managedIndexConfig.indexUuid, logger)
if (metadataCheck != MetadataCheck.SUCCESS) {
logger.info("Skipping execution while metadata status is $metadataCheck")
Expand Down

0 comments on commit 5782256

Please sign in to comment.