diff --git a/server/src/internalClusterTest/java/org/opensearch/gateway/RecoveryFromGatewayIT.java b/server/src/internalClusterTest/java/org/opensearch/gateway/RecoveryFromGatewayIT.java index 3128b55c17029..adc233ab6d047 100644 --- a/server/src/internalClusterTest/java/org/opensearch/gateway/RecoveryFromGatewayIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/gateway/RecoveryFromGatewayIT.java @@ -793,10 +793,7 @@ public void testShardFetchMultiNodeMultiIndexesUsingBatchAction() { ShardId shardId = clusterSearchShardsGroup.getShardId(); assertEquals(1, clusterSearchShardsGroup.getShards().length); String nodeId = clusterSearchShardsGroup.getShards()[0].currentNodeId(); - GatewayShardStarted gatewayShardStarted = response.getNodesMap() - .get(nodeId) - .getNodeGatewayStartedShardsBatch() - .get(shardId); + GatewayShardStarted gatewayShardStarted = response.getNodesMap().get(nodeId).getNodeGatewayStartedShardsBatch().get(shardId); assertNodeGatewayStartedShardsHappyCase(gatewayShardStarted); } } @@ -951,9 +948,7 @@ private void assertNodeStoreFilesMetadataSuccessCase( assertNotNull(storeFileMetadata.peerRecoveryRetentionLeases()); } - private void assertNodeGatewayStartedShardsHappyCase( - GatewayShardStarted gatewayShardStarted - ) { + private void assertNodeGatewayStartedShardsHappyCase(GatewayShardStarted gatewayShardStarted) { assertNull(gatewayShardStarted.storeException()); assertNotNull(gatewayShardStarted.allocationId()); assertTrue(gatewayShardStarted.primary()); diff --git a/server/src/main/java/org/opensearch/gateway/PrimaryShardAllocator.java b/server/src/main/java/org/opensearch/gateway/PrimaryShardAllocator.java index f76c82478155a..e16e84c95b4b2 100644 --- a/server/src/main/java/org/opensearch/gateway/PrimaryShardAllocator.java +++ b/server/src/main/java/org/opensearch/gateway/PrimaryShardAllocator.java @@ -139,13 +139,17 @@ private static List adaptToNodeStartedShardList(FetchRe return null; } List nodeShardStates = new ArrayList<>(); - shardsState.getData().forEach((node, nodeGatewayStartedShard) -> { nodeShardStates.add(new NodeGatewayShardStarted( - nodeGatewayStartedShard.allocationId(), - nodeGatewayStartedShard.primary(), - nodeGatewayStartedShard.replicationCheckpoint(), - nodeGatewayStartedShard.storeException(), - node - )); }); + shardsState.getData().forEach((node, nodeGatewayStartedShard) -> { + nodeShardStates.add( + new NodeGatewayShardStarted( + nodeGatewayStartedShard.allocationId(), + nodeGatewayStartedShard.primary(), + nodeGatewayStartedShard.replicationCheckpoint(), + nodeGatewayStartedShard.storeException(), + node + ) + ); + }); return nodeShardStates; } @@ -439,10 +443,7 @@ protected static NodeShardsResult buildNodeShardsResult( return new NodeShardsResult(nodeShardStates, numberOfAllocationsFound); } - private static Comparator createActiveShardComparator( - boolean matchAnyShard, - Set inSyncAllocationIds - ) { + private static Comparator createActiveShardComparator(boolean matchAnyShard, Set inSyncAllocationIds) { /** * Orders the active shards copies based on below comparators * 1. No store exception i.e. shard copy is readable diff --git a/server/src/main/java/org/opensearch/gateway/PrimaryShardBatchAllocator.java b/server/src/main/java/org/opensearch/gateway/PrimaryShardBatchAllocator.java index 3f04ac4d2f575..08ce4ab9b3f39 100644 --- a/server/src/main/java/org/opensearch/gateway/PrimaryShardBatchAllocator.java +++ b/server/src/main/java/org/opensearch/gateway/PrimaryShardBatchAllocator.java @@ -99,10 +99,7 @@ public HashMap makeAllocationDecision( // process the received data for (ShardRouting unassignedShard : eligibleShards) { - List nodeShardStates = adaptToNodeShardStates( - unassignedShard, - shardsState - ); + List nodeShardStates = adaptToNodeShardStates(unassignedShard, shardsState); // get allocation decision for this shard shardAllocationDecisions.put(unassignedShard, getAllocationDecision(unassignedShard, allocation, nodeShardStates, logger)); } @@ -135,7 +132,8 @@ private static List adaptToNodeShardStates( // build data for a shard from all the nodes nodeResponses.forEach((node, nodeGatewayStartedShardsBatch) -> { - TransportNodesGatewayStartedShardHelper.GatewayShardStarted shardData = nodeGatewayStartedShardsBatch.getNodeGatewayStartedShardsBatch() + TransportNodesGatewayStartedShardHelper.GatewayShardStarted shardData = nodeGatewayStartedShardsBatch + .getNodeGatewayStartedShardsBatch() .get(unassignedShard.shardId()); nodeShardStates.add( new NodeGatewayShardStarted( diff --git a/server/src/main/java/org/opensearch/gateway/TransportNodesGatewayStartedShardHelper.java b/server/src/main/java/org/opensearch/gateway/TransportNodesGatewayStartedShardHelper.java index 01b944d4390d1..5168cac6f920b 100644 --- a/server/src/main/java/org/opensearch/gateway/TransportNodesGatewayStartedShardHelper.java +++ b/server/src/main/java/org/opensearch/gateway/TransportNodesGatewayStartedShardHelper.java @@ -95,12 +95,7 @@ public static GatewayShardStarted getShardInfoOnLocalNode( exception ); String allocationId = shardStateMetadata.allocationId != null ? shardStateMetadata.allocationId.getId() : null; - return new GatewayShardStarted( - allocationId, - shardStateMetadata.primary, - null, - exception - ); + return new GatewayShardStarted(allocationId, shardStateMetadata.primary, null, exception); } } @@ -241,9 +236,13 @@ public static class NodeGatewayShardStarted extends GatewayShardStarted { private final DiscoveryNode node; - public NodeGatewayShardStarted(String allocationId, boolean primary, - ReplicationCheckpoint replicationCheckpoint, Exception storeException, - DiscoveryNode node) { + public NodeGatewayShardStarted( + String allocationId, + boolean primary, + ReplicationCheckpoint replicationCheckpoint, + Exception storeException, + DiscoveryNode node + ) { super(allocationId, primary, replicationCheckpoint, storeException); this.node = node; } diff --git a/server/src/main/java/org/opensearch/gateway/TransportNodesListGatewayStartedShards.java b/server/src/main/java/org/opensearch/gateway/TransportNodesListGatewayStartedShards.java index cb4470d0c04da..f81e6bb46bb64 100644 --- a/server/src/main/java/org/opensearch/gateway/TransportNodesListGatewayStartedShards.java +++ b/server/src/main/java/org/opensearch/gateway/TransportNodesListGatewayStartedShards.java @@ -53,13 +53,13 @@ import org.opensearch.core.index.shard.ShardId; import org.opensearch.core.xcontent.NamedXContentRegistry; import org.opensearch.env.NodeEnvironment; +import org.opensearch.gateway.TransportNodesGatewayStartedShardHelper.GatewayShardStarted; import org.opensearch.indices.IndicesService; import org.opensearch.indices.replication.checkpoint.ReplicationCheckpoint; import org.opensearch.indices.store.ShardAttributes; import org.opensearch.threadpool.ThreadPool; import org.opensearch.transport.TransportRequest; import org.opensearch.transport.TransportService; -import org.opensearch.gateway.TransportNodesGatewayStartedShardHelper.GatewayShardStarted; import java.io.IOException; import java.util.List; diff --git a/server/src/main/java/org/opensearch/gateway/TransportNodesListGatewayStartedShardsBatch.java b/server/src/main/java/org/opensearch/gateway/TransportNodesListGatewayStartedShardsBatch.java index c6aeca85f984b..d8e83b955d46d 100644 --- a/server/src/main/java/org/opensearch/gateway/TransportNodesListGatewayStartedShardsBatch.java +++ b/server/src/main/java/org/opensearch/gateway/TransportNodesListGatewayStartedShardsBatch.java @@ -27,8 +27,8 @@ import org.opensearch.core.index.shard.ShardId; import org.opensearch.core.xcontent.NamedXContentRegistry; import org.opensearch.env.NodeEnvironment; -import org.opensearch.indices.IndicesService; import org.opensearch.gateway.TransportNodesGatewayStartedShardHelper.GatewayShardStarted; +import org.opensearch.indices.IndicesService; import org.opensearch.indices.store.ShardAttributes; import org.opensearch.threadpool.ThreadPool; import org.opensearch.transport.TransportRequest; @@ -248,8 +248,6 @@ public void writeTo(StreamOutput out) throws IOException { } } - - /** * This is the response from a single node, this is used in {@link NodesGatewayStartedShardsBatch} for creating * node to its response mapping for this transport request.