Skip to content

Commit 7b8b9c6

Browse files
committed
Fix test by using non cluster manager for client
Signed-off-by: Gaurav Bafna <[email protected]>
1 parent 0e80c3b commit 7b8b9c6

File tree

4 files changed

+23
-20
lines changed

4 files changed

+23
-20
lines changed

server/src/internalClusterTest/java/org/opensearch/remotestore/RemoteRestoreSnapshotIT.java

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
import org.opensearch.action.DocWriteResponse;
1212
import org.opensearch.action.admin.cluster.remotestore.restore.RestoreRemoteStoreRequest;
1313
import org.opensearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse;
14+
import org.opensearch.action.admin.cluster.snapshots.get.GetSnapshotsRequest;
15+
import org.opensearch.action.admin.cluster.snapshots.get.GetSnapshotsResponse;
1416
import org.opensearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse;
1517
import org.opensearch.action.admin.indices.delete.DeleteIndexRequest;
1618
import org.opensearch.action.admin.indices.recovery.RecoveryResponse;
@@ -25,6 +27,7 @@
2527
import org.opensearch.common.blobstore.BlobPath;
2628
import org.opensearch.common.io.PathUtils;
2729
import org.opensearch.common.settings.Settings;
30+
import org.opensearch.common.unit.TimeValue;
2831
import org.opensearch.common.util.io.IOUtils;
2932
import org.opensearch.core.common.unit.ByteSizeUnit;
3033
import org.opensearch.core.index.Index;
@@ -63,6 +66,7 @@
6366
import java.util.Objects;
6467
import java.util.Optional;
6568
import java.util.concurrent.ExecutionException;
69+
import java.util.concurrent.TimeUnit;
6670
import java.util.stream.Collectors;
6771
import java.util.stream.Stream;
6872

@@ -997,7 +1001,7 @@ public void testConcurrentSnapshotV2CreateOperation() throws InterruptedExceptio
9971001
assertThat(repositoryData.getSnapshotIds().size(), greaterThanOrEqualTo(1));
9981002
}
9991003

1000-
public void testConcurrentSnapshotV2CreateOperation_MasterChange() throws InterruptedException, ExecutionException, IOException {
1004+
public void testConcurrentSnapshotV2CreateOperation_MasterChange() throws Exception {
10011005
internalCluster().startClusterManagerOnlyNode(pinnedTimestampSettings());
10021006
internalCluster().startClusterManagerOnlyNode(pinnedTimestampSettings());
10031007
internalCluster().startClusterManagerOnlyNode(pinnedTimestampSettings());
@@ -1033,14 +1037,16 @@ public void testConcurrentSnapshotV2CreateOperation_MasterChange() throws Interr
10331037
Thread thread = new Thread(() -> {
10341038
try {
10351039
String snapshotName = "snapshot-earlier-master";
1036-
CreateSnapshotResponse createSnapshotResponse2 = client().admin()
1040+
internalCluster().nonClusterManagerClient()
1041+
.admin()
10371042
.cluster()
10381043
.prepareCreateSnapshot(snapshotRepoName, snapshotName)
10391044
.setWaitForCompletion(true)
1045+
.setMasterNodeTimeout(TimeValue.timeValueSeconds(60))
10401046
.get();
1041-
} catch (Exception e) {}
1042-
});
10431047

1048+
} catch (Exception ignored) {}
1049+
});
10441050
thread.start();
10451051

10461052
// stop existing master
@@ -1049,17 +1055,18 @@ public void testConcurrentSnapshotV2CreateOperation_MasterChange() throws Interr
10491055

10501056
// Validate that we have greater one snapshot has been created
10511057
String snapshotName = "new-snapshot";
1052-
CreateSnapshotResponse createSnapshotResponse2 = client().admin()
1053-
.cluster()
1054-
.prepareCreateSnapshot(snapshotRepoName, snapshotName)
1055-
.setWaitForCompletion(false)
1056-
.get();
1057-
Repository repository = internalCluster().getInstance(RepositoriesService.class).repository(snapshotRepoName);
1058-
PlainActionFuture<RepositoryData> repositoryDataPlainActionFuture = new PlainActionFuture<>();
1059-
repository.getRepositoryData(repositoryDataPlainActionFuture);
1058+
try {
1059+
client().admin().cluster().prepareCreateSnapshot(snapshotRepoName, snapshotName).setWaitForCompletion(true).get();
1060+
} catch (Exception e) {
1061+
logger.info("Exception while creating new-snapshot", e);
1062+
}
10601063

1061-
RepositoryData repositoryData = repositoryDataPlainActionFuture.get();
1062-
assertThat(repositoryData.getSnapshotIds().size(), greaterThanOrEqualTo(1));
1064+
// Validate that snapshot is present in repository data
1065+
assertBusy(() -> {
1066+
GetSnapshotsRequest request = new GetSnapshotsRequest(snapshotRepoName);
1067+
GetSnapshotsResponse response2 = client().admin().cluster().getSnapshots(request).actionGet();
1068+
assertThat(response2.getSnapshots().size(), greaterThanOrEqualTo(1));
1069+
}, 30, TimeUnit.SECONDS);
10631070
thread.join();
10641071
}
10651072

server/src/main/java/org/opensearch/cluster/SnapshotsInProgress.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ public Entry(
349349
);
350350
}
351351

352-
public Entry(
352+
private Entry(
353353
Snapshot snapshot,
354354
boolean includeGlobalState,
355355
boolean partial,

server/src/main/java/org/opensearch/repositories/blobstore/BlobStoreRepository.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2916,8 +2916,6 @@ public void getRepositoryData(ActionListener<RepositoryData> listener) {
29162916
}
29172917
final Tuple<Long, BytesReference> cached = latestKnownRepositoryData.get();
29182918
// Fast path loading repository data directly from cache if we're in fully consistent mode and the cache matches up with
2919-
// Fast path loading repository data directly from cache if we're in fully consistent mode and the cache matches up with
2920-
// Fast path loading repository data directly from cache if we're in fully consistent mode and the cache matches up with
29212919
// the latest known repository generation
29222920
if (bestEffortConsistency == false && cached != null && cached.v1() == latestKnownRepoGen.get()) {
29232921
try {
@@ -3396,7 +3394,6 @@ public ClusterState execute(ClusterState currentState) {
33963394
+ "]"
33973395
);
33983396
}
3399-
logger.info("Done Setting it to {} {}", newGen, newGen);
34003397
return updateRepositoryGenerationsIfNecessary(
34013398
stateFilter.apply(
34023399
ClusterState.builder(currentState)

server/src/main/java/org/opensearch/snapshots/SnapshotsService.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,7 @@ public void createSnapshotV2(final CreateSnapshotRequest request, final ActionLi
470470
final String snapshotName = indexNameExpressionResolver.resolveDateMathExpression(request.snapshot());
471471

472472
Repository repository = repositoriesService.repository(repositoryName);
473+
validate(repositoryName, snapshotName);
473474
repository.executeConsistentStateUpdate(repositoryData -> new ClusterStateUpdateTask(Priority.URGENT) {
474475
private SnapshotsInProgress.Entry newEntry;
475476

@@ -482,8 +483,6 @@ public void createSnapshotV2(final CreateSnapshotRequest request, final ActionLi
482483
@Override
483484
public ClusterState execute(ClusterState currentState) {
484485
// move to in progress
485-
validate(repositoryName, snapshotName);
486-
487486
snapshotId = new SnapshotId(snapshotName, UUIDs.randomBase64UUID()); // new UUID for the snapshot
488487
Repository repository = repositoriesService.repository(repositoryName);
489488

0 commit comments

Comments
 (0)