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 e82f050 commit 0d66292
Show file tree
Hide file tree
Showing 12 changed files with 21 additions and 41 deletions.
2 changes: 1 addition & 1 deletion gradle/run.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 'cluster.routing.allocation.enable', 'all'
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'
Expand Down
4 changes: 0 additions & 4 deletions server/src/main/java/org/opensearch/action/ActionModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -688,9 +688,7 @@ public <Request extends ActionRequest, Response extends ActionResponse> void reg
actions.register(AutoPutMappingAction.INSTANCE, TransportAutoPutMappingAction.class);
actions.register(IndicesAliasesAction.INSTANCE, TransportIndicesAliasesAction.class);
actions.register(UpdateSettingsAction.INSTANCE, TransportUpdateSettingsAction.class);

actions.register(SearchOnlyAction.INSTANCE, TransportSearchOnlyAction.class);

actions.register(AnalyzeAction.INSTANCE, TransportAnalyzeAction.class);
actions.register(PutIndexTemplateAction.INSTANCE, TransportPutIndexTemplateAction.class);
actions.register(GetIndexTemplatesAction.INSTANCE, TransportGetIndexTemplatesAction.class);
Expand Down Expand Up @@ -912,9 +910,7 @@ public void initRestHandlers(Supplier<DiscoveryNodes> nodesInCluster) {
registerHandler.accept(new RestUpgradeAction());
registerHandler.accept(new RestUpgradeStatusAction());
registerHandler.accept(new RestClearIndicesCacheAction());

registerHandler.accept(new RestSearchonlyAction());

registerHandler.accept(new RestIndexAction());
registerHandler.accept(new CreateHandler());
registerHandler.accept(new AutoIdHandler(nodesInCluster));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public SearchOnlyResponse(StreamInput in) throws IOException {

@Override
public void writeTo(StreamOutput out) throws IOException {
out.writeList(new ArrayList<>(nodeResponses)); // Convert Collection to List
out.writeList(new ArrayList<>(nodeResponses));
out.writeBoolean(hasFailures);
out.writeOptionalString(failureReason);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,18 +254,8 @@ 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:
if (isSearchOnlyEnabled) {
computeStatus = getIndexHealthStatus(ClusterHealthStatus.GREEN, computeStatus);
} else {
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 @@ -230,7 +231,12 @@ 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) {
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";
if (primaryRouting.active()) {
if (activeShards == totalShards) {
Expand All @@ -243,6 +249,7 @@ public static ClusterHealthStatus getShardHealth(final ShardRouting primaryRouti
}
}


/**
* Checks if an inactive primary shard should cause the cluster health to go RED.
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Boolean> 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<Boolean> INDEX_BLOCKS_SEARCH_ONLY_SETTING = APIBlock.SEARCH_ONLY.setting();


public static final Setting<Boolean> INDEX_BLOCKS_SEARCH_ONLY_SETTING = APIBlock.SEARCH_ONLY.setting();


public static final String SETTING_VERSION_CREATED = "index.version.created";

public static final Setting<Version> SETTING_INDEX_VERSION_CREATED = Setting.versionSetting(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ public RoutingNodes(ClusterState clusterState, boolean readOnly) {
// also fill replicaSet information
for (final IndexRoutingTable indexRoutingTable : routingTable.indicesRouting().values()) {
for (IndexShardRoutingTable indexShard : indexRoutingTable) {
// TO DO
// assert indexShard.primary != null;
for (ShardRouting shard : indexShard) {
// to get all the shards belonging to an index, including the replicas,
Expand Down Expand Up @@ -183,8 +184,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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -115,6 +116,7 @@ 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;
// TO DO
/*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 "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,7 @@ public final class IndexScopedSettings extends AbstractScopedSettings {
IndexSettings.SEARCHABLE_SNAPSHOT_ID_UUID,
IndexSettings.SEARCHABLE_SNAPSHOT_SHARD_PATH_TYPE,


// Search only setting
// Index Search only setting
IndexSettings.INDEX_SEARCH_ONLY_SETTING,

// Settings for remote translog
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,6 @@ public AllocateUnassignedDecision makeAllocationDecision(
return getAllocationDecision(unassignedShard, allocation, nodeShardStores, result, logger);
}

// Added this
protected AllocateUnassignedDecision getAllocationDecision(
ShardRouting unassignedShard,
RoutingAllocation allocation,
Expand All @@ -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()
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ public void getCheckpointMetadata(
return;
}

// Added this
if (mdFile == null) {
listener.onResponse(new CheckpointInfoResponse(indexShard.getLatestReplicationCheckpoint(), Collections.emptyMap(), null));
} else {
Expand Down

0 comments on commit 0d66292

Please sign in to comment.