Search in sources :

Example 11 with RepositoryData

use of org.elasticsearch.repositories.RepositoryData in project elasticsearch by elastic.

the class BlobStoreRepositoryTests method testIndexGenerationalFiles.

public void testIndexGenerationalFiles() throws Exception {
    final BlobStoreRepository repository = setupRepo();
    // write to index generational file
    RepositoryData repositoryData = generateRandomRepoData();
    repository.writeIndexGen(repositoryData, repositoryData.getGenId());
    assertThat(repository.getRepositoryData(), equalTo(repositoryData));
    assertThat(repository.latestIndexBlobId(), equalTo(0L));
    assertThat(repository.readSnapshotIndexLatestBlob(), equalTo(0L));
    // adding more and writing to a new index generational file
    repositoryData = addRandomSnapshotsToRepoData(repository.getRepositoryData(), true);
    repository.writeIndexGen(repositoryData, repositoryData.getGenId());
    assertEquals(repository.getRepositoryData(), repositoryData);
    assertThat(repository.latestIndexBlobId(), equalTo(1L));
    assertThat(repository.readSnapshotIndexLatestBlob(), equalTo(1L));
    // removing a snapshot and writing to a new index generational file
    repositoryData = repository.getRepositoryData().removeSnapshot(repositoryData.getSnapshotIds().get(0));
    repository.writeIndexGen(repositoryData, repositoryData.getGenId());
    assertEquals(repository.getRepositoryData(), repositoryData);
    assertThat(repository.latestIndexBlobId(), equalTo(2L));
    assertThat(repository.readSnapshotIndexLatestBlob(), equalTo(2L));
}
Also used : RepositoryData(org.elasticsearch.repositories.RepositoryData)

Example 12 with RepositoryData

use of org.elasticsearch.repositories.RepositoryData in project elasticsearch by elastic.

the class BlobStoreRepositoryTests method testRepositoryDataConcurrentModificationNotAllowed.

public void testRepositoryDataConcurrentModificationNotAllowed() throws IOException {
    final BlobStoreRepository repository = setupRepo();
    // write to index generational file
    RepositoryData repositoryData = generateRandomRepoData();
    repository.writeIndexGen(repositoryData, repositoryData.getGenId());
    // write repo data again to index generational file, errors because we already wrote to the
    // N+1 generation from which this repository data instance was created
    expectThrows(RepositoryException.class, () -> repository.writeIndexGen(repositoryData, repositoryData.getGenId()));
}
Also used : RepositoryData(org.elasticsearch.repositories.RepositoryData)

Example 13 with RepositoryData

use of org.elasticsearch.repositories.RepositoryData in project elasticsearch by elastic.

the class SnapshotsService method snapshotShards.

/**
     * Returns status of shards  currently finished snapshots
     * <p>
     * This method is executed on master node and it's complimentary to the {@link SnapshotShardsService#currentSnapshotShards(Snapshot)} because it
     * returns similar information but for already finished snapshots.
     * </p>
     *
     * @param repositoryName  repository name
     * @param snapshotInfo    snapshot info
     * @return map of shard id to snapshot status
     */
