Skip to content

Commit

Permalink
Allowing preference based rotuing for dot indices
Browse files Browse the repository at this point in the history
Signed-off-by: Shourya Dutta Biswas <[email protected]>
  • Loading branch information
shourya035 committed Jan 3, 2024
1 parent 71d7e4d commit fa3e1d4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1558,6 +1558,14 @@ public static void validateRefreshIntervalSettings(Settings requestSettings, Clu
}
}

/*
Method to check if a non-data stream index name starts with a dot (.)
Used across various validators to ensure that dot indices are exempt from certain restrictions
*/
public static boolean shouldIndexBeIgnored(String indexName) {
return indexName.charAt(0) == '.' && indexName.startsWith(DataStream.BACKING_INDEX_PREFIX) == false;
}

/**
* Validates {@code index.translog.durability} is not async if the {@code cluster.remote_store.index.restrict.async-durability} is set to true.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

import org.opensearch.cluster.ClusterState;
import org.opensearch.cluster.metadata.IndexMetadata;
import org.opensearch.cluster.metadata.MetadataCreateIndexService;
import org.opensearch.cluster.metadata.WeightedRoutingMetadata;
import org.opensearch.cluster.node.DiscoveryNodes;
import org.opensearch.cluster.routing.allocation.decider.AwarenessAllocationDecider;
Expand Down Expand Up @@ -344,7 +345,15 @@ private ShardIterator preferenceActiveShardIterator(
}
}
preferenceType = Preference.parse(preference);
checkPreferenceBasedRoutingAllowed(preferenceType, weightedRoutingMetadata);
/*
Apply preference based routing only if:
- Index is a data stream index
OR
- Index name does not start with a dot (.)
*/
if (MetadataCreateIndexService.shouldIndexBeIgnored(indexShard.shardId().getIndexName()) == false) {
checkPreferenceBasedRoutingAllowed(preferenceType, weightedRoutingMetadata);
}
switch (preferenceType) {
case PREFER_NODES:
final Set<String> nodesIds = Arrays.stream(preference.substring(Preference.PREFER_NODES.type().length() + 1).split(","))
Expand Down

0 comments on commit fa3e1d4

Please sign in to comment.