From c6e2c808c185c138b63a48353346af132cc48817 Mon Sep 17 00:00:00 2001 From: Vinay Krishna Pudyodu Date: Fri, 22 Nov 2024 13:57:49 -0800 Subject: [PATCH] fixed java style after running precommit locally Signed-off-by: Vinay Krishna Pudyodu --- ...ransportSegmentReplicationStatsAction.java | 22 ++++----- ...ortSegmentReplicationStatsActionTests.java | 46 +++++++++++++------ 2 files changed, 41 insertions(+), 27 deletions(-) diff --git a/server/src/main/java/org/opensearch/action/admin/indices/replication/TransportSegmentReplicationStatsAction.java b/server/src/main/java/org/opensearch/action/admin/indices/replication/TransportSegmentReplicationStatsAction.java index 38a5b1c05c8cf..ca408e5433837 100644 --- a/server/src/main/java/org/opensearch/action/admin/indices/replication/TransportSegmentReplicationStatsAction.java +++ b/server/src/main/java/org/opensearch/action/admin/indices/replication/TransportSegmentReplicationStatsAction.java @@ -166,9 +166,7 @@ protected SegmentReplicationStatsRequest readRequestFrom(StreamInput in) throws @Override protected SegmentReplicationShardStatsResponse shardOperation(SegmentReplicationStatsRequest request, ShardRouting shardRouting) { ShardId shardId = shardRouting.shardId(); - IndexShard indexShard = indicesService - .indexServiceSafe(shardId.getIndex()) - .getShard(shardId.id()); + IndexShard indexShard = indicesService.indexServiceSafe(shardId.getIndex()).getShard(shardId.id()); if (indexShard.indexSettings().isSegRepEnabledOrRemoteNode() == false) { return null; @@ -237,28 +235,24 @@ private long calculateCheckpointsBehind( return 0; } - if(completedSegmentReplicationState == null || - completedSegmentReplicationState.getReplicationCheckpoint() == null) { - return ongoingSegmentReplicationState - .getReplicationCheckpoint() - .getSegmentInfosVersion(); + if (completedSegmentReplicationState == null || completedSegmentReplicationState.getReplicationCheckpoint() == null) { + return ongoingSegmentReplicationState.getReplicationCheckpoint().getSegmentInfosVersion(); } - return ongoingSegmentReplicationState.getReplicationCheckpoint().getSegmentInfosVersion() - - completedSegmentReplicationState.getReplicationCheckpoint().getSegmentInfosVersion(); + return ongoingSegmentReplicationState.getReplicationCheckpoint().getSegmentInfosVersion() - completedSegmentReplicationState + .getReplicationCheckpoint() + .getSegmentInfosVersion(); } private long calculateBytesBehind( SegmentReplicationState completedSegmentReplicationState, SegmentReplicationState ongoingSegmentReplicationState ) { - if (ongoingSegmentReplicationState == null || - ongoingSegmentReplicationState.getReplicationCheckpoint() == null) { + if (ongoingSegmentReplicationState == null || ongoingSegmentReplicationState.getReplicationCheckpoint() == null) { return 0; } - if (completedSegmentReplicationState == null || - completedSegmentReplicationState.getReplicationCheckpoint() == null) { + if (completedSegmentReplicationState == null || completedSegmentReplicationState.getReplicationCheckpoint() == null) { Store.RecoveryDiff diff = Store.segmentReplicationDiff( ongoingSegmentReplicationState.getReplicationCheckpoint().getMetadataMap(), Collections.emptyMap() diff --git a/server/src/test/java/org/opensearch/action/admin/indices/replication/TransportSegmentReplicationStatsActionTests.java b/server/src/test/java/org/opensearch/action/admin/indices/replication/TransportSegmentReplicationStatsActionTests.java index cbb737d92972f..a69f5a9c67537 100644 --- a/server/src/test/java/org/opensearch/action/admin/indices/replication/TransportSegmentReplicationStatsActionTests.java +++ b/server/src/test/java/org/opensearch/action/admin/indices/replication/TransportSegmentReplicationStatsActionTests.java @@ -8,7 +8,6 @@ package org.opensearch.action.admin.indices.replication; -import org.junit.Before; import org.opensearch.Version; import org.opensearch.action.support.ActionFilters; import org.opensearch.cluster.ClusterState; @@ -27,6 +26,7 @@ import org.opensearch.cluster.routing.TestShardRouting; import org.opensearch.cluster.service.ClusterService; import org.opensearch.common.settings.Settings; +import org.opensearch.core.action.support.DefaultShardOperationFailedException; import org.opensearch.core.index.Index; import org.opensearch.core.index.shard.ShardId; import org.opensearch.core.rest.RestStatus; @@ -45,14 +45,15 @@ import org.opensearch.indices.replication.common.ReplicationType; import org.opensearch.test.OpenSearchTestCase; import org.opensearch.transport.TransportService; +import org.junit.Before; +import java.util.ArrayList; import java.util.EnumSet; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; -import static java.util.Collections.EMPTY_LIST; import static java.util.Collections.emptyMap; import static java.util.Collections.emptySet; import static org.mockito.ArgumentMatchers.any; @@ -74,7 +75,6 @@ public class TransportSegmentReplicationStatsActionTests extends OpenSearchTestC private ShardId shardId; - TransportSegmentReplicationStatsAction action; private final ClusterBlock writeClusterBlock = new ClusterBlock( @@ -393,7 +393,8 @@ public void testShardOperationOnSearchReplicaWhenCompletedAndOngoingSegRepStateI public void testNewResponseWhenAllReplicasReturnResponseCombinesTheResults() { SegmentReplicationStatsRequest request = new SegmentReplicationStatsRequest(); - String[] shards = {"1", "2", "3"}; + List shardFailures = new ArrayList<>(); + String[] shards = { "1", "2", "3" }; request.shards(shards); int totalShards = 3; @@ -421,7 +422,11 @@ public void testNewResponseWhenAllReplicasReturnResponseCombinesTheResults() { Set segmentReplicationShardStats = new HashSet<>(); SegmentReplicationShardStats segmentReplicationShardStatsOfReplica = new SegmentReplicationShardStats(allocIdOne, 0, 0, 0, 0, 0); segmentReplicationShardStats.add(segmentReplicationShardStatsOfReplica); - SegmentReplicationPerGroupStats segmentReplicationPerGroupStats = new SegmentReplicationPerGroupStats(shardIdOne, segmentReplicationShardStats, 0); + SegmentReplicationPerGroupStats segmentReplicationPerGroupStats = new SegmentReplicationPerGroupStats( + shardIdOne, + segmentReplicationShardStats, + 0 + ); SegmentReplicationState segmentReplicationState = mock(SegmentReplicationState.class); SegmentReplicationShardStats segmentReplicationShardStatsFromSearchReplica = mock(SegmentReplicationShardStats.class); @@ -435,14 +440,21 @@ public void testNewResponseWhenAllReplicasReturnResponseCombinesTheResults() { ); SegmentReplicationStatsResponse response = action.newResponse( - request, totalShards, successfulShards, failedShard, responses, EMPTY_LIST, ClusterState.EMPTY_STATE); + request, + totalShards, + successfulShards, + failedShard, + responses, + shardFailures, + ClusterState.EMPTY_STATE + ); List responseStats = response.getReplicationStats().get(TEST_INDEX); SegmentReplicationPerGroupStats primStats = responseStats.get(0); Set segRpShardStatsSet = primStats.getReplicaStats(); - for (SegmentReplicationShardStats segRpShardStats: segRpShardStatsSet) { - if(segRpShardStats.getAllocationId().equals(allocIdOne)) { + for (SegmentReplicationShardStats segRpShardStats : segRpShardStatsSet) { + if (segRpShardStats.getAllocationId().equals(allocIdOne)) { assertEquals(segmentReplicationState, segRpShardStats.getCurrentReplicationState()); } @@ -454,7 +466,8 @@ public void testNewResponseWhenAllReplicasReturnResponseCombinesTheResults() { public void testNewResponseWhenTwoPrimaryShardsForSameIndex() { SegmentReplicationStatsRequest request = new SegmentReplicationStatsRequest(); - String[] shards = {"1", "2"}; + List shardFailures = new ArrayList<>(); + String[] shards = { "1", "2" }; request.shards(shards); int totalShards = 3; int successfulShards = 3; @@ -478,16 +491,23 @@ public void testNewResponseWhenTwoPrimaryShardsForSameIndex() { ); SegmentReplicationStatsResponse response = action.newResponse( - request, totalShards, successfulShards, failedShard, responses, EMPTY_LIST, ClusterState.EMPTY_STATE); + request, + totalShards, + successfulShards, + failedShard, + responses, + shardFailures, + ClusterState.EMPTY_STATE + ); List responseStats = response.getReplicationStats().get(TEST_INDEX); - for (SegmentReplicationPerGroupStats primStat: responseStats) { - if(primStat.getShardId().equals(shardIdOne)) { + for (SegmentReplicationPerGroupStats primStat : responseStats) { + if (primStat.getShardId().equals(shardIdOne)) { assertEquals(segmentReplicationPerGroupStatsOne, primStat); } - if(primStat.getShardId().equals(shardIdTwo)) { + if (primStat.getShardId().equals(shardIdTwo)) { assertEquals(segmentReplicationPerGroupStatsTwo, primStat); } }