public Map<ShardId, IndexShardSnapshotStatus> snapshotShards(final String repositoryName, final SnapshotInfo snapshotInfo) throws IOException {
    Map<ShardId, IndexShardSnapshotStatus> shardStatus = new HashMap<>();
    Repository repository = repositoriesService.repository(repositoryName);
    RepositoryData repositoryData = repository.getRepositoryData();
    MetaData metaData = repository.getSnapshotMetaData(snapshotInfo, repositoryData.resolveIndices(snapshotInfo.indices()));
    for (String index : snapshotInfo.indices()) {
        IndexId indexId = repositoryData.resolveIndexId(index);
        IndexMetaData indexMetaData = metaData.indices().get(index);
        if (indexMetaData != null) {
            int numberOfShards = indexMetaData.getNumberOfShards();
            for (int i = 0; i < numberOfShards; i++) {
                ShardId shardId = new ShardId(indexMetaData.getIndex(), i);
                SnapshotShardFailure shardFailure = findShardFailure(snapshotInfo.shardFailures(), shardId);
                if (shardFailure != null) {
                    IndexShardSnapshotStatus shardSnapshotStatus = new IndexShardSnapshotStatus();
                    shardSnapshotStatus.updateStage(IndexShardSnapshotStatus.Stage.FAILURE);
                    shardSnapshotStatus.failure(shardFailure.reason());
                    shardStatus.put(shardId, shardSnapshotStatus);
                } else {
                    IndexShardSnapshotStatus shardSnapshotStatus = repository.getShardSnapshotStatus(snapshotInfo.snapshotId(), snapshotInfo.version(), indexId, shardId);
                    shardStatus.put(shardId, shardSnapshotStatus);
                }
            }
        }
    }
    return unmodifiableMap(shardStatus);
}
Also used : ShardId(org.elasticsearch.index.shard.ShardId) IndexShardSnapshotStatus(org.elasticsearch.index.snapshots.IndexShardSnapshotStatus) IndexId(org.elasticsearch.repositories.IndexId) Repository(org.elasticsearch.repositories.Repository) HashMap(java.util.HashMap) MetaData(org.elasticsearch.cluster.metadata.MetaData) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) RepositoriesMetaData(org.elasticsearch.cluster.metadata.RepositoriesMetaData) RepositoryData(org.elasticsearch.repositories.RepositoryData) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData)

Example 14 with RepositoryData

use of org.elasticsearch.repositories.RepositoryData in project elasticsearch by elastic.

the class SnapshotsService method deleteSnapshot.

/**
     * Deletes a snapshot from the repository, looking up the {@link Snapshot} reference before deleting.
     * If the snapshot is still running cancels the snapshot first and then deletes it from the repository.
     *
     * @param repositoryName  repositoryName
     * @param snapshotName    snapshotName
     * @param listener        listener
     */
