Search in sources :

Example 16 with SnapshotId

use of org.elasticsearch.snapshots.SnapshotId in project elasticsearch by elastic.

the class BlobStoreRepository method finalizeSnapshot.

/**
     * {@inheritDoc}
     */
@Override
public SnapshotInfo finalizeSnapshot(final SnapshotId snapshotId, final List<IndexId> indices, final long startTime, final String failure, final int totalShards, final List<SnapshotShardFailure> shardFailures, final long repositoryStateId) {
    try {
        SnapshotInfo blobStoreSnapshot = new SnapshotInfo(snapshotId, indices.stream().map(IndexId::getName).collect(Collectors.toList()), startTime, failure, System.currentTimeMillis(), totalShards, shardFailures);
        snapshotFormat.write(blobStoreSnapshot, snapshotsBlobContainer, snapshotId.getUUID());
        final RepositoryData repositoryData = getRepositoryData();
        List<SnapshotId> snapshotIds = repositoryData.getSnapshotIds();
        if (!snapshotIds.contains(snapshotId)) {
            writeIndexGen(repositoryData.addSnapshot(snapshotId, indices), repositoryStateId);
        }
        return blobStoreSnapshot;
    } catch (IOException ex) {
        throw new RepositoryException(metadata.name(), "failed to update snapshot in repository", ex);
    }
}
Also used : IndexId(org.elasticsearch.repositories.IndexId) SnapshotId(org.elasticsearch.snapshots.SnapshotId) SnapshotInfo(org.elasticsearch.snapshots.SnapshotInfo) RepositoryException(org.elasticsearch.repositories.RepositoryException) IOException(java.io.IOException) RepositoryData(org.elasticsearch.repositories.RepositoryData)

Example 17 with SnapshotId

use of org.elasticsearch.snapshots.SnapshotId in project elasticsearch by elastic.

the class RepositoryDataTests method randomSnapshots.

private static List<SnapshotId> randomSnapshots(final List<SnapshotId> origSnapshotIds) {
    final int numSnapshots = randomIntBetween(1, 30);
    final List<SnapshotId> snapshotIds = new ArrayList<>(origSnapshotIds);
    for (int i = 0; i < numSnapshots; i++) {
        snapshotIds.add(new SnapshotId(randomAsciiOfLength(8), UUIDs.randomBase64UUID()));
    }
    return snapshotIds;
}
Also used : SnapshotId(org.elasticsearch.snapshots.SnapshotId) ArrayList(java.util.ArrayList)

Example 18 with SnapshotId

use of org.elasticsearch.snapshots.SnapshotId in project elasticsearch by elastic.

the class BlobStoreRepositoryTests method addRandomSnapshotsToRepoData.

private RepositoryData addRandomSnapshotsToRepoData(RepositoryData repoData, boolean inclIndices) {
    int numSnapshots = randomIntBetween(1, 20);
    for (int i = 0; i < numSnapshots; i++) {
        SnapshotId snapshotId = new SnapshotId(randomAsciiOfLength(8), UUIDs.randomBase64UUID());
        int numIndices = inclIndices ? randomIntBetween(0, 20) : 0;
        List<IndexId> indexIds = new ArrayList<>(numIndices);
        for (int j = 0; j < numIndices; j++) {
            indexIds.add(new IndexId(randomAsciiOfLength(8), UUIDs.randomBase64UUID()));
        }
        repoData = repoData.addSnapshot(snapshotId, indexIds);
    }
    return repoData;
}
Also used : SnapshotId(org.elasticsearch.snapshots.SnapshotId) IndexId(org.elasticsearch.repositories.IndexId) ArrayList(java.util.ArrayList)

Example 19 with SnapshotId

use of org.elasticsearch.snapshots.SnapshotId in project elasticsearch by elastic.

the class BlobStoreRepositoryTests method testRetrieveSnapshots.

