Skip to content

Commit

Permalink
Upstream fetch
Browse files Browse the repository at this point in the history
Signed-off-by: Prudhvi Godithi <[email protected]>
  • Loading branch information
prudhvigodithi committed Feb 7, 2025
1 parent db5212b commit 8f1d4ea
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import org.opensearch.action.ActionRequestBuilder;
import org.opensearch.action.support.clustermanager.AcknowledgedResponse;
import org.opensearch.client.OpenSearchClient;
import org.opensearch.common.annotation.PublicApi;
import org.opensearch.transport.client.OpenSearchClient;

@PublicApi(since = "1.0.0")
public class SearchOnlyRequestBuilder extends ActionRequestBuilder<SearchOnlyRequest, AcknowledgedResponse> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ protected void clusterManagerOperation(
final String customDataPath = IndexMetadata.INDEX_DATA_PATH_SETTING.get(state.metadata().index(index).getSettings());
for (IndexShardRoutingTable routing : indexShardRoutingTables) {
final int shardId = routing.shardId().id();
ClusterShardHealth shardHealth = new ClusterShardHealth(shardId, routing);
ClusterShardHealth shardHealth = new ClusterShardHealth(shardId, routing, state.metadata().index(index));
if (request.shardStatuses().contains(shardHealth.getStatus())) {
shardsToFetch.add(Tuple.tuple(routing.shardId(), customDataPath));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public ClusterIndexHealth(final IndexMetadata indexMetadata, final IndexRoutingT
shards = new HashMap<>();
for (IndexShardRoutingTable shardRoutingTable : indexRoutingTable) {
int shardId = shardRoutingTable.shardId().id();
shards.put(shardId, new ClusterShardHealth(shardId, shardRoutingTable));
shards.put(shardId, new ClusterShardHealth(shardId, shardRoutingTable, indexMetadata));
}

// update the index status
Expand Down Expand Up @@ -218,7 +218,7 @@ public ClusterIndexHealth(
if (isShardLevelHealthRequired) {
for (IndexShardRoutingTable indexShardRoutingTable : indexRoutingTable) {
int shardId = indexShardRoutingTable.shardId().id();
ClusterShardHealth shardHealth = new ClusterShardHealth(shardId, indexShardRoutingTable);
ClusterShardHealth shardHealth = new ClusterShardHealth(shardId, indexShardRoutingTable, indexMetadata);
if (shardHealth.isPrimaryActive()) {
computeActivePrimaryShards++;
}
Expand Down Expand Up @@ -268,7 +268,8 @@ public ClusterIndexHealth(
ClusterHealthStatus shardHealth = ClusterShardHealth.getShardHealth(
primaryShard,
activeShardsPerShardId,
shardRoutingCountPerShardId
shardRoutingCountPerShardId,
indexMetadata
);
computeStatus = getIndexHealthStatus(shardHealth, computeStatus);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

package org.opensearch.cluster.health;

import org.opensearch.cluster.metadata.IndexMetadata;
import org.opensearch.cluster.routing.IndexShardRoutingTable;
import org.opensearch.cluster.routing.RecoverySource;
import org.opensearch.cluster.routing.ShardRouting;
Expand Down Expand Up @@ -113,7 +114,7 @@ public final class ClusterShardHealth implements Writeable, ToXContentFragment {
private int delayedUnassignedShards;
private final boolean primaryActive;

public ClusterShardHealth(final int shardId, final IndexShardRoutingTable shardRoutingTable) {
public ClusterShardHealth(final int shardId, final IndexShardRoutingTable shardRoutingTable, final IndexMetadata indexMetadata) {
this.shardId = shardId;
int computeActiveShards = 0;
int computeRelocatingShards = 0;
Expand All @@ -139,13 +140,13 @@ public ClusterShardHealth(final int shardId, final IndexShardRoutingTable shardR
}
}
final ShardRouting primaryRouting = shardRoutingTable.primaryShard();
this.status = getShardHealth(primaryRouting, computeActiveShards, shardRoutingTable.size());
this.status = getShardHealth(primaryRouting, computeActiveShards, shardRoutingTable.size(), indexMetadata);
this.activeShards = computeActiveShards;
this.relocatingShards = computeRelocatingShards;
this.initializingShards = computeInitializingShards;
this.unassignedShards = computeUnassignedShards;
this.delayedUnassignedShards = computeDelayedUnassignedShards;
this.primaryActive = primaryRouting.active();
this.primaryActive = primaryRouting != null && primaryRouting.active();
}

public ClusterShardHealth(final StreamInput in) throws IOException {
Expand Down Expand Up @@ -230,16 +231,23 @@ public void writeTo(final StreamOutput out) throws IOException {
* Shard health is RED when the primary is not active.
* </p>
*/
public static ClusterHealthStatus getShardHealth(final ShardRouting primaryRouting, final int activeShards, final int totalShards) {
// TO DO
// assert primaryRouting != null : "Primary shard routing can't be null";
public static ClusterHealthStatus getShardHealth(final ShardRouting primaryRouting, final int activeShards, final int totalShards, final IndexMetadata indexMetadata) {
if (primaryRouting == null) {
boolean isSearchOnlyEnabled = indexMetadata.getSettings()
.getAsBoolean(IndexMetadata.INDEX_BLOCKS_SEARCH_ONLY_SETTING.getKey(), false);
return isSearchOnlyEnabled ? ClusterHealthStatus.GREEN : ClusterHealthStatus.RED;
}

if (primaryRouting.active()) {
// If primary is active, check if all replicas are active
if (activeShards == totalShards) {
return ClusterHealthStatus.GREEN;
} else {
// Primary is active but some replicas are not
return ClusterHealthStatus.YELLOW;
}
} else {
// Primary is not active, determine health based on recovery state
return getInactivePrimaryHealth(primaryRouting);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package org.opensearch.rest.action.admin.indices;

import org.opensearch.client.node.NodeClient;
import org.opensearch.core.common.Strings;
import org.opensearch.rest.BaseRestHandler;
import org.opensearch.rest.RestRequest;
import org.opensearch.rest.action.RestToXContentListener;
import org.opensearch.transport.client.node.NodeClient;

import java.util.List;

Expand Down

0 comments on commit 8f1d4ea

Please sign in to comment.