Search in sources :

Example 51 with StoreFileMetaData

use of org.elasticsearch.index.store.StoreFileMetaData in project crate by crate.

the class ReplicaShardAllocatorTests method testSimpleFullMatchAllocation.

/**
 * Verifies that when there is a full match (syncId and files) we allocate it to matching node.
 */
public void testSimpleFullMatchAllocation() {
    RoutingAllocation allocation = onePrimaryOnNode1And1Replica(yesAllocationDeciders());
    DiscoveryNode nodeToMatch = randomBoolean() ? node2 : node3;
    testAllocator.addData(node1, "MATCH", new StoreFileMetadata("file1", 10, "MATCH_CHECKSUM", MIN_SUPPORTED_LUCENE_VERSION)).addData(nodeToMatch, "MATCH", 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(nodeToMatch.getId()));
}
Also used : DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) StoreFileMetadata(org.elasticsearch.index.store.StoreFileMetadata) RoutingAllocation(org.elasticsearch.cluster.routing.allocation.RoutingAllocation)

Example 52 with StoreFileMetaData

use of org.elasticsearch.index.store.StoreFileMetaData in project crate by crate.

the class ReplicaShardAllocatorTests method testCancelRecoveryIfFoundCopyWithNoopRetentionLease.

public void testCancelRecoveryIfFoundCopyWithNoopRetentionLease() {
    final UnassignedInfo unassignedInfo;
    final Set<String> failedNodeIds;
    if (randomBoolean()) {
        failedNodeIds = Collections.emptySet();
        unassignedInfo = new UnassignedInfo(UnassignedInfo.Reason.CLUSTER_RECOVERED, null);
    } else {
        failedNodeIds = new HashSet<>(randomSubsetOf(Set.of("node-4", "node-5", "node-6", "node-7")));
        unassignedInfo = new UnassignedInfo(UnassignedInfo.Reason.ALLOCATION_FAILED, null, null, randomIntBetween(1, 10), System.nanoTime(), System.currentTimeMillis(), false, UnassignedInfo.AllocationStatus.NO_ATTEMPT, failedNodeIds);
    }
    RoutingAllocation allocation = onePrimaryOnNode1And1ReplicaRecovering(yesAllocationDeciders(), unassignedInfo);
    long retainingSeqNo = randomLongBetween(1, Long.MAX_VALUE);
    testAllocator.addData(node1, Arrays.asList(newRetentionLease(node1, retainingSeqNo), newRetentionLease(node3, retainingSeqNo)), "MATCH", new StoreFileMetadata("file1", 10, "MATCH_CHECKSUM", MIN_SUPPORTED_LUCENE_VERSION));
    testAllocator.addData(node2, "NO_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(true));
    List<ShardRouting> unassignedShards = allocation.routingNodes().shardsWithState(ShardRoutingState.UNASSIGNED);
    assertThat(unassignedShards, hasSize(1));
    assertThat(unassignedShards.get(0).shardId(), equalTo(shardId));
    assertThat(unassignedShards.get(0).unassignedInfo().getNumFailedAllocations(), equalTo(0));
    assertThat(unassignedShards.get(0).unassignedInfo().getFailedNodeIds(), equalTo(failedNodeIds));
}
Also used : UnassignedInfo(org.elasticsearch.cluster.routing.UnassignedInfo) StoreFileMetadata(org.elasticsearch.index.store.StoreFileMetadata) RoutingAllocation(org.elasticsearch.cluster.routing.allocation.RoutingAllocation) TestShardRouting(org.elasticsearch.cluster.routing.TestShardRouting) ShardRouting(org.elasticsearch.cluster.routing.ShardRouting)

Example 53 with StoreFileMetaData

use of org.elasticsearch.index.store.StoreFileMetaData in project crate by crate.

the class ReplicaShardAllocatorTests method testNoPrimaryData.

/**
 * When we can't find primary data, but still find replica data, we go ahead and keep it unassigned
 * to be allocated. This is today behavior, which relies on a primary corruption identified with
 * adding a replica and having that replica actually recover and cause the corruption to be identified
 * See CorruptFileTest#
 */
public void testNoPrimaryData() {
    RoutingAllocation allocation = onePrimaryOnNode1And1Replica(yesAllocationDeciders());
    testAllocator.addData(node2, "MATCH", new StoreFileMetadata("file1", 10, "MATCH_CHECKSUM", MIN_SUPPORTED_LUCENE_VERSION));
    testAllocator.allocateUnassigned(allocation);
    assertThat(allocation.routingNodes().shardsWithState(ShardRoutingState.UNASSIGNED).size(), equalTo(1));
    assertThat(allocation.routingNodes().shardsWithState(ShardRoutingState.UNASSIGNED).get(0).shardId(), equalTo(shardId));
}
Also used : StoreFileMetadata(org.elasticsearch.index.store.StoreFileMetadata) RoutingAllocation(org.elasticsearch.cluster.routing.allocation.RoutingAllocation)

Example 54 with StoreFileMetaData

use of org.elasticsearch.index.store.StoreFileMetaData in project crate by crate.

the class ReplicaShardAllocatorTests method testDelayedAllocation.

public void testDelayedAllocation() {
    RoutingAllocation allocation = onePrimaryOnNode1And1Replica(yesAllocationDeciders(), Settings.builder().put(UnassignedInfo.INDEX_DELAYED_NODE_LEFT_TIMEOUT_SETTING.getKey(), TimeValue.timeValueHours(1)).build(), UnassignedInfo.Reason.NODE_LEFT);
    testAllocator.addData(node1, "MATCH", new StoreFileMetadata("file1", 10, "MATCH_CHECKSUM", MIN_SUPPORTED_LUCENE_VERSION));
    if (randomBoolean()) {
        // we sometime return empty list of files, make sure we test this as well
        testAllocator.addData(node2, null);
    }
    testAllocator.allocateUnassigned(allocation);
    assertThat(allocation.routingNodesChanged(), equalTo(false));
    assertThat(allocation.routingNodes().unassigned().ignored().size(), equalTo(1));
    assertThat(allocation.routingNodes().unassigned().ignored().get(0).shardId(), equalTo(shardId));
    allocation = onePrimaryOnNode1And1Replica(yesAllocationDeciders(), Settings.builder().put(UnassignedInfo.INDEX_DELAYED_NODE_LEFT_TIMEOUT_SETTING.getKey(), TimeValue.timeValueHours(1)).build(), UnassignedInfo.Reason.NODE_LEFT);
    testAllocator.addData(node2, "MATCH", new StoreFileMetadata("file1", 10, "MATCH_CHECKSUM", MIN_SUPPORTED_LUCENE_VERSION));
    testAllocator.allocateUnassigned(allocation);
    assertThat(allocation.routingNodesChanged(), equalTo(true));
    assertThat(allocation.routingNodes().shardsWithState(ShardRoutingState.INITIALIZING).size(), equalTo(1));
    assertThat(allocation.routingNodes().shardsWithState(ShardRoutingState.INITIALIZING).get(0).currentNodeId(), equalTo(node2.getId()));
}
Also used : StoreFileMetadata(org.elasticsearch.index.store.StoreFileMetadata) RoutingAllocation(org.elasticsearch.cluster.routing.allocation.RoutingAllocation)

Example 55 with StoreFileMetaData

use of org.elasticsearch.index.store.StoreFileMetaData 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)

Aggregations

StoreFileMetadata (org.elasticsearch.index.store.StoreFileMetadata)34 RoutingAllocation (org.elasticsearch.cluster.routing.allocation.RoutingAllocation)30 StoreFileMetaData (org.elasticsearch.index.store.StoreFileMetaData)25 IOException (java.io.IOException)19 ArrayList (java.util.ArrayList)18 Store (org.elasticsearch.index.store.Store)17 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)16 CorruptIndexException (org.apache.lucene.index.CorruptIndexException)13 Directory (org.apache.lucene.store.Directory)10 RetentionLease (org.elasticsearch.index.seqno.RetentionLease)10 IndexShardRelocatedException (org.elasticsearch.index.shard.IndexShardRelocatedException)10 List (java.util.List)9 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)9 Document (org.apache.lucene.document.Document)9 StringField (org.apache.lucene.document.StringField)9 RandomIndexWriter (org.apache.lucene.index.RandomIndexWriter)9 BytesArray (org.elasticsearch.common.bytes.BytesArray)9 RecoveryEngineException (org.elasticsearch.index.engine.RecoveryEngineException)9 ParsedDocument (org.elasticsearch.index.mapper.ParsedDocument)9 Settings (org.elasticsearch.common.settings.Settings)8