Search in sources :

Example 1 with Entry

use of org.elasticsearch.cluster.SnapshotsInProgress.Entry in project elasticsearch by elastic.

the class SharedClusterSnapshotRestoreIT method testDeleteOrphanSnapshot.

public void testDeleteOrphanSnapshot() throws Exception {
    Client client = client();
    logger.info("-->  creating repository");
    final String repositoryName = "test-repo";
    assertAcked(client.admin().cluster().preparePutRepository(repositoryName).setType("mock").setSettings(Settings.builder().put("location", randomRepoPath()).put("compress", randomBoolean()).put("chunk_size", randomIntBetween(100, 1000), ByteSizeUnit.BYTES)));
    logger.info("--> create the index");
    final String idxName = "test-idx";
    createIndex(idxName);
    ensureGreen();
    ClusterService clusterService = internalCluster().getInstance(ClusterService.class, internalCluster().getMasterName());
    final CountDownLatch countDownLatch = new CountDownLatch(1);
    logger.info("--> snapshot");
    final String snapshotName = "test-snap";
    CreateSnapshotResponse createSnapshotResponse = client.admin().cluster().prepareCreateSnapshot(repositoryName, snapshotName).setWaitForCompletion(true).setIndices(idxName).get();
    assertThat(createSnapshotResponse.getSnapshotInfo().successfulShards(), greaterThan(0));
    assertThat(createSnapshotResponse.getSnapshotInfo().successfulShards(), equalTo(createSnapshotResponse.getSnapshotInfo().totalShards()));
    logger.info("--> emulate an orphan snapshot");
    RepositoriesService repositoriesService = internalCluster().getInstance(RepositoriesService.class, internalCluster().getMasterName());
    final RepositoryData repositoryData = repositoriesService.repository(repositoryName).getRepositoryData();
    final IndexId indexId = repositoryData.resolveIndexId(idxName);
    clusterService.submitStateUpdateTask("orphan snapshot test", new ClusterStateUpdateTask() {

        @Override
        public ClusterState execute(ClusterState currentState) {
            // Simulate orphan snapshot
            ImmutableOpenMap.Builder<ShardId, ShardSnapshotStatus> shards = ImmutableOpenMap.builder();
            shards.put(new ShardId(idxName, "_na_", 0), new ShardSnapshotStatus("unknown-node", State.ABORTED));
            shards.put(new ShardId(idxName, "_na_", 1), new ShardSnapshotStatus("unknown-node", State.ABORTED));
            shards.put(new ShardId(idxName, "_na_", 2), new ShardSnapshotStatus("unknown-node", State.ABORTED));
            List<Entry> entries = new ArrayList<>();
            entries.add(new Entry(new Snapshot(repositoryName, createSnapshotResponse.getSnapshotInfo().snapshotId()), true, false, State.ABORTED, Collections.singletonList(indexId), System.currentTimeMillis(), repositoryData.getGenId(), shards.build()));
            return ClusterState.builder(currentState).putCustom(SnapshotsInProgress.TYPE, new SnapshotsInProgress(Collections.unmodifiableList(entries))).build();
        }

        @Override
        public void onFailure(String source, Exception e) {
            fail();
        }

        @Override
        public void clusterStateProcessed(String source, ClusterState oldState, final ClusterState newState) {
            countDownLatch.countDown();
        }
    });
    countDownLatch.await();
    logger.info("--> try deleting the orphan snapshot");
    assertAcked(client.admin().cluster().prepareDeleteSnapshot(repositoryName, snapshotName).get("10s"));
}
Also used : IndexId(org.elasticsearch.repositories.IndexId) ClusterState(org.elasticsearch.cluster.ClusterState) XContentFactory.jsonBuilder(org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder) IndexRequestBuilder(org.elasticsearch.action.index.IndexRequestBuilder) ClusterStateUpdateTask(org.elasticsearch.cluster.ClusterStateUpdateTask) Matchers.containsString(org.hamcrest.Matchers.containsString) CountDownLatch(java.util.concurrent.CountDownLatch) InvalidIndexNameException(org.elasticsearch.indices.InvalidIndexNameException) ExecutionException(java.util.concurrent.ExecutionException) RepositoryException(org.elasticsearch.repositories.RepositoryException) RepositoryData(org.elasticsearch.repositories.RepositoryData) ShardId(org.elasticsearch.index.shard.ShardId) Entry(org.elasticsearch.cluster.SnapshotsInProgress.Entry) ClusterService(org.elasticsearch.cluster.service.ClusterService) CreateSnapshotResponse(org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse) RepositoriesService(org.elasticsearch.repositories.RepositoriesService) SnapshotsInProgress(org.elasticsearch.cluster.SnapshotsInProgress) ShardSnapshotStatus(org.elasticsearch.cluster.SnapshotsInProgress.ShardSnapshotStatus) ArrayList(java.util.ArrayList) List(java.util.List) Client(org.elasticsearch.client.Client)

Example 2 with Entry

