Skip to content

Commit

Permalink
[Transform] Check for internal index searchability as well as active …
Browse files Browse the repository at this point in the history
…primary

Currently, before performing operations that require the transform
internal index be available we check whether its primary shard is
active.

In stateless Elasticsearch we need to separately check whether the
index is searchable, as search and indexing shards are separate.
  • Loading branch information
droberts195 committed Oct 13, 2023
1 parent b8a204f commit da46663
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ protected static boolean hasLatestVersionedIndex(ClusterState state) {
protected static boolean allPrimaryShardsActiveForLatestVersionedIndex(ClusterState state) {
IndexRoutingTable indexRouting = state.routingTable().index(TransformInternalIndexConstants.LATEST_INDEX_VERSIONED_NAME);

return indexRouting != null && indexRouting.allPrimaryShardsActive();
return indexRouting != null && indexRouting.allPrimaryShardsActive() && indexRouting.readyForSearch(state);
}

private static void waitForLatestVersionedIndexShardsActive(Client client, ActionListener<Void> listener) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,9 @@ static List<String> verifyIndicesPrimaryShardsAreActive(ClusterState clusterStat
List<String> unavailableIndices = new ArrayList<>(indices.length);
for (String index : indices) {
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 @@ -63,11 +63,12 @@ public static ClusterState randomTransformClusterState() {
}

public static ClusterState randomTransformClusterState(boolean shardsReady) {
String uuid = UUIDs.randomBase64UUID();
Map<String, IndexMetadata> indexMapBuilder = new HashMap<>();
try {
IndexMetadata.Builder builder = new IndexMetadata.Builder(TransformInternalIndexConstants.LATEST_INDEX_VERSIONED_NAME).settings(
Settings.builder()
.put(TransformInternalIndex.settings(Settings.EMPTY))
.put(TransformInternalIndex.settings(Settings.builder().put(IndexMetadata.SETTING_INDEX_UUID, uuid).build()))
.put(IndexMetadata.SETTING_INDEX_VERSION_CREATED.getKey(), IndexVersion.current())
.build()
).numberOfReplicas(0).numberOfShards(1).putMapping(Strings.toString(TransformInternalIndex.mappings()));
Expand All @@ -80,7 +81,7 @@ public static ClusterState randomTransformClusterState(boolean shardsReady) {
ClusterState.Builder csBuilder = ClusterState.builder(ClusterName.DEFAULT);
csBuilder.metadata(metaBuilder.build());

final var index = new Index(TransformInternalIndexConstants.LATEST_INDEX_VERSIONED_NAME, UUIDs.randomBase64UUID());
final var index = new Index(TransformInternalIndexConstants.LATEST_INDEX_VERSIONED_NAME, uuid);
csBuilder.routingTable(
RoutingTable.builder()
.add(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ private void addIndices(Metadata.Builder metadata, RoutingTable.Builder routingT
indices.add(TransformInternalIndexConstants.LATEST_INDEX_NAME);
for (String indexName : indices) {
IndexMetadata.Builder indexMetadata = IndexMetadata.builder(indexName);
indexMetadata.settings(indexSettings(IndexVersion.current(), 1, 0));
indexMetadata.settings(indexSettings(IndexVersion.current(), 1, 0).put(IndexMetadata.SETTING_INDEX_UUID, "_uuid"));
metadata.put(indexMetadata);
Index index = new Index(indexName, "_uuid");
ShardId shardId = new ShardId(index, 0);
Expand Down

0 comments on commit da46663

Please sign in to comment.