Skip to content

Commit

Permalink
Spotless changes
Browse files Browse the repository at this point in the history
Signed-off-by: Lakshya Taragi <lakshya.taragi@gmail.com>
  • Loading branch information
ltaragi committed Oct 20, 2024
1 parent a38968e commit eb39c25
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,8 @@ public void testSnapshotStatusFailuresWithIndexFilter() throws Exception {
.execute()
.actionGet()
);
String cause = "index list filter is supported only when a single 'repository' is passed, but found 'repository' param = [_all]";
String cause =
"index list filter is supported only when a single 'repository' is passed, but found 'repository' param = [_all]";
assertTrue(ex.getMessage().contains(cause));
});

Expand Down Expand Up @@ -840,7 +841,8 @@ public void testSnapshotStatusFailuresWithIndexFilter() throws Exception {
.execute()
.actionGet()
);
String cause = "index list filter is supported only when a single 'snapshot' is passed, but found 'snapshot' param = [[test-snap-1, test-snap-2]]";
String cause =
"index list filter is supported only when a single 'snapshot' is passed, but found 'snapshot' param = [[test-snap-1, test-snap-2]]";
assertTrue(ex.getMessage().contains(cause));
});

Expand Down Expand Up @@ -918,8 +920,6 @@ public void testSnapshotStatusShardLimitOfResponseForInProgressSnapshot() throws
.put("wait_after_unblock", 200)
);



