Search in sources :

Example 6 with SnapshotId

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

the class UnassignedInfoTests method testNewIndexRestored.

public void testNewIndexRestored() {
    MetaData metaData = MetaData.builder().put(IndexMetaData.builder("test").settings(settings(Version.CURRENT)).numberOfShards(randomIntBetween(1, 3)).numberOfReplicas(randomIntBetween(0, 3))).build();
    ClusterState clusterState = ClusterState.builder(ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(RoutingTable.builder().addAsNewRestore(metaData.index("test"), new SnapshotRecoverySource(new Snapshot("rep1", new SnapshotId("snp1", UUIDs.randomBase64UUID())), Version.CURRENT, "test"), new IntHashSet()).build()).build();
    for (ShardRouting shard : clusterState.getRoutingNodes().shardsWithState(UNASSIGNED)) {
        assertThat(shard.unassignedInfo().getReason(), equalTo(UnassignedInfo.Reason.NEW_INDEX_RESTORED));
    }
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) Snapshot(org.elasticsearch.snapshots.Snapshot) SnapshotId(org.elasticsearch.snapshots.SnapshotId) SnapshotRecoverySource(org.elasticsearch.cluster.routing.RecoverySource.SnapshotRecoverySource) MetaData(org.elasticsearch.cluster.metadata.MetaData) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) IntHashSet(com.carrotsearch.hppc.IntHashSet)

Example 7 with SnapshotId

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

the class RepositoryDataTests method testAddSnapshots.

public void testAddSnapshots() {
    RepositoryData repositoryData = generateRandomRepoData();
    // test that adding the same snapshot id to the repository data throws an exception
    Map<String, IndexId> indexIdMap = repositoryData.getIndices();
    // test that adding a snapshot and its indices works
    SnapshotId newSnapshot = new SnapshotId(randomAsciiOfLength(7), UUIDs.randomBase64UUID());
    List<IndexId> indices = new ArrayList<>();
    Set<IndexId> newIndices = new HashSet<>();
    int numNew = randomIntBetween(1, 10);
    for (int i = 0; i < numNew; i++) {
        IndexId indexId = new IndexId(randomAsciiOfLength(7), UUIDs.randomBase64UUID());
        newIndices.add(indexId);
        indices.add(indexId);
    }
    int numOld = randomIntBetween(1, indexIdMap.size());
    List<String> indexNames = new ArrayList<>(indexIdMap.keySet());
    for (int i = 0; i < numOld; i++) {
        indices.add(indexIdMap.get(indexNames.get(i)));
    }
    RepositoryData newRepoData = repositoryData.addSnapshot(newSnapshot, indices);
    // verify that the new repository data has the new snapshot and its indices
    assertTrue(newRepoData.getSnapshotIds().contains(newSnapshot));
    for (IndexId indexId : indices) {
        Set<SnapshotId> snapshotIds = newRepoData.getSnapshots(indexId);
        assertTrue(snapshotIds.contains(newSnapshot));
        if (newIndices.contains(indexId)) {
            // if it was a new index, only the new snapshot should be in its set
            assertEquals(snapshotIds.size(), 1);
        }
    }
    assertEquals(repositoryData.getGenId(), newRepoData.getGenId());
}
Also used : SnapshotId(org.elasticsearch.snapshots.SnapshotId) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 8 with SnapshotId

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

the class RepositoryDataTests method testRemoveSnapshot.

public void testRemoveSnapshot() {
    RepositoryData repositoryData = generateRandomRepoData();
    List<SnapshotId> snapshotIds = new ArrayList<>(repositoryData.getSnapshotIds());
    assertThat(snapshotIds.size(), greaterThan(0));
    SnapshotId removedSnapshotId = snapshotIds.remove(randomIntBetween(0, snapshotIds.size() - 1));
    RepositoryData newRepositoryData = repositoryData.removeSnapshot(removedSnapshotId);
    // make sure the repository data's indices no longer contain the removed snapshot
    for (final IndexId indexId : newRepositoryData.getIndices().values()) {
        assertFalse(newRepositoryData.getSnapshots(indexId).contains(removedSnapshotId));
    }
}
Also used : SnapshotId(org.elasticsearch.snapshots.SnapshotId) ArrayList(java.util.ArrayList)

Example 9 with SnapshotId

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

the class RepositoryDataTests method testInitIndices.

public void testInitIndices() {
    final int numSnapshots = randomIntBetween(1, 30);
    final List<SnapshotId> snapshotIds = new ArrayList<>(numSnapshots);
    for (int i = 0; i < numSnapshots; i++) {
        snapshotIds.add(new SnapshotId(randomAsciiOfLength(8), UUIDs.randomBase64UUID()));
    }
    RepositoryData repositoryData = new RepositoryData(EMPTY_REPO_GEN, snapshotIds, Collections.emptyMap(), Collections.emptyList());
    // test that initializing indices works
    Map<IndexId, Set<SnapshotId>> indices = randomIndices(snapshotIds);
    RepositoryData newRepoData = repositoryData.initIndices(indices);
    assertEquals(repositoryData.getSnapshotIds(), newRepoData.getSnapshotIds());
    for (IndexId indexId : indices.keySet()) {
        assertEquals(indices.get(indexId), newRepoData.getSnapshots(indexId));
    }
}
Also used : SnapshotId(org.elasticsearch.snapshots.SnapshotId) Set(java.util.Set) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) ArrayList(java.util.ArrayList)

Example 10 with SnapshotId

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

the class BlobStoreRepositoryTests method testReadAndWriteIncompatibleSnapshots.

public void testReadAndWriteIncompatibleSnapshots() throws Exception {
    final BlobStoreRepository repository = setupRepo();
    // write to and read from incompatible snapshots file with no entries
    assertEquals(0, repository.getRepositoryData().getIncompatibleSnapshotIds().size());
    RepositoryData emptyData = RepositoryData.EMPTY;
    repository.writeIndexGen(emptyData, emptyData.getGenId());
    repository.writeIncompatibleSnapshots(emptyData);
    RepositoryData readData = repository.getRepositoryData();
    assertEquals(emptyData, readData);
    assertEquals(0, readData.getIndices().size());
    assertEquals(0, readData.getSnapshotIds().size());
    // write to and read from incompatible snapshots with some number of entries
    final int numSnapshots = randomIntBetween(1, 20);
    final List<SnapshotId> snapshotIds = new ArrayList<>(numSnapshots);
    for (int i = 0; i < numSnapshots; i++) {
        snapshotIds.add(new SnapshotId(randomAsciiOfLength(8), UUIDs.randomBase64UUID()));
    }
    RepositoryData repositoryData = new RepositoryData(readData.getGenId(), Collections.emptyList(), Collections.emptyMap(), snapshotIds);
    repository.blobContainer().deleteBlob("incompatible-snapshots");
    repository.writeIncompatibleSnapshots(repositoryData);
    readData = repository.getRepositoryData();
    assertEquals(repositoryData.getIncompatibleSnapshotIds(), readData.getIncompatibleSnapshotIds());
}
Also used : SnapshotId(org.elasticsearch.snapshots.SnapshotId) ArrayList(java.util.ArrayList) RepositoryData(org.elasticsearch.repositories.RepositoryData)

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