Search in sources :

Example 1 with AllocationStatus

use of org.opensearch.cluster.routing.UnassignedInfo.AllocationStatus in project OpenSearch by opensearch-project.

the class AllocateUnassignedDecisionTests method testCachedDecisions.

public void testCachedDecisions() {
    List<AllocationStatus> cacheableStatuses = Arrays.asList(AllocationStatus.DECIDERS_NO, AllocationStatus.DECIDERS_THROTTLED, AllocationStatus.NO_VALID_SHARD_COPY, AllocationStatus.FETCHING_SHARD_DATA, AllocationStatus.DELAYED_ALLOCATION);
    for (AllocationStatus allocationStatus : cacheableStatuses) {
        if (allocationStatus == AllocationStatus.DECIDERS_THROTTLED) {
            AllocateUnassignedDecision cached = AllocateUnassignedDecision.throttle(null);
            AllocateUnassignedDecision another = AllocateUnassignedDecision.throttle(null);
            assertSame(cached, another);
            AllocateUnassignedDecision notCached = AllocateUnassignedDecision.throttle(new ArrayList<>());
            another = AllocateUnassignedDecision.throttle(new ArrayList<>());
            assertNotSame(notCached, another);
        } else {
            AllocateUnassignedDecision cached = AllocateUnassignedDecision.no(allocationStatus, null);
            AllocateUnassignedDecision another = AllocateUnassignedDecision.no(allocationStatus, null);
            assertSame(cached, another);
            AllocateUnassignedDecision notCached = AllocateUnassignedDecision.no(allocationStatus, new ArrayList<>());
            another = AllocateUnassignedDecision.no(allocationStatus, new ArrayList<>());
            assertNotSame(notCached, another);
        }
    }
    // yes decisions are not precomputed and cached
    AllocateUnassignedDecision first = AllocateUnassignedDecision.yes(node1, "abc", emptyList(), randomBoolean());
    AllocateUnassignedDecision second = AllocateUnassignedDecision.yes(node1, "abc", emptyList(), randomBoolean());
    // same fields for the ShardAllocationDecision, but should be different instances
    assertNotSame(first, second);
}
Also used : AllocationStatus(org.opensearch.cluster.routing.UnassignedInfo.AllocationStatus) ArrayList(java.util.ArrayList)

Example 2 with AllocationStatus

use of org.opensearch.cluster.routing.UnassignedInfo.AllocationStatus in project OpenSearch by opensearch-project.

the class UnassignedInfoTests method testAllocationStatusSerialization.

public void testAllocationStatusSerialization() throws IOException {
    for (AllocationStatus allocationStatus : AllocationStatus.values()) {
        BytesStreamOutput out = new BytesStreamOutput();
        allocationStatus.writeTo(out);
        ByteBufferStreamInput in = new ByteBufferStreamInput(ByteBuffer.wrap(out.bytes().toBytesRef().bytes));
        AllocationStatus readStatus = AllocationStatus.readFrom(in);
        assertThat(readStatus, equalTo(allocationStatus));
    }
}
Also used : ByteBufferStreamInput(org.opensearch.common.io.stream.ByteBufferStreamInput) AllocationStatus(org.opensearch.cluster.routing.UnassignedInfo.AllocationStatus) BytesStreamOutput(org.opensearch.common.io.stream.BytesStreamOutput)

Example 3 with AllocationStatus

use of org.opensearch.cluster.routing.UnassignedInfo.AllocationStatus in project OpenSearch by opensearch-project.

the class AllocateUnassignedDecisionTests method testNoDecision.

