Search in sources :

Example 11 with RepositoriesService

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]));
    }
}
Also used : ImmutableOpenMap(org.opensearch.common.collect.ImmutableOpenMap) Metadata(org.opensearch.cluster.metadata.Metadata) SETTING_VERSION_CREATED(org.opensearch.cluster.metadata.IndexMetadata.SETTING_VERSION_CREATED) AllocationService(org.opensearch.cluster.routing.allocation.AllocationService) TestThreadPool(org.opensearch.threadpool.TestThreadPool) Version(org.opensearch.Version) DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) IndexId(org.opensearch.repositories.IndexId) PlainActionFuture(org.opensearch.action.support.PlainActionFuture) OpenSearchAllocationTestCase(org.opensearch.cluster.OpenSearchAllocationTestCase) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Locale(java.util.Locale) After(org.junit.After) Map(java.util.Map) Matchers.nullValue(org.hamcrest.Matchers.nullValue) SETTING_NUMBER_OF_REPLICAS(org.opensearch.cluster.metadata.IndexMetadata.SETTING_NUMBER_OF_REPLICAS) Repository(org.opensearch.repositories.Repository) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) ClusterApplier(org.opensearch.cluster.service.ClusterApplier) Index(org.opensearch.index.Index) Predicate(java.util.function.Predicate) Matchers.allOf(org.hamcrest.Matchers.allOf) OpenSearchTestCase(org.opensearch.test.OpenSearchTestCase) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Settings(org.opensearch.common.settings.Settings) DiscoveryNodeRole(org.opensearch.cluster.node.DiscoveryNodeRole) CountDownLatch(java.util.concurrent.CountDownLatch) Matchers.equalTo(org.hamcrest.Matchers.equalTo) SETTING_CREATION_DATE(org.opensearch.cluster.metadata.IndexMetadata.SETTING_CREATION_DATE) Matchers.is(org.hamcrest.Matchers.is) FilterRepository(org.opensearch.repositories.FilterRepository) ClusterServiceUtils(org.opensearch.test.ClusterServiceUtils) Mockito.mock(org.mockito.Mockito.mock) RepositoriesService(org.opensearch.repositories.RepositoriesService) DiscoveryNodes(org.opensearch.cluster.node.DiscoveryNodes) IndexMetadata(org.opensearch.cluster.metadata.IndexMetadata) ThreadPool(org.opensearch.threadpool.ThreadPool) INTERNAL_SNAPSHOT_INFO_MAX_CONCURRENT_FETCHES_SETTING(org.opensearch.snapshots.InternalSnapshotsInfoService.INTERNAL_SNAPSHOT_INFO_MAX_CONCURRENT_FETCHES_SETTING) Function(java.util.function.Function) RecoverySource(org.opensearch.cluster.routing.RecoverySource) IndexRoutingTable(org.opensearch.cluster.routing.IndexRoutingTable) ClusterState(org.opensearch.cluster.ClusterState) IndexShardSnapshotStatus(org.opensearch.index.snapshots.IndexShardSnapshotStatus) RerouteService(org.opensearch.cluster.routing.RerouteService) ShardRoutingState(org.opensearch.cluster.routing.ShardRoutingState) Matchers.lessThan(org.hamcrest.Matchers.lessThan) UUIDs(org.opensearch.common.UUIDs) Before(org.junit.Before) Matchers.greaterThanOrEqualTo(org.hamcrest.Matchers.greaterThanOrEqualTo) AllocationId(org.opensearch.cluster.routing.AllocationId) IntHashSet(com.carrotsearch.hppc.IntHashSet) ThreadPoolStats(org.opensearch.threadpool.ThreadPoolStats) Mockito.when(org.mockito.Mockito.when) CLUSTER_ROUTING_ALLOCATION_NODE_CONCURRENT_RECOVERIES_SETTING(org.opensearch.cluster.routing.allocation.decider.ThrottlingAllocationDecider.CLUSTER_ROUTING_ALLOCATION_NODE_CONCURRENT_RECOVERIES_SETTING) ShardRouting(org.opensearch.cluster.routing.ShardRouting) ShardId(org.opensearch.index.shard.ShardId) TimeUnit(java.util.concurrent.TimeUnit) ClusterService(org.opensearch.cluster.service.ClusterService) RestoreInProgress(org.opensearch.cluster.RestoreInProgress) RoutingTable(org.opensearch.cluster.routing.RoutingTable) SETTING_NUMBER_OF_SHARDS(org.opensearch.cluster.metadata.IndexMetadata.SETTING_NUMBER_OF_SHARDS) CLUSTER_ROUTING_ALLOCATION_NODE_INITIAL_PRIMARIES_RECOVERIES_SETTING(org.opensearch.cluster.routing.allocation.decider.ThrottlingAllocationDecider.CLUSTER_ROUTING_ALLOCATION_NODE_INITIAL_PRIMARIES_RECOVERIES_SETTING) Collections(java.util.Collections) IndexId(org.opensearch.repositories.IndexId) CountDownLatch(java.util.concurrent.CountDownLatch) ShardId(org.opensearch.index.shard.ShardId) Repository(org.opensearch.repositories.Repository) FilterRepository(org.opensearch.repositories.FilterRepository) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) FilterRepository(org.opensearch.repositories.FilterRepository) RerouteService(org.opensearch.cluster.routing.RerouteService) ShardRouting(org.opensearch.cluster.routing.ShardRouting)

Example 12 with RepositoriesService

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;
}
Also used : Path(java.nio.file.Path) RepositoriesService(org.opensearch.repositories.RepositoriesService) AcknowledgedResponse(org.opensearch.action.support.master.AcknowledgedResponse) Client(org.opensearch.client.Client)

Example 13 with RepositoriesService

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);
    }
}
Also used : MockRepository(org.opensearch.snapshots.mockstore.MockRepository) RepositoriesService(org.opensearch.repositories.RepositoriesService)

Example 14 with RepositoriesService

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;
}
Also used : MockRepository(org.opensearch.snapshots.mockstore.MockRepository) RepositoriesService(org.opensearch.repositories.RepositoriesService)

Example 15 with RepositoriesService

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());
}
Also used : RepositoriesService(org.opensearch.repositories.RepositoriesService) TestThreadPool(org.opensearch.threadpool.TestThreadPool) Before(org.junit.Before)

Aggregations

RepositoriesService (org.opensearch.repositories.RepositoriesService)24 Settings (org.opensearch.common.settings.Settings)8 Repository (org.opensearch.repositories.Repository)8 ThreadPool (org.opensearch.threadpool.ThreadPool)6 Collections (java.util.Collections)5 Map (java.util.Map)5 Function (java.util.function.Function)5 Client (org.opensearch.client.Client)5 Locale (java.util.Locale)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 TimeUnit (java.util.concurrent.TimeUnit)4 Arrays (java.util.Arrays)3 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 SetOnce (org.apache.lucene.util.SetOnce)3 Matchers.containsString (org.hamcrest.Matchers.containsString)3 CreateSnapshotResponse (org.opensearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse)3 IndexMetadata (org.opensearch.cluster.metadata.IndexMetadata)3 RecoverySource (org.opensearch.cluster.routing.RecoverySource)3 ShardRouting (org.opensearch.cluster.routing.ShardRouting)3