Skip to content

Commit

Permalink
fixed java style after running precommit locally
Browse files Browse the repository at this point in the history
Signed-off-by: Vinay Krishna Pudyodu <vinkrish.neo@gmail.com>
  • Loading branch information
vinaykpud committed Nov 22, 2024
1 parent 803c15b commit c6e2c80
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -74,7 +75,6 @@ public class TransportSegmentReplicationStatsActionTests extends OpenSearchTestC

private ShardId shardId;


TransportSegmentReplicationStatsAction action;

private final ClusterBlock writeClusterBlock = new ClusterBlock(
Expand Down Expand Up @@ -393,7 +393,8 @@ public void testShardOperationOnSearchReplicaWhenCompletedAndOngoingSegRepStateI

public void testNewResponseWhenAllReplicasReturnResponseCombinesTheResults() {
SegmentReplicationStatsRequest request = new SegmentReplicationStatsRequest();
String[] shards = {"1", "2", "3"};
List<DefaultShardOperationFailedException> shardFailures = new ArrayList<>();
String[] shards = { "1", "2", "3" };
request.shards(shards);

int totalShards = 3;
Expand Down Expand Up @@ -421,7 +422,11 @@ public void testNewResponseWhenAllReplicasReturnResponseCombinesTheResults() {
Set<SegmentReplicationShardStats> 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);
Expand All @@ -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<SegmentReplicationPerGroupStats> responseStats = response.getReplicationStats().get(TEST_INDEX);
SegmentReplicationPerGroupStats primStats = responseStats.get(0);
Set<SegmentReplicationShardStats> 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());
}

Expand All @@ -454,7 +466,8 @@ public void testNewResponseWhenAllReplicasReturnResponseCombinesTheResults() {

public void testNewResponseWhenTwoPrimaryShardsForSameIndex() {
SegmentReplicationStatsRequest request = new SegmentReplicationStatsRequest();
String[] shards = {"1", "2"};
List<DefaultShardOperationFailedException> shardFailures = new ArrayList<>();
String[] shards = { "1", "2" };
request.shards(shards);
int totalShards = 3;
int successfulShards = 3;
Expand All @@ -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<SegmentReplicationPerGroupStats> 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);
}
}
Expand Down

0 comments on commit c6e2c80

Please sign in to comment.