From 0c6185baca76193e9b798028c5ccc36152c3be3d Mon Sep 17 00:00:00 2001
From: Prudhvi Godithi
Date: Thu, 6 Feb 2025 12:58:04 -0800
Subject: [PATCH] Upstream fetch
Signed-off-by: Prudhvi Godithi
---
gradle/run.gradle | 2 +-
.../opensearch/cluster/health/ClusterIndexHealth.java | 9 ---------
.../opensearch/cluster/health/ClusterShardHealth.java | 8 +++++++-
.../opensearch/cluster/metadata/IndexMetadata.java | 6 ------
.../org/opensearch/cluster/routing/RoutingNodes.java | 7 ++++++-
.../org/opensearch/cluster/routing/ShardRouting.java | 3 +--
.../ReplicaAfterPrimaryActiveAllocationDecider.java | 4 ----
.../org/opensearch/gateway/ReplicaShardAllocator.java | 11 +----------
.../replication/RemoteStoreReplicationSource.java | 1 -
9 files changed, 16 insertions(+), 35 deletions(-)
diff --git a/gradle/run.gradle b/gradle/run.gradle
index dc620900744e9..dd6eeb956642f 100644
--- a/gradle/run.gradle
+++ b/gradle/run.gradle
@@ -47,7 +47,7 @@ testClusters {
}
setting 'opensearch.experimental.feature.read.write.split.enabled', 'true'
setting 'path.repo', '["/tmp/my-repo"]'
- setting 'node.attr.remote_store', 'true'
+ // setting 'node.attr.remote_store', 'true'
setting 'cluster.remote_store.state.enabled', 'true'
setting 'node.attr.remote_store.segment.repository', 'my-repository'
setting 'node.attr.remote_store.translog.repository', 'my-repository'
diff --git a/server/src/main/java/org/opensearch/cluster/health/ClusterIndexHealth.java b/server/src/main/java/org/opensearch/cluster/health/ClusterIndexHealth.java
index 7791f5f9a795a..7a207a9575fb2 100644
--- a/server/src/main/java/org/opensearch/cluster/health/ClusterIndexHealth.java
+++ b/server/src/main/java/org/opensearch/cluster/health/ClusterIndexHealth.java
@@ -254,15 +254,6 @@ public ClusterIndexHealth(
}
}
ShardRouting primaryShard = indexShardRoutingTable.primaryShard();
- /*if (primaryShard.active()) {
- computeActivePrimaryShards++;
- }
- ClusterHealthStatus shardHealth = ClusterShardHealth.getShardHealth(
- primaryShard,
- activeShardsPerShardId,
- shardRoutingCountPerShardId
- );
- computeStatus = getIndexHealthStatus(shardHealth, computeStatus);*/
if (primaryShard == null) {
// 3. If there is no primary shard:
diff --git a/server/src/main/java/org/opensearch/cluster/health/ClusterShardHealth.java b/server/src/main/java/org/opensearch/cluster/health/ClusterShardHealth.java
index ce9a67911cfdb..afe17531fc4d0 100644
--- a/server/src/main/java/org/opensearch/cluster/health/ClusterShardHealth.java
+++ b/server/src/main/java/org/opensearch/cluster/health/ClusterShardHealth.java
@@ -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;
@@ -230,7 +231,11 @@ public void writeTo(final StreamOutput out) throws IOException {
* Shard health is RED when the primary is not active.
*
*/
- public static ClusterHealthStatus getShardHealth(final ShardRouting primaryRouting, final int activeShards, final int totalShards) {
+ public static ClusterHealthStatus getShardHealth(
+ final ShardRouting primaryRouting,
+ final int activeShards,
+ final int totalShards
+ ) {
// assert primaryRouting != null : "Primary shard routing can't be null";
if (primaryRouting.active()) {
if (activeShards == totalShards) {
@@ -243,6 +248,7 @@ public static ClusterHealthStatus getShardHealth(final ShardRouting primaryRouti
}
}
+
/**
* Checks if an inactive primary shard should cause the cluster health to go RED.
*
diff --git a/server/src/main/java/org/opensearch/cluster/metadata/IndexMetadata.java b/server/src/main/java/org/opensearch/cluster/metadata/IndexMetadata.java
index 2c273bd83fcb1..e648115884941 100644
--- a/server/src/main/java/org/opensearch/cluster/metadata/IndexMetadata.java
+++ b/server/src/main/java/org/opensearch/cluster/metadata/IndexMetadata.java
@@ -575,14 +575,8 @@ public static APIBlock readFrom(StreamInput input) throws IOException {
public static final String SETTING_READ_ONLY_ALLOW_DELETE = APIBlock.READ_ONLY_ALLOW_DELETE.settingName();
public static final Setting INDEX_BLOCKS_READ_ONLY_ALLOW_DELETE_SETTING = APIBlock.READ_ONLY_ALLOW_DELETE.setting();
-
- // public static final String SETTING_BLOCKS_SEARCH_ONLY = APIBlock.SEARCH_ONLY.settingName();
- // public static final Setting INDEX_BLOCKS_SEARCH_ONLY_SETTING = APIBlock.SEARCH_ONLY.setting();
-
-
public static final Setting INDEX_BLOCKS_SEARCH_ONLY_SETTING = APIBlock.SEARCH_ONLY.setting();
-
public static final String SETTING_VERSION_CREATED = "index.version.created";
public static final Setting SETTING_INDEX_VERSION_CREATED = Setting.versionSetting(
diff --git a/server/src/main/java/org/opensearch/cluster/routing/RoutingNodes.java b/server/src/main/java/org/opensearch/cluster/routing/RoutingNodes.java
index 346282fc740d3..1dd223c6e64db 100644
--- a/server/src/main/java/org/opensearch/cluster/routing/RoutingNodes.java
+++ b/server/src/main/java/org/opensearch/cluster/routing/RoutingNodes.java
@@ -183,8 +183,13 @@ private void updateRecoveryCounts(final ShardRouting routing, final boolean incr
final int howMany = increment ? 1 : -1;
assert routing.initializing() : "routing must be initializing: " + routing;
+
+ boolean isSearchOnly = metadata.index(routing.index()).getSettings().getAsBoolean(IndexMetadata.INDEX_BLOCKS_SEARCH_ONLY_SETTING.getKey(), false);
// TODO: check primary == null || primary.active() after all tests properly add ReplicaAfterPrimaryActiveAllocationDecider
- // assert primary == null || primary.assignedToNode() : "shard is initializing but its primary is not assigned to a node";
+ if (!isSearchOnly) {
+ assert primary == null || primary.assignedToNode()
+ : "shard is initializing but its primary is not assigned to a node";
+ }
// Primary shard routing, excluding the relocating primaries.
if (routing.primary() && (primary == null || primary == routing)) {
diff --git a/server/src/main/java/org/opensearch/cluster/routing/ShardRouting.java b/server/src/main/java/org/opensearch/cluster/routing/ShardRouting.java
index 14d9e1163fdf2..e0d2b7fc6f9b3 100644
--- a/server/src/main/java/org/opensearch/cluster/routing/ShardRouting.java
+++ b/server/src/main/java/org/opensearch/cluster/routing/ShardRouting.java
@@ -33,6 +33,7 @@
package org.opensearch.cluster.routing;
import org.opensearch.Version;
+import org.opensearch.cluster.metadata.IndexMetadata;
import org.opensearch.cluster.routing.RecoverySource.ExistingStoreRecoverySource;
import org.opensearch.cluster.routing.RecoverySource.PeerRecoverySource;
import org.opensearch.cluster.routing.allocation.allocator.BalancedShardsAllocator;
@@ -115,8 +116,6 @@ protected ShardRouting(
assert !(state == ShardRoutingState.UNASSIGNED && unassignedInfo == null) : "unassigned shard must be created with meta";
assert (state == ShardRoutingState.UNASSIGNED || state == ShardRoutingState.INITIALIZING) == (recoverySource != null)
: "recovery source only available on unassigned or initializing shard but was " + state;
- /*assert recoverySource == null || recoverySource == PeerRecoverySource.INSTANCE || primary || searchOnly
- : "replica shards always recover from primary";*/
assert (currentNodeId == null) == (state == ShardRoutingState.UNASSIGNED) : "unassigned shard must not be assigned to a node "
+ this;
}
diff --git a/server/src/main/java/org/opensearch/cluster/routing/allocation/decider/ReplicaAfterPrimaryActiveAllocationDecider.java b/server/src/main/java/org/opensearch/cluster/routing/allocation/decider/ReplicaAfterPrimaryActiveAllocationDecider.java
index 0f07420e21a3e..6349189e7186e 100644
--- a/server/src/main/java/org/opensearch/cluster/routing/allocation/decider/ReplicaAfterPrimaryActiveAllocationDecider.java
+++ b/server/src/main/java/org/opensearch/cluster/routing/allocation/decider/ReplicaAfterPrimaryActiveAllocationDecider.java
@@ -57,10 +57,6 @@ public Decision canAllocate(ShardRouting shardRouting, RoutingAllocation allocat
return allocation.decision(Decision.YES, NAME, "shard is primary and can be allocated");
}
ShardRouting primary = allocation.routingNodes().activePrimary(shardRouting.shardId());
- // Added this
- /*if (primary == null && !shardRouting.isSearchOnly()) {
- return allocation.decision(Decision.NO, NAME, "primary shard for this replica is not yet active");
- }*/
if (primary == null) {
boolean indexIsSearchOnly = allocation.metadata()
.getIndexSafe(shardRouting.index())
diff --git a/server/src/main/java/org/opensearch/gateway/ReplicaShardAllocator.java b/server/src/main/java/org/opensearch/gateway/ReplicaShardAllocator.java
index 5b790d702e95b..3e4d0a0d88ab1 100644
--- a/server/src/main/java/org/opensearch/gateway/ReplicaShardAllocator.java
+++ b/server/src/main/java/org/opensearch/gateway/ReplicaShardAllocator.java
@@ -229,7 +229,6 @@ public AllocateUnassignedDecision makeAllocationDecision(
return getAllocationDecision(unassignedShard, allocation, nodeShardStores, result, logger);
}
- // Added this
protected AllocateUnassignedDecision getAllocationDecision(
ShardRouting unassignedShard,
RoutingAllocation allocation,
@@ -254,6 +253,7 @@ protected AllocateUnassignedDecision getAllocationDecision(
if (primaryShard == null) {
// Determine if the index is configured for search-only.
+
boolean isIndexSearchOnly = allocation.metadata()
.getIndexSafe(unassignedShard.index())
.getSettings()
@@ -284,15 +284,6 @@ protected AllocateUnassignedDecision getAllocationDecision(
return AllocateUnassignedDecision.yes(selectedCandidate, null, new ArrayList<>(), false);
}
- /* force methad an allocation using the first available data node.
- if (!dataNodes.isEmpty()) {
- // forcibly picks the first node
- DiscoveryNode forcedCandidate = dataNodes.iterator().next();
- logger.info("Forcing allocation of search-only replica {} to node {} because no candidate qualified normally", unassignedShard, forcedCandidate);
- return AllocateUnassignedDecision.yes(forcedCandidate, null, new ArrayList<>(), false);
- }*/
-
-
// If there are no data nodes available, delay allocation.
return AllocateUnassignedDecision.delayed(0L, 0L, null);
} else {
diff --git a/server/src/main/java/org/opensearch/indices/replication/RemoteStoreReplicationSource.java b/server/src/main/java/org/opensearch/indices/replication/RemoteStoreReplicationSource.java
index 9fa575a18a0e1..c323b9c56106a 100644
--- a/server/src/main/java/org/opensearch/indices/replication/RemoteStoreReplicationSource.java
+++ b/server/src/main/java/org/opensearch/indices/replication/RemoteStoreReplicationSource.java
@@ -74,7 +74,6 @@ public void getCheckpointMetadata(
return;
}
- // Added this
if (mdFile == null) {
listener.onResponse(new CheckpointInfoResponse(indexShard.getLatestReplicationCheckpoint(), Collections.emptyMap(), null));
} else {