Skip to content

Commit

Permalink
[ML] Check for internal index searchability as well as active primary
Browse files Browse the repository at this point in the history
Currently, before performing operations that require the ML internal
indices be available we check whether their primary shards are active.

In stateless Elasticsearch we need to separately check whether the
indices are searchable, as search and indexing shards are separate.
  • Loading branch information
droberts195 committed Oct 13, 2023
1 parent b8a204f commit 66c1a76
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,6 @@ static boolean mlConfigIndexIsAllocated(ClusterState clusterState) {
}

IndexRoutingTable routingTable = clusterState.getRoutingTable().index(configIndexOrAlias.getWriteIndex());
return routingTable != null && routingTable.allPrimaryShardsActive();
return routingTable != null && routingTable.allPrimaryShardsActive() && routingTable.readyForSearch(clusterState);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ public boolean isAbleToRun(ClusterState latestState) {
continue;
}
IndexRoutingTable routingTable = latestState.getRoutingTable().index(index);
if (routingTable == null || routingTable.allPrimaryShardsActive() == false) {
if (routingTable == null
|| routingTable.allPrimaryShardsActive() == false
|| routingTable.readyForSearch(latestState) == false) {
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,9 @@ private AssignmentFailure verifyIndicesActive() {

for (String concreteIndex : concreteIndices) {
IndexRoutingTable routingTable = clusterState.getRoutingTable().index(concreteIndex);
if (routingTable == null || routingTable.allPrimaryShardsActive() == false) {
if (routingTable == null
|| routingTable.allPrimaryShardsActive() == false
|| routingTable.readyForSearch(clusterState) == false) {
return new AssignmentFailure(
"cannot start datafeed ["
+ datafeedId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,9 @@ static boolean verifyIndicesExistAndPrimaryShardsAreActive(ClusterState clusterS
return false;
}
IndexRoutingTable routingTable = clusterState.getRoutingTable().index(index);
if (routingTable == null || routingTable.allPrimaryShardsActive() == false) {
if (routingTable == null
|| routingTable.allPrimaryShardsActive() == false
|| routingTable.readyForSearch(clusterState) == false) {
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ public static List<String> verifyIndicesPrimaryShardsAreActive(
continue;
}
IndexRoutingTable routingTable = clusterState.getRoutingTable().index(index);
if (routingTable == null || routingTable.allPrimaryShardsActive() == false) {
if (routingTable == null
|| routingTable.allPrimaryShardsActive() == false
|| routingTable.readyForSearch(clusterState) == false) {
unavailableIndices.add(index);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ public void testIsAbleToRun() {
.put(IndexMetadata.SETTING_VERSION_CREATED, IndexVersion.current())
.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1)
.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0)
.put(IndexMetadata.SETTING_INDEX_UUID, "_uuid")
);
metadata.put(indexMetadata);
Index index = new Index(MlConfigIndex.indexName(), "_uuid");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public void testVerifyIndicesExistAndPrimaryShardsAreActive() {
.put(IndexMetadata.SETTING_VERSION_CREATED, IndexVersion.current())
.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1)
.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0)
.put(IndexMetadata.SETTING_INDEX_UUID, "_uuid")
);
metadata.put(indexMetadata);
addToRoutingTable(concreteIndex, routingTable);
Expand All @@ -91,6 +92,7 @@ public void testVerifyIndicesExistAndPrimaryShardsAreActive() {
.put(IndexMetadata.SETTING_VERSION_CREATED, IndexVersion.current())
.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1)
.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0)
.put(IndexMetadata.SETTING_INDEX_UUID, "_uuid")
);
metadata.put(indexMetadata);
addToRoutingTable(concreteIndex, routingTable);
Expand All @@ -111,6 +113,7 @@ public void testVerifyIndicesExistAndPrimaryShardsAreActive() {
.put(IndexMetadata.SETTING_VERSION_CREATED, IndexVersion.current())
.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1)
.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0)
.put(IndexMetadata.SETTING_INDEX_UUID, "_uuid")
);
metadata.put(indexMetadata);
addToRoutingTable(concreteIndex, routingTable);
Expand Down Expand Up @@ -174,6 +177,7 @@ public void testUpdateStatsUpgradeMode() {
.put(IndexMetadata.SETTING_VERSION_CREATED, IndexVersion.current())
.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1)
.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0)
.put(IndexMetadata.SETTING_INDEX_UUID, "_uuid")
);
Metadata.Builder metadata = Metadata.builder().put(indexMetadata);

Expand Down Expand Up @@ -201,6 +205,7 @@ public void testUpdateStatsUpgradeMode() {
.put(IndexMetadata.SETTING_VERSION_CREATED, IndexVersion.current())
.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1)
.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0)
.put(IndexMetadata.SETTING_INDEX_UUID, "_uuid")
);

// now set the upgrade mode
Expand Down Expand Up @@ -232,6 +237,7 @@ public void testUpdateStatsUpgradeMode() {
.put(IndexMetadata.SETTING_VERSION_CREATED, IndexVersion.current())
.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1)
.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0)
.put(IndexMetadata.SETTING_INDEX_UUID, "_uuid")
);

Metadata.Builder metadata = Metadata.builder()
Expand Down Expand Up @@ -288,6 +294,7 @@ public void testUpdateStatsResetMode() {
.put(IndexMetadata.SETTING_VERSION_CREATED, IndexVersion.current())
.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1)
.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0)
.put(IndexMetadata.SETTING_INDEX_UUID, "_uuid")
);

// now set the upgrade mode
Expand Down Expand Up @@ -319,6 +326,7 @@ public void testUpdateStatsResetMode() {
.put(IndexMetadata.SETTING_VERSION_CREATED, IndexVersion.current())
.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1)
.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0)
.put(IndexMetadata.SETTING_INDEX_UUID, "_uuid")
);

Metadata.Builder metadata = Metadata.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ private void addIndices(Metadata.Builder metadata, RoutingTable.Builder routingT
.put(IndexMetadata.SETTING_VERSION_CREATED, IndexVersion.current())
.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1)
.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0)
.put(IndexMetadata.SETTING_INDEX_UUID, "_uuid")
);
if (indexName.equals(AnomalyDetectorsIndexFields.STATE_INDEX_PREFIX)) {
indexMetadata.putAlias(new AliasMetadata.Builder(AnomalyDetectorsIndex.jobStateIndexWriteAlias()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ private void addIndices(Metadata.Builder metadata, RoutingTable.Builder routingT
.put(IndexMetadata.SETTING_VERSION_CREATED, IndexVersion.current())
.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1)
.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0)
.put(IndexMetadata.SETTING_INDEX_UUID, "_uuid")
);
if (indexName.equals(AnomalyDetectorsIndexFields.STATE_INDEX_PREFIX)) {
indexMetadata.putAlias(new AliasMetadata.Builder(AnomalyDetectorsIndex.jobStateIndexWriteAlias()));
Expand Down

0 comments on commit 66c1a76

Please sign in to comment.