Search in sources :

Example 16 with RetentionLease

use of org.elasticsearch.index.seqno.RetentionLease in project crate by crate.

the class ReplicaShardAllocatorTests method testNotCancellingRecoveryIfSyncedOnExistingRecovery.

public void testNotCancellingRecoveryIfSyncedOnExistingRecovery() {
    final UnassignedInfo unassignedInfo;
    if (randomBoolean()) {
        unassignedInfo = new UnassignedInfo(UnassignedInfo.Reason.CLUSTER_RECOVERED, null);
    } else {
        unassignedInfo = new UnassignedInfo(UnassignedInfo.Reason.ALLOCATION_FAILED, null, null, randomIntBetween(1, 10), System.nanoTime(), System.currentTimeMillis(), false, UnassignedInfo.AllocationStatus.NO_ATTEMPT, Set.of("node-4"));
    }
    RoutingAllocation allocation = onePrimaryOnNode1And1ReplicaRecovering(yesAllocationDeciders(), unassignedInfo);
    List<RetentionLease> retentionLeases = new ArrayList<>();
    if (randomBoolean()) {
        long retainingSeqNoOnPrimary = randomLongBetween(0, Long.MAX_VALUE);
        retentionLeases.add(newRetentionLease(node1, retainingSeqNoOnPrimary));
        if (randomBoolean()) {
            retentionLeases.add(newRetentionLease(node2, randomLongBetween(0, retainingSeqNoOnPrimary)));
        }
        if (randomBoolean()) {
            retentionLeases.add(newRetentionLease(node3, randomLongBetween(0, retainingSeqNoOnPrimary)));
        }
    }
    testAllocator.addData(node1, retentionLeases, "MATCH", new StoreFileMetadata("file1", 10, "MATCH_CHECKSUM", MIN_SUPPORTED_LUCENE_VERSION));
    testAllocator.addData(node2, "MATCH", new StoreFileMetadata("file1", 10, "MATCH_CHECKSUM", MIN_SUPPORTED_LUCENE_VERSION));
    testAllocator.addData(node3, randomSyncId(), new StoreFileMetadata("file1", 10, "MATCH_CHECKSUM", MIN_SUPPORTED_LUCENE_VERSION));
    testAllocator.processExistingRecoveries(allocation);
    assertThat(allocation.routingNodesChanged(), equalTo(false));
    assertThat(allocation.routingNodes().shardsWithState(ShardRoutingState.UNASSIGNED).size(), equalTo(0));
}
Also used : UnassignedInfo(org.elasticsearch.cluster.routing.UnassignedInfo) RetentionLease(org.elasticsearch.index.seqno.RetentionLease) ArrayList(java.util.ArrayList) StoreFileMetadata(org.elasticsearch.index.store.StoreFileMetadata) RoutingAllocation(org.elasticsearch.cluster.routing.allocation.RoutingAllocation)

Example 17 with RetentionLease

use of org.elasticsearch.index.seqno.RetentionLease in project crate by crate.

the class ReplicaShardAllocatorTests method testPreferCopyWithHighestMatchingOperations.

public void testPreferCopyWithHighestMatchingOperations() {
    RoutingAllocation allocation = onePrimaryOnNode1And1Replica(yesAllocationDeciders());
    long retainingSeqNoOnPrimary = randomLongBetween(1, Integer.MAX_VALUE);
    long retainingSeqNoForNode2 = randomLongBetween(0, retainingSeqNoOnPrimary - 1);
    // Rarely use a seqNo above retainingSeqNoOnPrimary, which could in theory happen when primary fails and comes back quickly.
    long retainingSeqNoForNode3 = randomLongBetween(retainingSeqNoForNode2 + 1, retainingSeqNoOnPrimary + 100);
    List<RetentionLease> retentionLeases = Arrays.asList(newRetentionLease(node1, retainingSeqNoOnPrimary), newRetentionLease(node2, retainingSeqNoForNode2), newRetentionLease(node3, retainingSeqNoForNode3));
    testAllocator.addData(node1, retentionLeases, "MATCH", new StoreFileMetadata("file1", 10, "MATCH_CHECKSUM", MIN_SUPPORTED_LUCENE_VERSION));
    testAllocator.addData(node2, "NOT_MATCH", new StoreFileMetadata("file1", 10, "MATCH_CHECKSUM", MIN_SUPPORTED_LUCENE_VERSION));
    testAllocator.addData(node3, randomSyncId(), new StoreFileMetadata("file1", 10, "MATCH_CHECKSUM", MIN_SUPPORTED_LUCENE_VERSION));
    testAllocator.allocateUnassigned(allocation);
    assertThat(allocation.routingNodes().shardsWithState(ShardRoutingState.INITIALIZING).size(), equalTo(1));
    assertThat(allocation.routingNodes().shardsWithState(ShardRoutingState.INITIALIZING).get(0).currentNodeId(), equalTo(node3.getId()));
}
Also used : RetentionLease(org.elasticsearch.index.seqno.RetentionLease) StoreFileMetadata(org.elasticsearch.index.store.StoreFileMetadata) RoutingAllocation(org.elasticsearch.cluster.routing.allocation.RoutingAllocation)

Aggregations

RetentionLease (org.elasticsearch.index.seqno.RetentionLease)17 ArrayList (java.util.ArrayList)12 StoreFileMetadata (org.elasticsearch.index.store.StoreFileMetadata)9 RetentionLeases (org.elasticsearch.index.seqno.RetentionLeases)8 AtomicLong (java.util.concurrent.atomic.AtomicLong)7 IOException (java.io.IOException)5 RoutingAllocation (org.elasticsearch.cluster.routing.allocation.RoutingAllocation)5 Store (org.elasticsearch.index.store.Store)5 TimeValue (io.crate.common.unit.TimeValue)4 List (java.util.List)4 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)4 CorruptIndexException (org.apache.lucene.index.CorruptIndexException)4 ActionListener (org.elasticsearch.action.ActionListener)4 StepListener (org.elasticsearch.action.StepListener)4 BytesReference (org.elasticsearch.common.bytes.BytesReference)4 RecoveryEngineException (org.elasticsearch.index.engine.RecoveryEngineException)4 IndexShardRelocatedException (org.elasticsearch.index.shard.IndexShardRelocatedException)4 IOUtils (io.crate.common.io.IOUtils)3 Closeable (java.io.Closeable)3 Arrays (java.util.Arrays)3