logger.info("Create indices");
String index1 = "test-idx-1";
String index2 = "test-idx-2";
Expand All @@ -937,11 +937,7 @@ public void testSnapshotStatusShardLimitOfResponseForInProgressSnapshot() throws
logger.info("Create completed snapshot");
String completedSnapshot = "test-completed-snapshot";
String blockedNode = blockNodeWithIndex(repositoryName, index1);
client().admin()
.cluster()
.prepareCreateSnapshot(repositoryName, completedSnapshot)
.setWaitForCompletion(false)
.get();
client().admin().cluster().prepareCreateSnapshot(repositoryName, completedSnapshot).setWaitForCompletion(false).get();
waitForBlock(blockedNode, repositoryName, TimeValue.timeValueSeconds(60));
unblockNode(repositoryName, blockedNode);
waitForCompletion(repositoryName, completedSnapshot, TimeValue.timeValueSeconds(60));
Expand All @@ -955,11 +951,7 @@ public void testSnapshotStatusShardLimitOfResponseForInProgressSnapshot() throws
logger.info("Create in-progress snapshot");
String inProgressSnapshot = "test-in-progress-snapshot";
blockedNode = blockNodeWithIndex(repositoryName, index1);
client().admin()
.cluster()
.prepareCreateSnapshot(repositoryName, inProgressSnapshot)
.setWaitForCompletion(false)
.get();
client().admin().cluster().prepareCreateSnapshot(repositoryName, inProgressSnapshot).setWaitForCompletion(false).get();
waitForBlock(blockedNode, repositoryName, TimeValue.timeValueSeconds(60));
List<SnapshotStatus> snapshotStatuses = client().admin()
.cluster()
Expand All @@ -981,7 +973,12 @@ public void testSnapshotStatusShardLimitOfResponseForInProgressSnapshot() throws
assertBusy(() -> {
CircuitBreakingException exception = expectThrows(
CircuitBreakingException.class,
() -> client().admin().cluster().prepareSnapshotStatus(repositoryName).setSnapshots(inProgressSnapshot).execute().actionGet()
() -> client().admin()
.cluster()
.prepareSnapshotStatus(repositoryName)
.setSnapshots(inProgressSnapshot)
.execute()
.actionGet()
);
assertEquals(exception.status(), RestStatus.TOO_MANY_REQUESTS);
assertTrue(
Expand All @@ -993,7 +990,13 @@ public void testSnapshotStatusShardLimitOfResponseForInProgressSnapshot() throws
assertBusy(() -> {
CircuitBreakingException exception = expectThrows(
CircuitBreakingException.class,
() -> client().admin().cluster().prepareSnapshotStatus(repositoryName).setSnapshots(inProgressSnapshot).setIndices(index1, index2).execute().actionGet()
() -> client().admin()
.cluster()
.prepareSnapshotStatus(repositoryName)
.setSnapshots(inProgressSnapshot)
.setIndices(index1, index2)
.execute()
.actionGet()
);
assertEquals(exception.status(), RestStatus.TOO_MANY_REQUESTS);
assertTrue(
Expand All @@ -1013,12 +1016,18 @@ public void testSnapshotStatusShardLimitOfResponseForInProgressSnapshot() throws
.prepareSnapshotStatus(repositoryName)
.setSnapshots(inProgressSnapshot)
.get()
.getSnapshots().get(0);
.getSnapshots()
.get(0);
assertEquals(3, inProgressSnapshotStatus.getShards().size());

CircuitBreakingException exception = expectThrows(
CircuitBreakingException.class,
() -> client().admin().cluster().prepareSnapshotStatus(repositoryName).setSnapshots(inProgressSnapshot, completedSnapshot).execute().actionGet()
() -> client().admin()
.cluster()
.prepareSnapshotStatus(repositoryName)
.setSnapshots(inProgressSnapshot, completedSnapshot)
.execute()
.actionGet()
);
assertEquals(exception.status(), RestStatus.TOO_MANY_REQUESTS);
assertTrue(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ public ActionRequestValidationException validate() {
}
if (indices.length != 0) {
if (repository.equals("_all")) {
String error = "index list filter is supported only when a single 'repository' is passed, but found 'repository' param = [_all]";
String error =

Check warning on line 130 in server/src/main/java/org/opensearch/action/admin/cluster/snapshots/status/SnapshotsStatusRequest.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/action/admin/cluster/snapshots/status/SnapshotsStatusRequest.java#L130

Added line #L130 was not covered by tests
"index list filter is supported only when a single 'repository' is passed, but found 'repository' param = [_all]";
validationException = addValidationError(error, validationException);

Check warning on line 132 in server/src/main/java/org/opensearch/action/admin/cluster/snapshots/status/SnapshotsStatusRequest.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/action/admin/cluster/snapshots/status/SnapshotsStatusRequest.java#L132

Added line #L132 was not covered by tests
}
if (snapshots.length != 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ protected void clusterManagerOperation(
final ClusterState state,
final ActionListener<SnapshotsStatusResponse> listener
) throws Exception {
requestSetup(request);
setupForRequest(request);

Check warning on line 154 in server/src/main/java/org/opensearch/action/admin/cluster/snapshots/status/TransportSnapshotsStatusAction.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/action/admin/cluster/snapshots/status/TransportSnapshotsStatusAction.java#L154

Added line #L154 was not covered by tests

final SnapshotsInProgress snapshotsInProgress = state.custom(SnapshotsInProgress.TYPE, SnapshotsInProgress.EMPTY);
List<SnapshotsInProgress.Entry> currentSnapshots = SnapshotsService.currentSnapshots(
Expand Down Expand Up @@ -193,21 +193,21 @@ protected void clusterManagerOperation(

}

private void requestSetup(SnapshotsStatusRequest request) {
private void setupForRequest(SnapshotsStatusRequest request) {
requestedIndexNames = new HashSet<>(Arrays.asList(request.indices()));

Check warning on line 197 in server/src/main/java/org/opensearch/action/admin/cluster/snapshots/status/TransportSnapshotsStatusAction.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/action/admin/cluster/snapshots/status/TransportSnapshotsStatusAction.java#L197

Added line #L197 was not covered by tests
requestUsesIndexFilter = requestedIndexNames.isEmpty() == false;
totalShardsRequiredInResponse = 0;
maximumAllowedShardCount = clusterService.getClusterSettings().get(MAX_SHARDS_ALLOWED_IN_STATUS_API);
}

Check warning on line 201 in server/src/main/java/org/opensearch/action/admin/cluster/snapshots/status/TransportSnapshotsStatusAction.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/action/admin/cluster/snapshots/status/TransportSnapshotsStatusAction.java#L199-L201

Added lines #L199 - L201 were not covered by tests


/*
* To get the node IDs of the relevant (according to the index filter) shards which are part of current snapshots
* It also deals with any missing indices (for index-filter case) and calculates the number of shards contributed by all
* the current snapshots to the total count (irrespective of index-filter)
* If this count exceeds the limit, CircuitBreakingException is thrown
* */
private Set<String> getNodeIdsOfCurrentSnapshots(final SnapshotsStatusRequest request, List<SnapshotsInProgress.Entry> currentSnapshots) throws CircuitBreakingException {
private Set<String> getNodeIdsOfCurrentSnapshots(final SnapshotsStatusRequest request, List<SnapshotsInProgress.Entry> currentSnapshots)
throws CircuitBreakingException {
Set<String> nodesIdsOfCurrentSnapshotShards = new HashSet<>();
int totalShardsAcrossCurrentSnapshots = 0;

Check warning on line 212 in server/src/main/java/org/opensearch/action/admin/cluster/snapshots/status/TransportSnapshotsStatusAction.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/action/admin/cluster/snapshots/status/TransportSnapshotsStatusAction.java#L211-L212

Added lines #L211 - L212 were not covered by tests

Expand All @@ -217,7 +217,8 @@ private Set<String> getNodeIdsOfCurrentSnapshots(final SnapshotsStatusRequest re
// index-filter is allowed only for a single snapshot, which has to be this one
// first check if any requested indices are missing from this current snapshot

final Set<String> indicesInCurrentSnapshot = currentSnapshotEntry.indices().stream()
final Set<String> indicesInCurrentSnapshot = currentSnapshotEntry.indices()
.stream()
.map(IndexId::getName)
.collect(Collectors.toSet());

Check warning on line 223 in server/src/main/java/org/opensearch/action/admin/cluster/snapshots/status/TransportSnapshotsStatusAction.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/action/admin/cluster/snapshots/status/TransportSnapshotsStatusAction.java#L220-L223

Added lines #L220 - L223 were not covered by tests

Expand All @@ -226,15 +227,22 @@ private Set<String> getNodeIdsOfCurrentSnapshots(final SnapshotsStatusRequest re
.collect(Collectors.toSet());

Check warning on line 227 in server/src/main/java/org/opensearch/action/admin/cluster/snapshots/status/TransportSnapshotsStatusAction.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/action/admin/cluster/snapshots/status/TransportSnapshotsStatusAction.java#L227

Added line #L227 was not covered by tests

if (indicesNotFound.isEmpty() == false) {
handleIndexNotFound(requestedIndexNames, indicesNotFound, request, currentSnapshotEntry.snapshot().getSnapshotId().getName(), false);
handleIndexNotFound(

Check warning on line 230 in server/src/main/java/org/opensearch/action/admin/cluster/snapshots/status/TransportSnapshotsStatusAction.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/action/admin/cluster/snapshots/status/TransportSnapshotsStatusAction.java#L230

Added line #L230 was not covered by tests
requestedIndexNames,
indicesNotFound,
request,
currentSnapshotEntry.snapshot().getSnapshotId().getName(),

Check warning on line 234 in server/src/main/java/org/opensearch/action/admin/cluster/snapshots/status/TransportSnapshotsStatusAction.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/action/admin/cluster/snapshots/status/TransportSnapshotsStatusAction.java#L234

Added line #L234 was not covered by tests
false
);
}
// the actual no. of shards contributed by this current snapshot will now be calculated
} else {

Check warning on line 239 in server/src/main/java/org/opensearch/action/admin/cluster/snapshots/status/TransportSnapshotsStatusAction.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/action/admin/cluster/snapshots/status/TransportSnapshotsStatusAction.java#L239

Added line #L239 was not covered by tests
// all shards of this current snapshot are required in response
totalShardsAcrossCurrentSnapshots = currentSnapshotEntry.shards().size();

Check warning on line 241 in server/src/main/java/org/opensearch/action/admin/cluster/snapshots/status/TransportSnapshotsStatusAction.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/action/admin/cluster/snapshots/status/TransportSnapshotsStatusAction.java#L241

Added line #L241 was not covered by tests
}

for (final Map.Entry<ShardId, SnapshotsInProgress.ShardSnapshotStatus> shardStatusEntry : currentSnapshotEntry.shards().entrySet()) {
for (final Map.Entry<ShardId, SnapshotsInProgress.ShardSnapshotStatus> shardStatusEntry : currentSnapshotEntry.shards()
.entrySet()) {
SnapshotsInProgress.ShardSnapshotStatus shardStatus = shardStatusEntry.getValue();
boolean indexPresentInFilter = requestedIndexNames.contains(shardStatusEntry.getKey().getIndexName());

Check warning on line 247 in server/src/main/java/org/opensearch/action/admin/cluster/snapshots/status/TransportSnapshotsStatusAction.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/action/admin/cluster/snapshots/status/TransportSnapshotsStatusAction.java#L245-L247

Added lines #L245 - L247 were not covered by tests

Expand All @@ -261,7 +269,8 @@ private Set<String> getNodeIdsOfCurrentSnapshots(final SnapshotsStatusRequest re
// index-filter is allowed only for a single snapshot. If index-filter is being used and limit got exceeded,
// this snapshot is current and its relevant indices contribute more shards than the limit

// if index-filter is not being used and limit got exceed, there could be more shards required in response coming from completed snapshots
// if index-filter is not being used and limit got exceed, there could be more shards required in response coming from completed
// snapshots
// but since the limit is already exceeded, we can fail request here
boolean couldInvolveMoreShards = requestUsesIndexFilter == false;
handleMaximumAllowedShardCountExceeded(request.repository(), totalShardsRequiredInResponse, couldInvolveMoreShards);

Check warning on line 276 in server/src/main/java/org/opensearch/action/admin/cluster/snapshots/status/TransportSnapshotsStatusAction.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/action/admin/cluster/snapshots/status/TransportSnapshotsStatusAction.java#L276

Added line #L276 was not covered by tests
Expand Down Expand Up @@ -669,16 +678,28 @@ private void handleIndexNotFound(
// remove unavailable indices from the set to be processed
indicesToProcess.removeAll(indicesNotFound);

Check warning on line 679 in server/src/main/java/org/opensearch/action/admin/cluster/snapshots/status/TransportSnapshotsStatusAction.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/action/admin/cluster/snapshots/status/TransportSnapshotsStatusAction.java#L679

Added line #L679 was not covered by tests
} else {
String cause = "indices [" + indices + "] missing in snapshot [" + snapshotName + "] of repository [" + request.repository() + "]";
String cause = "indices ["

Check warning on line 681 in server/src/main/java/org/opensearch/action/admin/cluster/snapshots/status/TransportSnapshotsStatusAction.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/action/admin/cluster/snapshots/status/TransportSnapshotsStatusAction.java#L681

Added line #L681 was not covered by tests
+ indices
+ "] missing in snapshot ["
+ snapshotName
+ "] of repository ["
+ request.repository()

Check warning on line 686 in server/src/main/java/org/opensearch/action/admin/cluster/snapshots/status/TransportSnapshotsStatusAction.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/action/admin/cluster/snapshots/status/TransportSnapshotsStatusAction.java#L686

Added line #L686 was not covered by tests
+ "]";
throw new IndexNotFoundException(indices, new IllegalArgumentException(cause));

Check warning on line 688 in server/src/main/java/org/opensearch/action/admin/cluster/snapshots/status/TransportSnapshotsStatusAction.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/action/admin/cluster/snapshots/status/TransportSnapshotsStatusAction.java#L688

Added line #L688 was not covered by tests
}
}

private void handleMaximumAllowedShardCountExceeded(String repositoryName, int totalContributingShards, boolean couldInvolveMoreShards) throws CircuitBreakingException {
private void handleMaximumAllowedShardCountExceeded(String repositoryName, int totalContributingShards, boolean couldInvolveMoreShards)
throws CircuitBreakingException {
String shardCount = "[" + totalContributingShards + (couldInvolveMoreShards ? "+" : "") + "]";
String message = "[" + repositoryName + "] Total shard count " + shardCount + " is more than the maximum allowed value of shard count [" +
maximumAllowedShardCount + "] for snapshot status request. Try narrowing down the request by using a snapshot list or " +
"an index list for a singular snapshot.";
String message = "["

Check warning on line 695 in server/src/main/java/org/opensearch/action/admin/cluster/snapshots/status/TransportSnapshotsStatusAction.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/action/admin/cluster/snapshots/status/TransportSnapshotsStatusAction.java#L695

Added line #L695 was not covered by tests
+ repositoryName
+ "] Total shard count "
+ shardCount
+ " is more than the maximum allowed value of shard count ["
+ maximumAllowedShardCount
+ "] for snapshot status request. Try narrowing down the request by using a snapshot list or "
+ "an index list for a singular snapshot.";

throw new CircuitBreakingException(message, CircuitBreaker.Durability.PERMANENT);

Check warning on line 704 in server/src/main/java/org/opensearch/action/admin/cluster/snapshots/status/TransportSnapshotsStatusAction.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/action/admin/cluster/snapshots/status/TransportSnapshotsStatusAction.java#L704

Added line #L704 was not covered by tests
}
Expand Down

0 comments on commit eb39c25

Please sign in to comment.