public void deleteSnapshot(final String repositoryName, final String snapshotName, final DeleteSnapshotListener listener, final boolean immediatePriority) {
    // First, look for the snapshot in the repository
    final Repository repository = repositoriesService.repository(repositoryName);
    final RepositoryData repositoryData = repository.getRepositoryData();
    final Optional<SnapshotId> incompatibleSnapshotId = repositoryData.getIncompatibleSnapshotIds().stream().filter(s -> snapshotName.equals(s.getName())).findFirst();
    if (incompatibleSnapshotId.isPresent()) {
        throw new SnapshotException(repositoryName, snapshotName, "cannot delete incompatible snapshot");
    }
    Optional<SnapshotId> matchedEntry = repositoryData.getSnapshotIds().stream().filter(s -> s.getName().equals(snapshotName)).findFirst();
    // if nothing found by the same name, then look in the cluster state for current in progress snapshots
    if (matchedEntry.isPresent() == false) {
        matchedEntry = currentSnapshots(repositoryName, Collections.emptyList()).stream().map(e -> e.snapshot().getSnapshotId()).filter(s -> s.getName().equals(snapshotName)).findFirst();
    }
    if (matchedEntry.isPresent() == false) {
        throw new SnapshotMissingException(repositoryName, snapshotName);
    }
    deleteSnapshot(new Snapshot(repositoryName, matchedEntry.get()), listener, repositoryData.getGenId(), immediatePriority);
}
Also used : MetaData(org.elasticsearch.cluster.metadata.MetaData) ShardId(org.elasticsearch.index.shard.ShardId) Arrays(java.util.Arrays) Nullable(org.elasticsearch.common.Nullable) ObjectObjectCursor(com.carrotsearch.hppc.cursors.ObjectObjectCursor) ClusterState(org.elasticsearch.cluster.ClusterState) ClusterStateUpdateTask(org.elasticsearch.cluster.ClusterStateUpdateTask) Settings(org.elasticsearch.common.settings.Settings) RestoreInProgress(org.elasticsearch.cluster.RestoreInProgress) Locale(java.util.Locale) Map(java.util.Map) IndicesOptions(org.elasticsearch.action.support.IndicesOptions) ThreadPool(org.elasticsearch.threadpool.ThreadPool) Priority(org.elasticsearch.common.Priority) ShardSearchFailure(org.elasticsearch.action.search.ShardSearchFailure) SnapshotDeletionsInProgress(org.elasticsearch.cluster.SnapshotDeletionsInProgress) UUIDs(org.elasticsearch.common.UUIDs) Set(java.util.Set) State(org.elasticsearch.cluster.SnapshotsInProgress.State) IndexShardRoutingTable(org.elasticsearch.cluster.routing.IndexShardRoutingTable) ObjectCursor(com.carrotsearch.hppc.cursors.ObjectCursor) ClusterChangedEvent(org.elasticsearch.cluster.ClusterChangedEvent) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) List(java.util.List) IndexRoutingTable(org.elasticsearch.cluster.routing.IndexRoutingTable) Supplier(org.apache.logging.log4j.util.Supplier) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) RepositoryMissingException(org.elasticsearch.repositories.RepositoryMissingException) Optional(java.util.Optional) ShardSnapshotStatus(org.elasticsearch.cluster.SnapshotsInProgress.ShardSnapshotStatus) RepositoryData(org.elasticsearch.repositories.RepositoryData) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ShardRouting(org.elasticsearch.cluster.routing.ShardRouting) SearchShardTarget(org.elasticsearch.search.SearchShardTarget) ImmutableOpenMap(org.elasticsearch.common.collect.ImmutableOpenMap) ClusterService(org.elasticsearch.cluster.service.ClusterService) IndexShardSnapshotStatus(org.elasticsearch.index.snapshots.IndexShardSnapshotStatus) HashMap(java.util.HashMap) Index(org.elasticsearch.index.Index) ParameterizedMessage(org.apache.logging.log4j.message.ParameterizedMessage) IndexId(org.elasticsearch.repositories.IndexId) SnapshotsInProgress.completed(org.elasticsearch.cluster.SnapshotsInProgress.completed) Strings(org.elasticsearch.common.Strings) Inject(org.elasticsearch.common.inject.Inject) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) TimeValue(org.elasticsearch.common.unit.TimeValue) ClusterStateApplier(org.elasticsearch.cluster.ClusterStateApplier) RepositoriesMetaData(org.elasticsearch.cluster.metadata.RepositoriesMetaData) DiscoveryNodes(org.elasticsearch.cluster.node.DiscoveryNodes) Repository(org.elasticsearch.repositories.Repository) IOException(java.io.IOException) RepositoriesService(org.elasticsearch.repositories.RepositoriesService) AbstractLifecycleComponent(org.elasticsearch.common.component.AbstractLifecycleComponent) CollectionUtil(org.apache.lucene.util.CollectionUtil) ExceptionsHelper(org.elasticsearch.ExceptionsHelper) RoutingTable(org.elasticsearch.cluster.routing.RoutingTable) SnapshotsInProgress(org.elasticsearch.cluster.SnapshotsInProgress) Collections.unmodifiableMap(java.util.Collections.unmodifiableMap) IndexNameExpressionResolver(org.elasticsearch.cluster.metadata.IndexNameExpressionResolver) Tuple(org.elasticsearch.common.collect.Tuple) Collections(java.util.Collections) ActionListener(org.elasticsearch.action.ActionListener) Repository(org.elasticsearch.repositories.Repository) RepositoryData(org.elasticsearch.repositories.RepositoryData)

Example 15 with RepositoryData

use of org.elasticsearch.repositories.RepositoryData in project elasticsearch by elastic.

the class ESBlobStoreRepositoryIntegTestCase method testIndicesDeletedFromRepository.

