Search in sources :

Example 1 with SnapshotId

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

the class RepositoryData method snapshotsToXContent.

/**
     * Writes the snapshots metadata and the related indices metadata to x-content, omitting the
     * incompatible snapshots.
     */
public XContentBuilder snapshotsToXContent(final XContentBuilder builder, final ToXContent.Params params) throws IOException {
    builder.startObject();
    // write the snapshots list
    builder.startArray(SNAPSHOTS);
    for (final SnapshotId snapshot : getSnapshotIds()) {
        snapshot.toXContent(builder, params);
    }
    builder.endArray();
    // write the indices map
    builder.startObject(INDICES);
    for (final IndexId indexId : getIndices().values()) {
        builder.startObject(indexId.getName());
        builder.field(INDEX_ID, indexId.getId());
        builder.startArray(SNAPSHOTS);
        Set<SnapshotId> snapshotIds = indexSnapshots.get(indexId);
        assert snapshotIds != null;
        for (final SnapshotId snapshotId : snapshotIds) {
            snapshotId.toXContent(builder, params);
        }
        builder.endArray();
        builder.endObject();
    }
    builder.endObject();
    builder.endObject();
    return builder;
}
Also used : SnapshotId(org.elasticsearch.snapshots.SnapshotId)

Example 2 with SnapshotId

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

the class RepositoryData method addIncompatibleSnapshots.

/**
     * Returns a new {@link RepositoryData} instance containing the same snapshot data as the
     * invoking instance, with the given incompatible snapshots added to the new instance.
     */
public RepositoryData addIncompatibleSnapshots(final List<SnapshotId> incompatibleSnapshotIds) {
    List<SnapshotId> newSnapshotIds = new ArrayList<>(this.snapshotIds);
    List<SnapshotId> newIncompatibleSnapshotIds = new ArrayList<>(this.incompatibleSnapshotIds);
    for (SnapshotId snapshotId : incompatibleSnapshotIds) {
        newSnapshotIds.remove(snapshotId);
        newIncompatibleSnapshotIds.add(snapshotId);
    }
    return new RepositoryData(this.genId, newSnapshotIds, this.indexSnapshots, newIncompatibleSnapshotIds);
}
Also used : SnapshotId(org.elasticsearch.snapshots.SnapshotId) ArrayList(java.util.ArrayList)

Example 3 with SnapshotId

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

the class RepositoryData method incompatibleSnapshotsToXContent.

/**
     * Writes the incompatible snapshot ids to x-content.
     */
public XContentBuilder incompatibleSnapshotsToXContent(final XContentBuilder builder, final ToXContent.Params params) throws IOException {
    builder.startObject();
    // write the incompatible snapshots list
    builder.startArray(INCOMPATIBLE_SNAPSHOTS);
    for (final SnapshotId snapshot : getIncompatibleSnapshotIds()) {
        snapshot.toXContent(builder, params);
    }
    builder.endArray();
    builder.endObject();
    return builder;
}
Also used : SnapshotId(org.elasticsearch.snapshots.SnapshotId)

Example 4 with SnapshotId

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

the class ShardRoutingTests method testEqualsIgnoringVersion.