public void testNoDecision() {
    final AllocationStatus allocationStatus = randomFrom(AllocationStatus.DELAYED_ALLOCATION, AllocationStatus.NO_VALID_SHARD_COPY, AllocationStatus.FETCHING_SHARD_DATA);
    AllocateUnassignedDecision noDecision = AllocateUnassignedDecision.no(allocationStatus, null);
    assertTrue(noDecision.isDecisionTaken());
    assertEquals(AllocationDecision.fromAllocationStatus(allocationStatus), noDecision.getAllocationDecision());
    assertEquals(allocationStatus, noDecision.getAllocationStatus());
    if (allocationStatus == AllocationStatus.FETCHING_SHARD_DATA) {
        assertEquals("cannot allocate because information about existing shard data is still being retrieved from " + "some of the nodes", noDecision.getExplanation());
    } else if (allocationStatus == AllocationStatus.DELAYED_ALLOCATION) {
        assertThat(noDecision.getExplanation(), startsWith("cannot allocate because the cluster is still waiting"));
    } else {
        assertThat(noDecision.getExplanation(), startsWith("cannot allocate because a previous copy of the primary shard existed"));
    }
    assertNull(noDecision.getNodeDecisions());
    assertNull(noDecision.getTargetNode());
    assertNull(noDecision.getAllocationId());
    List<NodeAllocationResult> nodeDecisions = new ArrayList<>();
    nodeDecisions.add(new NodeAllocationResult(node1, Decision.NO, 1));
    nodeDecisions.add(new NodeAllocationResult(node2, Decision.NO, 2));
    final boolean reuseStore = randomBoolean();
    noDecision = AllocateUnassignedDecision.no(AllocationStatus.DECIDERS_NO, nodeDecisions, reuseStore);
    assertTrue(noDecision.isDecisionTaken());
    assertEquals(AllocationDecision.NO, noDecision.getAllocationDecision());
    assertEquals(AllocationStatus.DECIDERS_NO, noDecision.getAllocationStatus());
    if (reuseStore) {
        assertEquals("cannot allocate because allocation is not permitted to any of the nodes that hold an in-sync shard copy", noDecision.getExplanation());
    } else {
        assertEquals("cannot allocate because allocation is not permitted to any of the nodes", noDecision.getExplanation());
    }
    assertEquals(nodeDecisions.stream().sorted().collect(Collectors.toList()), noDecision.getNodeDecisions());
    // node1 should be sorted first b/c of better weight ranking
    assertEquals("node1", noDecision.getNodeDecisions().iterator().next().getNode().getId());
    assertNull(noDecision.getTargetNode());
    assertNull(noDecision.getAllocationId());
    // test bad values
    expectThrows(NullPointerException.class, () -> AllocateUnassignedDecision.no(null, null));
}
Also used : AllocationStatus(org.opensearch.cluster.routing.UnassignedInfo.AllocationStatus) ArrayList(java.util.ArrayList)

Example 4 with AllocationStatus

use of org.opensearch.cluster.routing.UnassignedInfo.AllocationStatus in project OpenSearch by opensearch-project.

the class AllocateUnassignedDecision method fromDecision.

/**
 * Creates a {@link AllocateUnassignedDecision} from the given {@link Decision} and the assigned node, if any.
 */
public static AllocateUnassignedDecision fromDecision(Decision decision, @Nullable DiscoveryNode assignedNode, @Nullable List<NodeAllocationResult> nodeDecisions) {
    final Type decisionType = decision.type();
    AllocationStatus allocationStatus = decisionType != Decision.Type.YES ? AllocationStatus.fromDecision(decisionType) : null;
    return new AllocateUnassignedDecision(allocationStatus, assignedNode, null, nodeDecisions, false, 0L, 0L);
}
Also used : Type(org.opensearch.cluster.routing.allocation.decider.Decision.Type) AllocationStatus(org.opensearch.cluster.routing.UnassignedInfo.AllocationStatus)

Example 5 with AllocationStatus

use of org.opensearch.cluster.routing.UnassignedInfo.AllocationStatus in project OpenSearch by opensearch-project.

the class AllocationDecisionTests method testFromAllocationStatus.

/**
 * Tests getting a {@link AllocationDecision} from {@link AllocationStatus}.
 */
public void testFromAllocationStatus() {
    AllocationStatus allocationStatus = rarely() ? null : randomFrom(AllocationStatus.values());
    AllocationDecision allocationDecision = AllocationDecision.fromAllocationStatus(allocationStatus);
    AllocationDecision expected;
    if (allocationStatus == null) {
        expected = AllocationDecision.YES;
    } else if (allocationStatus == AllocationStatus.DECIDERS_THROTTLED) {
        expected = AllocationDecision.THROTTLED;
    } else if (allocationStatus == AllocationStatus.FETCHING_SHARD_DATA) {
        expected = AllocationDecision.AWAITING_INFO;
    } else if (allocationStatus == AllocationStatus.DELAYED_ALLOCATION) {
        expected = AllocationDecision.ALLOCATION_DELAYED;
    } else if (allocationStatus == AllocationStatus.NO_VALID_SHARD_COPY) {
        expected = AllocationDecision.NO_VALID_SHARD_COPY;
    } else if (allocationStatus == AllocationStatus.NO_ATTEMPT) {
        expected = AllocationDecision.NO_ATTEMPT;
    } else {
        expected = AllocationDecision.NO;
    }
    assertEquals(expected, allocationDecision);
}
Also used : AllocationStatus(org.opensearch.cluster.routing.UnassignedInfo.AllocationStatus)

Aggregations

AllocationStatus (org.opensearch.cluster.routing.UnassignedInfo.AllocationStatus)5 ArrayList (java.util.ArrayList)2 Type (org.opensearch.cluster.routing.allocation.decider.Decision.Type)1 ByteBufferStreamInput (org.opensearch.common.io.stream.ByteBufferStreamInput)1 BytesStreamOutput (org.opensearch.common.io.stream.BytesStreamOutput)1