public void testRetrieveSnapshots() throws Exception {
    final Client client = client();
    final Path location = ESIntegTestCase.randomRepoPath(node().settings());
    final String repositoryName = "test-repo";
    logger.info("-->  creating repository");
    PutRepositoryResponse putRepositoryResponse = client.admin().cluster().preparePutRepository(repositoryName).setType("fs").setSettings(Settings.builder().put(node().settings()).put("location", location)).get();
    assertThat(putRepositoryResponse.isAcknowledged(), equalTo(true));
    logger.info("--> creating an index and indexing documents");
    final String indexName = "test-idx";
    createIndex(indexName);
    ensureGreen();
    int numDocs = randomIntBetween(10, 20);
    for (int i = 0; i < numDocs; i++) {
        String id = Integer.toString(i);
        client().prepareIndex(indexName, "type1", id).setSource("text", "sometext").get();
    }
    client().admin().indices().prepareFlush(indexName).get();
    logger.info("--> create first snapshot");
    CreateSnapshotResponse createSnapshotResponse = client.admin().cluster().prepareCreateSnapshot(repositoryName, "test-snap-1").setWaitForCompletion(true).setIndices(indexName).get();
    final SnapshotId snapshotId1 = createSnapshotResponse.getSnapshotInfo().snapshotId();
    logger.info("--> create second snapshot");
    createSnapshotResponse = client.admin().cluster().prepareCreateSnapshot(repositoryName, "test-snap-2").setWaitForCompletion(true).setIndices(indexName).get();
    final SnapshotId snapshotId2 = createSnapshotResponse.getSnapshotInfo().snapshotId();
    logger.info("--> make sure the node's repository can resolve the snapshots");
    final RepositoriesService repositoriesService = getInstanceFromNode(RepositoriesService.class);
    @SuppressWarnings("unchecked") final BlobStoreRepository repository = (BlobStoreRepository) repositoriesService.repository(repositoryName);
    final List<SnapshotId> originalSnapshots = Arrays.asList(snapshotId1, snapshotId2);
    List<SnapshotId> snapshotIds = repository.getRepositoryData().getSnapshotIds().stream().sorted((s1, s2) -> s1.getName().compareTo(s2.getName())).collect(Collectors.toList());
    assertThat(snapshotIds, equalTo(originalSnapshots));
}
Also used : Path(java.nio.file.Path) RepositoryDataTests.generateRandomRepoData(org.elasticsearch.repositories.RepositoryDataTests.generateRandomRepoData) SnapshotId(org.elasticsearch.snapshots.SnapshotId) ESSingleNodeTestCase(org.elasticsearch.test.ESSingleNodeTestCase) Arrays(java.util.Arrays) Client(org.elasticsearch.client.Client) UUIDs(org.elasticsearch.common.UUIDs) IOException(java.io.IOException) RepositoriesService(org.elasticsearch.repositories.RepositoriesService) IndexId(org.elasticsearch.repositories.IndexId) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) PutRepositoryResponse(org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryResponse) List(java.util.List) Settings(org.elasticsearch.common.settings.Settings) ESIntegTestCase(org.elasticsearch.test.ESIntegTestCase) Matchers.equalTo(org.hamcrest.Matchers.equalTo) CreateSnapshotResponse(org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse) Path(java.nio.file.Path) Collections(java.util.Collections) RepositoryException(org.elasticsearch.repositories.RepositoryException) RepositoryData(org.elasticsearch.repositories.RepositoryData) SnapshotId(org.elasticsearch.snapshots.SnapshotId) CreateSnapshotResponse(org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse) RepositoriesService(org.elasticsearch.repositories.RepositoriesService) PutRepositoryResponse(org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryResponse) Client(org.elasticsearch.client.Client)

Example 20 with SnapshotId

use of org.elasticsearch.snapshots.SnapshotId in project elasticsearch by elastic.

the class PrimaryShardAllocatorTests method getRecoverOnAnyNodeRoutingAllocation.

private RoutingAllocation getRecoverOnAnyNodeRoutingAllocation(AllocationDeciders allocationDeciders, String... allocIds) {
    MetaData metaData = MetaData.builder().put(IndexMetaData.builder(shardId.getIndexName()).settings(settings(Version.CURRENT).put(IndexMetaData.SETTING_SHARED_FILESYSTEM, true).put(IndexMetaData.SETTING_SHARED_FS_ALLOW_RECOVERY_ON_ANY_NODE, true)).numberOfShards(1).numberOfReplicas(0).putInSyncAllocationIds(0, Sets.newHashSet(allocIds))).build();
    RoutingTable routingTable = RoutingTable.builder().addAsRestore(metaData.index(shardId.getIndex()), new SnapshotRecoverySource(new Snapshot("test", new SnapshotId("test", UUIDs.randomBase64UUID())), Version.CURRENT, shardId.getIndexName())).build();
    ClusterState state = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable).nodes(DiscoveryNodes.builder().add(node1).add(node2).add(node3)).build();
    return new RoutingAllocation(allocationDeciders, new RoutingNodes(state, false), state, null, System.nanoTime(), false);
}
Also used : Snapshot(org.elasticsearch.snapshots.Snapshot) SnapshotId(org.elasticsearch.snapshots.SnapshotId) ClusterState(org.elasticsearch.cluster.ClusterState) SnapshotRecoverySource(org.elasticsearch.cluster.routing.RecoverySource.SnapshotRecoverySource) RoutingTable(org.elasticsearch.cluster.routing.RoutingTable) RoutingNodes(org.elasticsearch.cluster.routing.RoutingNodes) MetaData(org.elasticsearch.cluster.metadata.MetaData) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) RoutingAllocation(org.elasticsearch.cluster.routing.allocation.RoutingAllocation)

Aggregations

SnapshotId (org.elasticsearch.snapshots.SnapshotId)27 Snapshot (org.elasticsearch.snapshots.Snapshot)13 ArrayList (java.util.ArrayList)11 ClusterState (org.elasticsearch.cluster.ClusterState)9 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)7 MetaData (org.elasticsearch.cluster.metadata.MetaData)7 SnapshotRecoverySource (org.elasticsearch.cluster.routing.RecoverySource.SnapshotRecoverySource)6 IndexId (org.elasticsearch.repositories.IndexId)5 IOException (java.io.IOException)4 HashSet (java.util.HashSet)4 RoutingTable (org.elasticsearch.cluster.routing.RoutingTable)4 RepositoryData (org.elasticsearch.repositories.RepositoryData)4 SnapshotInfo (org.elasticsearch.snapshots.SnapshotInfo)4 HashMap (java.util.HashMap)3 LinkedHashSet (java.util.LinkedHashSet)3 Set (java.util.Set)3 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)3 IntHashSet (com.carrotsearch.hppc.IntHashSet)2 Arrays (java.util.Arrays)2 Collections (java.util.Collections)2