Search in sources :

Example 1 with RecoveriesCollection

use of org.elasticsearch.indices.recovery.RecoveriesCollection in project elasticsearch by elastic.

the class RecoveriesCollectionTests method testLastAccessTimeUpdate.

public void testLastAccessTimeUpdate() throws Exception {
    try (ReplicationGroup shards = createGroup(0)) {
        final RecoveriesCollection collection = new RecoveriesCollection(logger, threadPool, v -> {
        });
        final long recoveryId = startRecovery(collection, shards.getPrimaryNode(), shards.addReplica());
        try (RecoveriesCollection.RecoveryRef status = collection.getRecovery(recoveryId)) {
            final long lastSeenTime = status.target().lastAccessTime();
            assertBusy(() -> {
                try (RecoveriesCollection.RecoveryRef currentStatus = collection.getRecovery(recoveryId)) {
                    assertThat("access time failed to update", lastSeenTime, lessThan(currentStatus.target().lastAccessTime()));
                }
            });
        } finally {
            collection.cancelRecovery(recoveryId, "life");
        }
    }
}
Also used : RecoveriesCollection(org.elasticsearch.indices.recovery.RecoveriesCollection)

Example 2 with RecoveriesCollection

use of org.elasticsearch.indices.recovery.RecoveriesCollection in project elasticsearch by elastic.

the class RecoveriesCollectionTests method testResetRecovery.

public void testResetRecovery() throws Exception {
    try (ReplicationGroup shards = createGroup(0)) {
        shards.startAll();
        int numDocs = randomIntBetween(1, 15);
        shards.indexDocs(numDocs);
        final RecoveriesCollection collection = new RecoveriesCollection(logger, threadPool, v -> {
        });
        IndexShard shard = shards.addReplica();
        final long recoveryId = startRecovery(collection, shards.getPrimaryNode(), shard);
        RecoveryTarget recoveryTarget = collection.getRecoveryTarget(recoveryId);
        final int currentAsTarget = shard.recoveryStats().currentAsTarget();
        final int referencesToStore = recoveryTarget.store().refCount();
        IndexShard indexShard = recoveryTarget.indexShard();
        Store store = recoveryTarget.store();
        String tempFileName = recoveryTarget.getTempNameForFile("foobar");
        RecoveryTarget resetRecovery = collection.resetRecovery(recoveryId, TimeValue.timeValueMinutes(60));
        final long resetRecoveryId = resetRecovery.recoveryId();
        assertNotSame(recoveryTarget, resetRecovery);
        assertNotSame(recoveryTarget.cancellableThreads(), resetRecovery.cancellableThreads());
        assertSame(indexShard, resetRecovery.indexShard());
        assertSame(store, resetRecovery.store());
        assertEquals(referencesToStore, resetRecovery.store().refCount());
        assertEquals(currentAsTarget, shard.recoveryStats().currentAsTarget());
        assertEquals(recoveryTarget.refCount(), 0);
        expectThrows(ElasticsearchException.class, () -> recoveryTarget.store());
        expectThrows(ElasticsearchException.class, () -> recoveryTarget.indexShard());
        String resetTempFileName = resetRecovery.getTempNameForFile("foobar");
        assertNotEquals(tempFileName, resetTempFileName);
        assertEquals(currentAsTarget, shard.recoveryStats().currentAsTarget());
        try (RecoveriesCollection.RecoveryRef newRecoveryRef = collection.getRecovery(resetRecoveryId)) {
            shards.recoverReplica(shard, (s, n) -> {
                assertSame(s, newRecoveryRef.target().indexShard());
                return newRecoveryRef.target();
            }, false);
        }
        shards.assertAllEqual(numDocs);
        assertNull("recovery is done", collection.getRecovery(recoveryId));
    }
}
Also used : IndexShard(org.elasticsearch.index.shard.IndexShard) RecoveriesCollection(org.elasticsearch.indices.recovery.RecoveriesCollection) Store(org.elasticsearch.index.store.Store) RecoveryTarget(org.elasticsearch.indices.recovery.RecoveryTarget)