public void testIndicesDeletedFromRepository() throws Exception {
    Client client = client();
    logger.info("-->  creating repository");
    final String repoName = "test-repo";
    createTestRepository(repoName);
    createIndex("test-idx-1", "test-idx-2", "test-idx-3");
    ensureGreen();
    logger.info("--> indexing some data");
    for (int i = 0; i < 20; i++) {
        index("test-idx-1", "doc", Integer.toString(i), "foo", "bar" + i);
        index("test-idx-2", "doc", Integer.toString(i), "foo", "baz" + i);
        index("test-idx-3", "doc", Integer.toString(i), "foo", "baz" + i);
    }
    refresh();
    logger.info("--> take a snapshot");
    CreateSnapshotResponse createSnapshotResponse = client.admin().cluster().prepareCreateSnapshot(repoName, "test-snap").setWaitForCompletion(true).get();
    assertEquals(createSnapshotResponse.getSnapshotInfo().successfulShards(), createSnapshotResponse.getSnapshotInfo().totalShards());
    logger.info("--> indexing more data");
    for (int i = 20; i < 40; i++) {
        index("test-idx-1", "doc", Integer.toString(i), "foo", "bar" + i);
        index("test-idx-2", "doc", Integer.toString(i), "foo", "baz" + i);
        index("test-idx-3", "doc", Integer.toString(i), "foo", "baz" + i);
    }
    logger.info("--> take another snapshot with only 2 of the 3 indices");
    createSnapshotResponse = client.admin().cluster().prepareCreateSnapshot(repoName, "test-snap2").setWaitForCompletion(true).setIndices("test-idx-1", "test-idx-2").get();
    assertEquals(createSnapshotResponse.getSnapshotInfo().successfulShards(), createSnapshotResponse.getSnapshotInfo().totalShards());
    logger.info("--> delete a snapshot");
    assertAcked(client().admin().cluster().prepareDeleteSnapshot(repoName, "test-snap").get());
    logger.info("--> verify index folder deleted from blob container");
    RepositoriesService repositoriesSvc = internalCluster().getInstance(RepositoriesService.class, internalCluster().getMasterName());
    @SuppressWarnings("unchecked") BlobStoreRepository repository = (BlobStoreRepository) repositoriesSvc.repository(repoName);
    BlobContainer indicesBlobContainer = repository.blobStore().blobContainer(repository.basePath().add("indices"));
    RepositoryData repositoryData = repository.getRepositoryData();
    for (IndexId indexId : repositoryData.getIndices().values()) {
        if (indexId.getName().equals("test-idx-3")) {
            // deleted index
            assertFalse(indicesBlobContainer.blobExists(indexId.getId()));
        }
    }
}
Also used : IndexId(org.elasticsearch.repositories.IndexId) CreateSnapshotResponse(org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse) RepositoriesService(org.elasticsearch.repositories.RepositoriesService) BlobContainer(org.elasticsearch.common.blobstore.BlobContainer) Client(org.elasticsearch.client.Client) RepositoryData(org.elasticsearch.repositories.RepositoryData)

Aggregations

RepositoryData (org.elasticsearch.repositories.RepositoryData)15 IOException (java.io.IOException)7 IndexId (org.elasticsearch.repositories.IndexId)7 ArrayList (java.util.ArrayList)6 ShardId (org.elasticsearch.index.shard.ShardId)6 List (java.util.List)5 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)5 RepositoryException (org.elasticsearch.repositories.RepositoryException)5 HashMap (java.util.HashMap)4 ParameterizedMessage (org.apache.logging.log4j.message.ParameterizedMessage)4 Supplier (org.apache.logging.log4j.util.Supplier)4 ClusterState (org.elasticsearch.cluster.ClusterState)4 RepositoriesService (org.elasticsearch.repositories.RepositoriesService)4 ObjectCursor (com.carrotsearch.hppc.cursors.ObjectCursor)3 ObjectObjectCursor (com.carrotsearch.hppc.cursors.ObjectObjectCursor)3 Collections (java.util.Collections)3 HashSet (java.util.HashSet)3 Map (java.util.Map)3 Set (java.util.Set)3 Collectors (java.util.stream.Collectors)3