public void testEqualsIgnoringVersion() {
    ShardRouting routing = randomShardRouting("test", 0);
    ShardRouting otherRouting = routing;
    Integer[] changeIds = new Integer[] { 0, 1, 2, 3, 4, 5, 6 };
    for (int changeId : randomSubsetOf(randomIntBetween(1, changeIds.length), changeIds)) {
        boolean unchanged = false;
        switch(changeId) {
            case 0:
                // change index
                ShardId shardId = new ShardId(new Index("blubb", randomAsciiOfLength(10)), otherRouting.id());
                otherRouting = new ShardRouting(shardId, otherRouting.currentNodeId(), otherRouting.relocatingNodeId(), otherRouting.primary(), otherRouting.state(), otherRouting.recoverySource(), otherRouting.unassignedInfo(), otherRouting.allocationId(), otherRouting.getExpectedShardSize());
                break;
            case 1:
                // change shard id
                otherRouting = new ShardRouting(new ShardId(otherRouting.index(), otherRouting.id() + 1), otherRouting.currentNodeId(), otherRouting.relocatingNodeId(), otherRouting.primary(), otherRouting.state(), otherRouting.recoverySource(), otherRouting.unassignedInfo(), otherRouting.allocationId(), otherRouting.getExpectedShardSize());
                break;
            case 2:
                // change current node
                otherRouting = new ShardRouting(otherRouting.shardId(), otherRouting.currentNodeId() == null ? "1" : otherRouting.currentNodeId() + "_1", otherRouting.relocatingNodeId(), otherRouting.primary(), otherRouting.state(), otherRouting.recoverySource(), otherRouting.unassignedInfo(), otherRouting.allocationId(), otherRouting.getExpectedShardSize());
                break;
            case 3:
                // change relocating node
                otherRouting = new ShardRouting(otherRouting.shardId(), otherRouting.currentNodeId(), otherRouting.relocatingNodeId() == null ? "1" : otherRouting.relocatingNodeId() + "_1", otherRouting.primary(), otherRouting.state(), otherRouting.recoverySource(), otherRouting.unassignedInfo(), otherRouting.allocationId(), otherRouting.getExpectedShardSize());
                break;
            case 4:
                // change recovery source (only works for inactive primaries)
                if (otherRouting.active() || otherRouting.primary() == false) {
                    unchanged = true;
                } else {
                    otherRouting = new ShardRouting(otherRouting.shardId(), otherRouting.currentNodeId(), otherRouting.relocatingNodeId(), otherRouting.primary(), otherRouting.state(), new RecoverySource.SnapshotRecoverySource(new Snapshot("test", new SnapshotId("s1", UUIDs.randomBase64UUID())), Version.CURRENT, "test"), otherRouting.unassignedInfo(), otherRouting.allocationId(), otherRouting.getExpectedShardSize());
                }
                break;
            case 5:
                // change primary flag
                otherRouting = TestShardRouting.newShardRouting(otherRouting.getIndexName(), otherRouting.id(), otherRouting.currentNodeId(), otherRouting.relocatingNodeId(), otherRouting.primary() == false, otherRouting.state(), otherRouting.unassignedInfo());
                break;
            case 6:
                // change state
                ShardRoutingState newState;
                do {
                    newState = randomFrom(ShardRoutingState.values());
                } while (newState == otherRouting.state());
                UnassignedInfo unassignedInfo = otherRouting.unassignedInfo();
                if (unassignedInfo == null && (newState == ShardRoutingState.UNASSIGNED || newState == ShardRoutingState.INITIALIZING)) {
                    unassignedInfo = new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "test");
                }
                otherRouting = TestShardRouting.newShardRouting(otherRouting.getIndexName(), otherRouting.id(), otherRouting.currentNodeId(), otherRouting.relocatingNodeId(), otherRouting.primary(), newState, unassignedInfo);
                break;
        }
        if (randomBoolean()) {
            // change unassigned info
            otherRouting = TestShardRouting.newShardRouting(otherRouting.getIndexName(), otherRouting.id(), otherRouting.currentNodeId(), otherRouting.relocatingNodeId(), otherRouting.primary(), otherRouting.state(), otherRouting.unassignedInfo() == null ? new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "test") : new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, otherRouting.unassignedInfo().getMessage() + "_1"));
        }
        if (unchanged == false) {
            logger.debug("comparing\nthis  {} to\nother {}", routing, otherRouting);
            assertFalse("expected non-equality\nthis  " + routing + ",\nother " + otherRouting, routing.equalsIgnoringMetaData(otherRouting));
        }
    }
}
Also used : ShardId(org.elasticsearch.index.shard.ShardId) Snapshot(org.elasticsearch.snapshots.Snapshot) SnapshotId(org.elasticsearch.snapshots.SnapshotId) Index(org.elasticsearch.index.Index)

Example 5 with SnapshotId

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

the class UnassignedInfoTests method testExistingIndexRestored.

public void testExistingIndexRestored() {
    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().addAsRestore(metaData.index("test"), new SnapshotRecoverySource(new Snapshot("rep1", new SnapshotId("snp1", UUIDs.randomBase64UUID())), Version.CURRENT, "test")).build()).build();
    for (ShardRouting shard : clusterState.getRoutingNodes().shardsWithState(UNASSIGNED)) {
        assertThat(shard.unassignedInfo().getReason(), equalTo(UnassignedInfo.Reason.EXISTING_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)

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