Example 3 with RecoveriesCollection

use of org.elasticsearch.indices.recovery.RecoveriesCollection in project elasticsearch by elastic.

the class RecoveriesCollectionTests method testRecoveryCancellation.

public void testRecoveryCancellation() throws Exception {
    try (ReplicationGroup shards = createGroup(0)) {
        final RecoveriesCollection collection = new RecoveriesCollection(logger, threadPool, v -> {
        });
        final long recoveryId = startRecovery(collection, shards.getPrimaryNode(), shards.addReplica());
        final long recoveryId2 = startRecovery(collection, shards.getPrimaryNode(), shards.addReplica());
        try (RecoveriesCollection.RecoveryRef recoveryRef = collection.getRecovery(recoveryId)) {
            ShardId shardId = recoveryRef.target().shardId();
            assertTrue("failed to cancel recoveries", collection.cancelRecoveriesForShard(shardId, "test"));
            assertThat("all recoveries should be cancelled", collection.size(), equalTo(0));
        } finally {
            collection.cancelRecovery(recoveryId, "meh");
            collection.cancelRecovery(recoveryId2, "meh");
        }
    }
}
Also used : ShardId(org.elasticsearch.index.shard.ShardId) RecoveriesCollection(org.elasticsearch.indices.recovery.RecoveriesCollection)

Example 4 with RecoveriesCollection

use of org.elasticsearch.indices.recovery.RecoveriesCollection in project elasticsearch by elastic.

the class RecoveriesCollectionTests method testRecoveryTimeout.

public void testRecoveryTimeout() throws Exception {
    try (ReplicationGroup shards = createGroup(0)) {
        final RecoveriesCollection collection = new RecoveriesCollection(logger, threadPool, v -> {
        });
        final AtomicBoolean failed = new AtomicBoolean();
        final CountDownLatch latch = new CountDownLatch(1);
        final long recoveryId = startRecovery(collection, shards.getPrimaryNode(), shards.addReplica(), new PeerRecoveryTargetService.RecoveryListener() {

            @Override
            public void onRecoveryDone(RecoveryState state) {
                latch.countDown();
            }

            @Override
            public void onRecoveryFailure(RecoveryState state, RecoveryFailedException e, boolean sendShardFailure) {
                failed.set(true);
                latch.countDown();
            }
        }, TimeValue.timeValueMillis(100));
        try {
            latch.await(30, TimeUnit.SECONDS);
            assertTrue("recovery failed to timeout", failed.get());
        } finally {
            collection.cancelRecovery(recoveryId, "meh");
        }
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) PeerRecoveryTargetService(org.elasticsearch.indices.recovery.PeerRecoveryTargetService) RecoveryFailedException(org.elasticsearch.indices.recovery.RecoveryFailedException) RecoveriesCollection(org.elasticsearch.indices.recovery.RecoveriesCollection) CountDownLatch(java.util.concurrent.CountDownLatch) RecoveryState(org.elasticsearch.indices.recovery.RecoveryState)

Aggregations

RecoveriesCollection (org.elasticsearch.indices.recovery.RecoveriesCollection)4 CountDownLatch (java.util.concurrent.CountDownLatch)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 IndexShard (org.elasticsearch.index.shard.IndexShard)1 ShardId (org.elasticsearch.index.shard.ShardId)1 Store (org.elasticsearch.index.store.Store)1 PeerRecoveryTargetService (org.elasticsearch.indices.recovery.PeerRecoveryTargetService)1 RecoveryFailedException (org.elasticsearch.indices.recovery.RecoveryFailedException)1 RecoveryState (org.elasticsearch.indices.recovery.RecoveryState)1 RecoveryTarget (org.elasticsearch.indices.recovery.RecoveryTarget)1