use of org.opensearch.repositories.RepositoriesService in project OpenSearch by opensearch-project.
the class InternalSnapshotsInfoServiceTests method testSnapshotShardSizes.
public void testSnapshotShardSizes() throws Exception {
final int maxConcurrentFetches = randomIntBetween(1, 10);
final int numberOfShards = randomIntBetween(1, 50);
final CountDownLatch rerouteLatch = new CountDownLatch(numberOfShards);
final RerouteService rerouteService = (reason, priority, listener) -> {
listener.onResponse(clusterService.state());
assertThat(rerouteLatch.getCount(), greaterThanOrEqualTo(0L));
rerouteLatch.countDown();
};
final InternalSnapshotsInfoService snapshotsInfoService = new InternalSnapshotsInfoService(Settings.builder().put(INTERNAL_SNAPSHOT_INFO_MAX_CONCURRENT_FETCHES_SETTING.getKey(), maxConcurrentFetches).build(), clusterService, () -> repositoriesService, () -> rerouteService);
final String indexName = randomAlphaOfLength(10).toLowerCase(Locale.ROOT);
final long[] expectedShardSizes = new long[numberOfShards];
for (int i = 0; i < expectedShardSizes.length; i++) {
expectedShardSizes[i] = randomNonNegativeLong();
}
final AtomicInteger getShardSnapshotStatusCount = new AtomicInteger(0);
final CountDownLatch latch = new CountDownLatch(1);
final Repository mockRepository = new FilterRepository(mock(Repository.class)) {
@Override
public IndexShardSnapshotStatus getShardSnapshotStatus(SnapshotId snapshotId, IndexId indexId, ShardId shardId) {
try {
assertThat(indexId.getName(), equalTo(indexName));
assertThat(shardId.id(), allOf(greaterThanOrEqualTo(0), lessThan(numberOfShards)));
latch.await();
getShardSnapshotStatusCount.incrementAndGet();
return IndexShardSnapshotStatus.newDone(0L, 0L, 0, 0, 0L, expectedShardSizes[shardId.id()], null);
} catch (InterruptedException e) {
throw new AssertionError(e);
}
}
};
when(repositoriesService.repository("_repo")).thenReturn(mockRepository);
applyClusterState("add-unassigned-shards", clusterState -> addUnassignedShards(clusterState, indexName, numberOfShards));
waitForMaxActiveGenericThreads(Math.min(numberOfShards, maxConcurrentFetches));
if (randomBoolean()) {
applyClusterState("reapply-last-cluster-state-to-check-deduplication-works", state -> ClusterState.builder(state).incrementVersion().build());
}
assertThat(snapshotsInfoService.numberOfUnknownSnapshotShardSizes(), equalTo(numberOfShards));
assertThat(snapshotsInfoService.numberOfKnownSnapshotShardSizes(), equalTo(0));
latch.countDown();
assertTrue(rerouteLatch.await(30L, TimeUnit.SECONDS));
assertThat(snapshotsInfoService.numberOfKnownSnapshotShardSizes(), equalTo(numberOfShards));
assertThat(snapshotsInfoService.numberOfUnknownSnapshotShardSizes(), equalTo(0));
assertThat(snapshotsInfoService.numberOfFailedSnapshotShardSizes(), equalTo(0));
assertThat(getShardSnapshotStatusCount.get(), equalTo(numberOfShards));
final SnapshotShardSizeInfo snapshotShardSizeInfo = snapshotsInfoService.snapshotShardSizes();
for (int i = 0; i < numberOfShards; i++) {
final ShardRouting shardRouting = clusterService.state().routingTable().index(indexName).shard(i).primaryShard();
assertThat(snapshotShardSizeInfo.getShardSize(shardRouting), equalTo(expectedShardSizes[i]));
assertThat(snapshotShardSizeInfo.getShardSize(shardRouting, Long.MIN_VALUE), equalTo(expectedShardSizes[i]));
}
}
use of org.opensearch.repositories.RepositoriesService in project OpenSearch by opensearch-project.
the class BlobStoreRepositoryTests method setupRepo.
private BlobStoreRepository setupRepo() {
final Client client = client();
final Path location = OpenSearchIntegTestCase.randomRepoPath(node().settings());
final String repositoryName = "test-repo";
AcknowledgedResponse putRepositoryResponse = client.admin().cluster().preparePutRepository(repositoryName).setType(REPO_TYPE).setSettings(Settings.builder().put(node().settings()).put("location", location)).get();
assertThat(putRepositoryResponse.isAcknowledged(), equalTo(true));
final RepositoriesService repositoriesService = getInstanceFromNode(RepositoriesService.class);
final BlobStoreRepository repository = (BlobStoreRepository) repositoriesService.repository(repositoryName);
assertThat("getBlobContainer has to be lazy initialized", repository.getBlobContainer(), nullValue());
return repository;
}
use of org.opensearch.repositories.RepositoriesService in project OpenSearch by opensearch-project.
the class AbstractSnapshotIntegTestCase method failReadsAllDataNodes.
public static void failReadsAllDataNodes(String repository) {
for (RepositoriesService repositoriesService : internalCluster().getDataNodeInstances(RepositoriesService.class)) {
MockRepository mockRepository = (MockRepository) repositoriesService.repository(repository);
mockRepository.setFailReadsAfterUnblock(true);
}
}
use of org.opensearch.repositories.RepositoriesService in project OpenSearch by opensearch-project.
the class AbstractSnapshotIntegTestCase method getFailureCount.
public static long getFailureCount(String repository) {
long failureCount = 0;
for (RepositoriesService repositoriesService : internalCluster().getDataOrMasterNodeInstances(RepositoriesService.class)) {
MockRepository mockRepository = (MockRepository) repositoriesService.repository(repository);
failureCount += mockRepository.getFailureCount();
}
return failureCount;
}
use of org.opensearch.repositories.RepositoriesService in project OpenSearch by opensearch-project.
the class InternalSnapshotsInfoServiceTests method setUp.
@Before
@Override
public void setUp() throws Exception {
super.setUp();
threadPool = new TestThreadPool(getTestName());
clusterService = ClusterServiceUtils.createClusterService(threadPool);
repositoriesService = mock(RepositoriesService.class);
rerouteService = (reason, priority, listener) -> listener.onResponse(clusterService.state());
}
Aggregations