use of org.elasticsearch.cluster.SnapshotsInProgress.Entry in project elasticsearch by elastic.

the class SnapshotsInProgressSerializationTests method makeTestChanges.

@Override
protected Custom makeTestChanges(Custom testInstance) {
    SnapshotsInProgress snapshots = (SnapshotsInProgress) testInstance;
    List<Entry> entries = new ArrayList<>(snapshots.entries());
    if (randomBoolean() && entries.size() > 1) {
        // remove some elements
        int leaveElements = randomIntBetween(0, entries.size() - 1);
        entries = randomSubsetOf(leaveElements, entries.toArray(new Entry[leaveElements]));
    }
    if (randomBoolean()) {
        // add some elements
        int addElements = randomInt(10);
        for (int i = 0; i < addElements; i++) {
            entries.add(randomSnapshot());
        }
    }
    if (randomBoolean()) {
        // modify some elements
        for (int i = 0; i < entries.size(); i++) {
            if (randomBoolean()) {
                entries.set(i, new Entry(entries.get(i), randomFrom(State.values()), entries.get(i).shards()));
            }
        }
    }
    return new SnapshotsInProgress(entries);
}
Also used : Entry(org.elasticsearch.cluster.SnapshotsInProgress.Entry) ArrayList(java.util.ArrayList) SnapshotsInProgress(org.elasticsearch.cluster.SnapshotsInProgress)

Example 3 with Entry

use of org.elasticsearch.cluster.SnapshotsInProgress.Entry in project elasticsearch by elastic.

the class SnapshotsInProgressSerializationTests method randomSnapshot.

private Entry randomSnapshot() {
    Snapshot snapshot = new Snapshot(randomAsciiOfLength(10), new SnapshotId(randomAsciiOfLength(10), randomAsciiOfLength(10)));
    boolean includeGlobalState = randomBoolean();
    boolean partial = randomBoolean();
    State state = randomFrom(State.values());
    int numberOfIndices = randomIntBetween(0, 10);
    List<IndexId> indices = new ArrayList<>();
    for (int i = 0; i < numberOfIndices; i++) {
        indices.add(new IndexId(randomAsciiOfLength(10), randomAsciiOfLength(10)));
    }
    long startTime = randomLong();
    long repositoryStateId = randomLong();
    ImmutableOpenMap.Builder<ShardId, SnapshotsInProgress.ShardSnapshotStatus> builder = ImmutableOpenMap.builder();
    int shardsCount = randomIntBetween(0, 10);
    for (int j = 0; j < shardsCount; j++) {
        ShardId shardId = new ShardId(new Index(randomAsciiOfLength(10), randomAsciiOfLength(10)), randomIntBetween(0, 10));
        String nodeId = randomAsciiOfLength(10);
        State shardState = randomFrom(State.values());
        builder.put(shardId, new SnapshotsInProgress.ShardSnapshotStatus(nodeId, shardState));
    }
    ImmutableOpenMap<ShardId, SnapshotsInProgress.ShardSnapshotStatus> shards = builder.build();
    return new Entry(snapshot, includeGlobalState, partial, state, indices, startTime, repositoryStateId, shards);
}
Also used : IndexId(org.elasticsearch.repositories.IndexId) ArrayList(java.util.ArrayList) Index(org.elasticsearch.index.Index) ImmutableOpenMap(org.elasticsearch.common.collect.ImmutableOpenMap) ShardId(org.elasticsearch.index.shard.ShardId) Entry(org.elasticsearch.cluster.SnapshotsInProgress.Entry) State(org.elasticsearch.cluster.SnapshotsInProgress.State) SnapshotsInProgress(org.elasticsearch.cluster.SnapshotsInProgress)

Aggregations

ArrayList (java.util.ArrayList)3 SnapshotsInProgress (org.elasticsearch.cluster.SnapshotsInProgress)3 Entry (org.elasticsearch.cluster.SnapshotsInProgress.Entry)3 ShardId (org.elasticsearch.index.shard.ShardId)2 IndexId (org.elasticsearch.repositories.IndexId)2 List (java.util.List)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ExecutionException (java.util.concurrent.ExecutionException)1 CreateSnapshotResponse (org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse)1 IndexRequestBuilder (org.elasticsearch.action.index.IndexRequestBuilder)1 Client (org.elasticsearch.client.Client)1 ClusterState (org.elasticsearch.cluster.ClusterState)1 ClusterStateUpdateTask (org.elasticsearch.cluster.ClusterStateUpdateTask)1 ShardSnapshotStatus (org.elasticsearch.cluster.SnapshotsInProgress.ShardSnapshotStatus)1 State (org.elasticsearch.cluster.SnapshotsInProgress.State)1 ClusterService (org.elasticsearch.cluster.service.ClusterService)1 ImmutableOpenMap (org.elasticsearch.common.collect.ImmutableOpenMap)1 XContentFactory.jsonBuilder (org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder)1 Index (org.elasticsearch.index.Index)1 InvalidIndexNameException (org.elasticsearch.indices.InvalidIndexNameException)1