Search in sources :

Example 6 with ClusterInfo

use of org.opensearch.cluster.ClusterInfo in project OpenSearch by opensearch-project.

the class ClusterAllocationExplainIT method testUnassignedReplicaDelayedAllocation.

public void testUnassignedReplicaDelayedAllocation() throws Exception {
    logger.info("--> starting 3 nodes");
    internalCluster().startNodes(3);
    prepareIndex(1, 1);
    logger.info("--> stopping the node with the replica");
    internalCluster().stopRandomNode(InternalTestCluster.nameFilter(replicaNode().getName()));
    ensureStableCluster(2);
    assertBusy(() -> assertEquals(AllocationDecision.ALLOCATION_DELAYED, client().admin().cluster().prepareAllocationExplain().setIndex("idx").setShard(0).setPrimary(false).get().getExplanation().getShardAllocationDecision().getAllocateDecision().getAllocationDecision()));
    logger.info("--> observing delayed allocation...");
    boolean includeYesDecisions = randomBoolean();
    boolean includeDiskInfo = randomBoolean();
    ClusterAllocationExplanation explanation = runExplain(false, includeYesDecisions, includeDiskInfo);
    ShardId shardId = explanation.getShard();
    boolean isPrimary = explanation.isPrimary();
    ShardRoutingState shardRoutingState = explanation.getShardState();
    DiscoveryNode currentNode = explanation.getCurrentNode();
    UnassignedInfo unassignedInfo = explanation.getUnassignedInfo();
    ClusterInfo clusterInfo = explanation.getClusterInfo();
    AllocateUnassignedDecision allocateDecision = explanation.getShardAllocationDecision().getAllocateDecision();
    MoveDecision moveDecision = explanation.getShardAllocationDecision().getMoveDecision();
    // verify shard info
    assertEquals("idx", shardId.getIndexName());
    assertEquals(0, shardId.getId());
    assertFalse(isPrimary);
    // verify current node info
    assertNotEquals(ShardRoutingState.STARTED, shardRoutingState);
    assertNull(currentNode);
    // verify unassigned info
    assertNotNull(unassignedInfo);
    assertEquals(Reason.NODE_LEFT, unassignedInfo.getReason());
    assertEquals(AllocationStatus.NO_ATTEMPT, unassignedInfo.getLastAllocationStatus());
    // verify cluster info
    verifyClusterInfo(clusterInfo, includeDiskInfo, 2);
    // verify decision objects
    assertTrue(allocateDecision.isDecisionTaken());
    assertFalse(moveDecision.isDecisionTaken());
    assertEquals(AllocationDecision.ALLOCATION_DELAYED, allocateDecision.getAllocationDecision());
    assertThat(allocateDecision.getExplanation(), startsWith("cannot allocate because the cluster is still waiting"));
    assertThat(allocateDecision.getExplanation(), containsString("despite being allowed to allocate the shard to at least one other node"));
    assertNull(allocateDecision.getAllocationId());
    assertNull(allocateDecision.getTargetNode());
    assertEquals(60000L, allocateDecision.getConfiguredDelayInMillis());
    assertThat(allocateDecision.getRemainingDelayInMillis(), greaterThan(0L));
    assertEquals(2, allocateDecision.getNodeDecisions().size());
    String primaryNodeName = primaryNodeName();
    for (NodeAllocationResult result : allocateDecision.getNodeDecisions()) {
        assertNotNull(result.getNode());
        boolean nodeHoldingPrimary = result.getNode().getName().equals(primaryNodeName);
        if (nodeHoldingPrimary) {
            // shouldn't be able to allocate to the same node as the primary, the same shard decider should say no
            assertEquals(AllocationDecision.NO, result.getNodeDecision());
            assertThat(result.getShardStoreInfo().getMatchingBytes(), greaterThan(0L));
        } else {
            assertEquals(AllocationDecision.YES, result.getNodeDecision());
            assertNull(result.getShardStoreInfo());
        }
        if (includeYesDecisions) {
            assertThat(result.getCanAllocateDecision().getDecisions().size(), greaterThan(1));
        } else {
            // if we are not including YES decisions, then the node holding the primary should have 1 NO decision,
            // the other node should have zero NO decisions
            assertEquals(nodeHoldingPrimary ? 1 : 0, result.getCanAllocateDecision().getDecisions().size());
        }
        for (Decision d : result.getCanAllocateDecision().getDecisions()) {
            if (d.label().equals("same_shard") && nodeHoldingPrimary) {
                assertEquals(Decision.Type.NO, d.type());
                assertThat(d.getExplanation(), startsWith("a copy of this shard is already allocated to this node ["));
            } else {
                assertEquals(Decision.Type.YES, d.type());
                assertNotNull(d.getExplanation());
            }
        }
    }
    // verify JSON output
    try (XContentParser parser = getParser(explanation)) {
        verifyShardInfo(parser, false, includeDiskInfo, ShardRoutingState.UNASSIGNED);
        parser.nextToken();
        assertEquals("can_allocate", parser.currentName());
        parser.nextToken();
        assertEquals(AllocationDecision.ALLOCATION_DELAYED.toString(), parser.text());
        parser.nextToken();
        assertEquals("allocate_explanation", parser.currentName());
        parser.nextToken();
        assertThat(parser.text(), startsWith("cannot allocate because the cluster is still waiting"));
        parser.nextToken();
        assertEquals("configured_delay_in_millis", parser.currentName());
        parser.nextToken();
        assertEquals(60000L, parser.longValue());
        parser.nextToken();
        assertEquals("remaining_delay_in_millis", parser.currentName());
        parser.nextToken();
        assertThat(parser.longValue(), greaterThan(0L));
        Map<String, AllocationDecision> nodes = new HashMap<>();
        nodes.put(primaryNodeName, AllocationDecision.NO);
        String[] currentNodes = internalCluster().getNodeNames();
        nodes.put(currentNodes[0].equals(primaryNodeName) ? currentNodes[1] : currentNodes[0], AllocationDecision.YES);
        verifyNodeDecisions(parser, nodes, includeYesDecisions, true);
        assertEquals(Token.END_OBJECT, parser.nextToken());
    }
}
Also used : DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) UnassignedInfo(org.opensearch.cluster.routing.UnassignedInfo) HashMap(java.util.HashMap) MoveDecision(org.opensearch.cluster.routing.allocation.MoveDecision) ShardRoutingState(org.opensearch.cluster.routing.ShardRoutingState) Matchers.containsString(org.hamcrest.Matchers.containsString) AllocationDecision(org.opensearch.cluster.routing.allocation.AllocationDecision) Decision(org.opensearch.cluster.routing.allocation.decider.Decision) MoveDecision(org.opensearch.cluster.routing.allocation.MoveDecision) AllocateUnassignedDecision(org.opensearch.cluster.routing.allocation.AllocateUnassignedDecision) ShardId(org.opensearch.index.shard.ShardId) ClusterInfo(org.opensearch.cluster.ClusterInfo) AllocationDecision(org.opensearch.cluster.routing.allocation.AllocationDecision) AllocateUnassignedDecision(org.opensearch.cluster.routing.allocation.AllocateUnassignedDecision) NodeAllocationResult(org.opensearch.cluster.routing.allocation.NodeAllocationResult) XContentParser(org.opensearch.common.xcontent.XContentParser)

Example 7 with ClusterInfo

use of org.opensearch.cluster.ClusterInfo in project OpenSearch by opensearch-project.

the class ClusterAllocationExplainIT method testAllocationFilteringOnIndexCreation.

public void testAllocationFilteringOnIndexCreation() throws Exception {
    logger.info("--> starting 2 nodes");
    internalCluster().startNodes(2);
    logger.info("--> creating an index with 1 primary, 0 replicas, with allocation filtering so the primary can't be assigned");
    prepareIndex(IndexMetadata.State.OPEN, 1, 0, Settings.builder().put("index.routing.allocation.include._name", "non_existent_node").build(), ActiveShardCount.NONE);
    boolean includeYesDecisions = randomBoolean();
    boolean includeDiskInfo = randomBoolean();
    ClusterAllocationExplanation explanation = runExplain(true, includeYesDecisions, includeDiskInfo);
    ShardId shardId = explanation.getShard();
    boolean isPrimary = explanation.isPrimary();
    ShardRoutingState shardRoutingState = explanation.getShardState();
    DiscoveryNode currentNode = explanation.getCurrentNode();
    UnassignedInfo unassignedInfo = explanation.getUnassignedInfo();
    ClusterInfo clusterInfo = explanation.getClusterInfo();
    AllocateUnassignedDecision allocateDecision = explanation.getShardAllocationDecision().getAllocateDecision();
    MoveDecision moveDecision = explanation.getShardAllocationDecision().getMoveDecision();
    // verify shard info
    assertEquals("idx", shardId.getIndexName());
    assertEquals(0, shardId.getId());
    assertTrue(isPrimary);
    // verify current node info
    assertNotEquals(ShardRoutingState.STARTED, shardRoutingState);
    assertNull(currentNode);
    // verify unassigned info
    assertNotNull(unassignedInfo);
    assertEquals(Reason.INDEX_CREATED, unassignedInfo.getReason());
    assertEquals(AllocationStatus.DECIDERS_NO, unassignedInfo.getLastAllocationStatus());
    // verify cluster info
    verifyClusterInfo(clusterInfo, includeDiskInfo, 2);
    // verify decision objects
    assertTrue(allocateDecision.isDecisionTaken());
    assertFalse(moveDecision.isDecisionTaken());
    assertEquals(AllocationDecision.NO, allocateDecision.getAllocationDecision());
    assertEquals("cannot allocate because allocation is not permitted to any of the nodes", allocateDecision.getExplanation());
    assertNull(allocateDecision.getAllocationId());
    assertNull(allocateDecision.getTargetNode());
    assertEquals(0L, allocateDecision.getConfiguredDelayInMillis());
    assertEquals(0L, allocateDecision.getRemainingDelayInMillis());
    assertEquals(2, allocateDecision.getNodeDecisions().size());
    for (NodeAllocationResult result : allocateDecision.getNodeDecisions()) {
        assertNotNull(result.getNode());
        assertEquals(AllocationDecision.NO, result.getNodeDecision());
        if (includeYesDecisions) {
            assertThat(result.getCanAllocateDecision().getDecisions().size(), greaterThan(1));
        } else {
            assertEquals(1, result.getCanAllocateDecision().getDecisions().size());
        }
        for (Decision d : result.getCanAllocateDecision().getDecisions()) {
            if (d.label().equals("filter")) {
                assertEquals(Decision.Type.NO, d.type());
                assertEquals("node does not match index setting [index.routing.allocation.include] filters " + "[_name:\"non_existent_node\"]", d.getExplanation());
            }
        }
    }
    // verify JSON output
    try (XContentParser parser = getParser(explanation)) {
        verifyShardInfo(parser, true, includeDiskInfo, ShardRoutingState.UNASSIGNED);
        parser.nextToken();
        assertEquals("can_allocate", parser.currentName());
        parser.nextToken();
        String allocationDecision = parser.text();
        assertTrue(allocationDecision.equals(AllocationDecision.NO.toString()) || allocationDecision.equals(AllocationDecision.AWAITING_INFO.toString()));
        parser.nextToken();
        assertEquals("allocate_explanation", parser.currentName());
        parser.nextToken();
        if (allocationDecision.equals("awaiting_info")) {
            assertEquals("cannot allocate because information about existing shard data is still being retrieved " + "from some of the nodes", parser.text());
        } else {
            assertEquals("cannot allocate because allocation is not permitted to any of the nodes", parser.text());
        }
        Map<String, AllocationDecision> nodeDecisions = new HashMap<>();
        for (String nodeName : internalCluster().getNodeNames()) {
            nodeDecisions.put(nodeName, AllocationDecision.NO);
        }
        verifyNodeDecisions(parser, nodeDecisions, includeYesDecisions, false);
        assertEquals(Token.END_OBJECT, parser.nextToken());
    }
}
Also used : DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) UnassignedInfo(org.opensearch.cluster.routing.UnassignedInfo) HashMap(java.util.HashMap) MoveDecision(org.opensearch.cluster.routing.allocation.MoveDecision) ShardRoutingState(org.opensearch.cluster.routing.ShardRoutingState) Matchers.containsString(org.hamcrest.Matchers.containsString) AllocationDecision(org.opensearch.cluster.routing.allocation.AllocationDecision) Decision(org.opensearch.cluster.routing.allocation.decider.Decision) MoveDecision(org.opensearch.cluster.routing.allocation.MoveDecision) AllocateUnassignedDecision(org.opensearch.cluster.routing.allocation.AllocateUnassignedDecision) ShardId(org.opensearch.index.shard.ShardId) ClusterInfo(org.opensearch.cluster.ClusterInfo) AllocationDecision(org.opensearch.cluster.routing.allocation.AllocationDecision) AllocateUnassignedDecision(org.opensearch.cluster.routing.allocation.AllocateUnassignedDecision) NodeAllocationResult(org.opensearch.cluster.routing.allocation.NodeAllocationResult) XContentParser(org.opensearch.common.xcontent.XContentParser)

Example 8 with ClusterInfo

use of org.opensearch.cluster.ClusterInfo in project OpenSearch by opensearch-project.

the class ClusterAllocationExplainIT method testUnassignedPrimaryWithExistingIndex.

public void testUnassignedPrimaryWithExistingIndex() throws Exception {
    logger.info("--> starting 2 nodes");
    internalCluster().startNodes(2);
    prepareIndex(1, 0);
    logger.info("--> stopping the node with the primary");
    internalCluster().stopRandomNode(InternalTestCluster.nameFilter(primaryNodeName()));
    ensureStableCluster(1);
    boolean includeYesDecisions = randomBoolean();
    boolean includeDiskInfo = randomBoolean();
    ClusterAllocationExplanation explanation = runExplain(true, includeYesDecisions, includeDiskInfo);
    ShardId shardId = explanation.getShard();
    boolean isPrimary = explanation.isPrimary();
    ShardRoutingState shardState = explanation.getShardState();
    DiscoveryNode currentNode = explanation.getCurrentNode();
    UnassignedInfo unassignedInfo = explanation.getUnassignedInfo();
    ClusterInfo clusterInfo = explanation.getClusterInfo();
    AllocateUnassignedDecision allocateDecision = explanation.getShardAllocationDecision().getAllocateDecision();
    MoveDecision moveDecision = explanation.getShardAllocationDecision().getMoveDecision();
    // verify shard info
    assertEquals("idx", shardId.getIndexName());
    assertEquals(0, shardId.getId());
    assertTrue(isPrimary);
    // verify current node info
    assertNotEquals(ShardRoutingState.STARTED, shardState);
    assertNull(currentNode);
    // verify unassigned info
    assertNotNull(unassignedInfo);
    assertEquals(Reason.NODE_LEFT, unassignedInfo.getReason());
    assertTrue(unassignedInfo.getLastAllocationStatus() == AllocationStatus.FETCHING_SHARD_DATA || unassignedInfo.getLastAllocationStatus() == AllocationStatus.NO_VALID_SHARD_COPY);
    // verify cluster info
    verifyClusterInfo(clusterInfo, includeDiskInfo, 1);
    // verify decision objects
    assertTrue(allocateDecision.isDecisionTaken());
    assertFalse(moveDecision.isDecisionTaken());
    assertTrue(allocateDecision.getAllocationDecision() == AllocationDecision.NO_VALID_SHARD_COPY || allocateDecision.getAllocationDecision() == AllocationDecision.AWAITING_INFO);
    if (allocateDecision.getAllocationDecision() == AllocationDecision.NO_VALID_SHARD_COPY) {
        assertEquals("cannot allocate because a previous copy of the primary shard existed but can no longer be " + "found on the nodes in the cluster", allocateDecision.getExplanation());
    } else {
        assertEquals("cannot allocate because information about existing shard data is still being retrieved from some of the nodes", allocateDecision.getExplanation());
    }
    assertNull(allocateDecision.getAllocationId());
    assertNull(allocateDecision.getTargetNode());
    assertEquals(0L, allocateDecision.getConfiguredDelayInMillis());
    assertEquals(0L, allocateDecision.getRemainingDelayInMillis());
    if (allocateDecision.getAllocationDecision() == AllocationDecision.NO_VALID_SHARD_COPY) {
        assertEquals(1, allocateDecision.getNodeDecisions().size());
        // verify JSON output
        try (XContentParser parser = getParser(explanation)) {
            verifyShardInfo(parser, true, includeDiskInfo, ShardRoutingState.UNASSIGNED);
            parser.nextToken();
            assertEquals("can_allocate", parser.currentName());
            parser.nextToken();
            assertEquals(AllocationDecision.NO_VALID_SHARD_COPY.toString(), parser.text());
            parser.nextToken();
            assertEquals("allocate_explanation", parser.currentName());
            parser.nextToken();
            assertEquals("cannot allocate because a previous copy of the primary shard existed but can no longer be found " + "on the nodes in the cluster", parser.text());
            verifyStaleShardCopyNodeDecisions(parser, 1, Collections.emptySet());
        }
    }
}
Also used : ShardId(org.opensearch.index.shard.ShardId) DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) ClusterInfo(org.opensearch.cluster.ClusterInfo) UnassignedInfo(org.opensearch.cluster.routing.UnassignedInfo) MoveDecision(org.opensearch.cluster.routing.allocation.MoveDecision) AllocateUnassignedDecision(org.opensearch.cluster.routing.allocation.AllocateUnassignedDecision) ShardRoutingState(org.opensearch.cluster.routing.ShardRoutingState) XContentParser(org.opensearch.common.xcontent.XContentParser)

Example 9 with ClusterInfo

use of org.opensearch.cluster.ClusterInfo in project OpenSearch by opensearch-project.

the class ClusterAllocationExplainIT method testUnassignedReplicaWithPriorCopy.

public void testUnassignedReplicaWithPriorCopy() throws Exception {
    logger.info("--> starting 3 nodes");
    List<String> nodes = internalCluster().startNodes(3);
    prepareIndex(1, 1);
    String primaryNodeName = primaryNodeName();
    nodes.remove(primaryNodeName);
    logger.info("--> shutting down all nodes except the one that holds the primary");
    Settings node0DataPathSettings = internalCluster().dataPathSettings(nodes.get(0));
    Settings node1DataPathSettings = internalCluster().dataPathSettings(nodes.get(1));
    internalCluster().stopRandomNode(InternalTestCluster.nameFilter(nodes.get(0)));
    internalCluster().stopRandomNode(InternalTestCluster.nameFilter(nodes.get(1)));
    ensureStableCluster(1);
    logger.info("--> setting allocation filtering to only allow allocation on the currently running node");
    client().admin().indices().prepareUpdateSettings("idx").setSettings(Settings.builder().put("index.routing.allocation.include._name", primaryNodeName)).get();
    logger.info("--> restarting the stopped nodes");
    internalCluster().startNode(Settings.builder().put("node.name", nodes.get(0)).put(node0DataPathSettings).build());
    internalCluster().startNode(Settings.builder().put("node.name", nodes.get(1)).put(node1DataPathSettings).build());
    ensureStableCluster(3);
    boolean includeYesDecisions = randomBoolean();
    boolean includeDiskInfo = randomBoolean();
    ClusterAllocationExplanation explanation = runExplain(false, includeYesDecisions, includeDiskInfo);
    ShardId shardId = explanation.getShard();
    boolean isPrimary = explanation.isPrimary();
    ShardRoutingState shardRoutingState = explanation.getShardState();
    DiscoveryNode currentNode = explanation.getCurrentNode();
    UnassignedInfo unassignedInfo = explanation.getUnassignedInfo();
    ClusterInfo clusterInfo = explanation.getClusterInfo();
    AllocateUnassignedDecision allocateDecision = explanation.getShardAllocationDecision().getAllocateDecision();
    MoveDecision moveDecision = explanation.getShardAllocationDecision().getMoveDecision();
    // verify shard info
    assertEquals("idx", shardId.getIndexName());
    assertEquals(0, shardId.getId());
    assertFalse(isPrimary);
    // verify current node info
    assertNotEquals(ShardRoutingState.STARTED, shardRoutingState);
    assertNull(currentNode);
    // verify unassigned info
    assertNotNull(unassignedInfo);
    assertEquals(Reason.NODE_LEFT, unassignedInfo.getReason());
    assertEquals(AllocationStatus.NO_ATTEMPT, unassignedInfo.getLastAllocationStatus());
    // verify cluster info
    verifyClusterInfo(clusterInfo, includeDiskInfo, 3);
    // verify decision objects
    assertTrue(allocateDecision.isDecisionTaken());
    assertFalse(moveDecision.isDecisionTaken());
    AllocationDecision decisionToAllocate = allocateDecision.getAllocationDecision();
    assertTrue(decisionToAllocate == AllocationDecision.AWAITING_INFO || decisionToAllocate == AllocationDecision.NO);
    if (decisionToAllocate == AllocationDecision.AWAITING_INFO) {
        assertEquals("cannot allocate because information about existing shard data is still being retrieved from some of the nodes", allocateDecision.getExplanation());
    } else {
        assertEquals("cannot allocate because allocation is not permitted to any of the nodes", allocateDecision.getExplanation());
    }
    assertNull(allocateDecision.getAllocationId());
    assertNull(allocateDecision.getTargetNode());
    assertEquals(0L, allocateDecision.getConfiguredDelayInMillis());
    assertEquals(0L, allocateDecision.getRemainingDelayInMillis());
    assertEquals(3, allocateDecision.getNodeDecisions().size());
    for (NodeAllocationResult result : allocateDecision.getNodeDecisions()) {
        assertNotNull(result.getNode());
        boolean nodeHoldingPrimary = result.getNode().getName().equals(primaryNodeName);
        assertEquals(AllocationDecision.NO, result.getNodeDecision());
        if (includeYesDecisions) {
            assertThat(result.getCanAllocateDecision().getDecisions().size(), greaterThan(1));
        } else {
            assertEquals(1, result.getCanAllocateDecision().getDecisions().size());
        }
        for (Decision d : result.getCanAllocateDecision().getDecisions()) {
            if (d.label().equals("same_shard") && nodeHoldingPrimary) {
                assertEquals(Decision.Type.NO, d.type());
                assertThat(d.getExplanation(), startsWith("a copy of this shard is already allocated to this node ["));
            } else if (d.label().equals("filter") && nodeHoldingPrimary == false) {
                assertEquals(Decision.Type.NO, d.type());
                assertEquals("node does not match index setting [index.routing.allocation.include] " + "filters [_name:\"" + primaryNodeName + "\"]", d.getExplanation());
            } else {
                assertEquals(Decision.Type.YES, d.type());
                assertNotNull(d.getExplanation());
            }
        }
    }
    // verify JSON output
    try (XContentParser parser = getParser(explanation)) {
        verifyShardInfo(parser, false, includeDiskInfo, ShardRoutingState.UNASSIGNED);
        parser.nextToken();
        assertEquals("can_allocate", parser.currentName());
        parser.nextToken();
        String allocationDecision = parser.text();
        assertTrue(allocationDecision.equals(AllocationDecision.NO.toString()) || allocationDecision.equals(AllocationDecision.AWAITING_INFO.toString()));
        parser.nextToken();
        assertEquals("allocate_explanation", parser.currentName());
        parser.nextToken();
        if (allocationDecision.equals("awaiting_info")) {
            assertEquals("cannot allocate because information about existing shard data is still being retrieved " + "from some of the nodes", parser.text());
        } else {
            assertEquals("cannot allocate because allocation is not permitted to any of the nodes", parser.text());
        }
        Map<String, AllocationDecision> nodeDecisions = new HashMap<>();
        for (String nodeName : internalCluster().getNodeNames()) {
            nodeDecisions.put(nodeName, AllocationDecision.NO);
        }
        verifyNodeDecisions(parser, nodeDecisions, includeYesDecisions, true);
        assertEquals(Token.END_OBJECT, parser.nextToken());
    }
}
Also used : DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) UnassignedInfo(org.opensearch.cluster.routing.UnassignedInfo) HashMap(java.util.HashMap) MoveDecision(org.opensearch.cluster.routing.allocation.MoveDecision) Matchers.containsString(org.hamcrest.Matchers.containsString) ShardRoutingState(org.opensearch.cluster.routing.ShardRoutingState) AllocationDecision(org.opensearch.cluster.routing.allocation.AllocationDecision) Decision(org.opensearch.cluster.routing.allocation.decider.Decision) MoveDecision(org.opensearch.cluster.routing.allocation.MoveDecision) AllocateUnassignedDecision(org.opensearch.cluster.routing.allocation.AllocateUnassignedDecision) ShardId(org.opensearch.index.shard.ShardId) ClusterInfo(org.opensearch.cluster.ClusterInfo) AllocationDecision(org.opensearch.cluster.routing.allocation.AllocationDecision) AllocateUnassignedDecision(org.opensearch.cluster.routing.allocation.AllocateUnassignedDecision) Settings(org.opensearch.common.settings.Settings) NodeAllocationResult(org.opensearch.cluster.routing.allocation.NodeAllocationResult) XContentParser(org.opensearch.common.xcontent.XContentParser)

Example 10 with ClusterInfo

use of org.opensearch.cluster.ClusterInfo in project OpenSearch by opensearch-project.

the class TransportClusterAllocationExplainAction method masterOperation.

@Override
protected void masterOperation(final ClusterAllocationExplainRequest request, final ClusterState state, final ActionListener<ClusterAllocationExplainResponse> listener) {
    final RoutingNodes routingNodes = state.getRoutingNodes();
    final ClusterInfo clusterInfo = clusterInfoService.getClusterInfo();
    final RoutingAllocation allocation = new RoutingAllocation(allocationDeciders, routingNodes, state, clusterInfo, snapshotsInfoService.snapshotShardSizes(), System.nanoTime());
    ShardRouting shardRouting = findShardToExplain(request, allocation);
    logger.debug("explaining the allocation for [{}], found shard [{}]", request, shardRouting);
    ClusterAllocationExplanation cae = explainShard(shardRouting, allocation, request.includeDiskInfo() ? clusterInfo : null, request.includeYesDecisions(), allocationService);
    listener.onResponse(new ClusterAllocationExplainResponse(cae));
}
Also used : ClusterInfo(org.opensearch.cluster.ClusterInfo) RoutingNodes(org.opensearch.cluster.routing.RoutingNodes) RoutingAllocation(org.opensearch.cluster.routing.allocation.RoutingAllocation) ShardRouting(org.opensearch.cluster.routing.ShardRouting)

Aggregations

ClusterInfo (org.opensearch.cluster.ClusterInfo)35 ClusterState (org.opensearch.cluster.ClusterState)21 DiskUsage (org.opensearch.cluster.DiskUsage)19 IndexMetadata (org.opensearch.cluster.metadata.IndexMetadata)19 ImmutableOpenMap (org.opensearch.common.collect.ImmutableOpenMap)19 ShardId (org.opensearch.index.shard.ShardId)19 Matchers.containsString (org.hamcrest.Matchers.containsString)18 Metadata (org.opensearch.cluster.metadata.Metadata)18 RoutingTable (org.opensearch.cluster.routing.RoutingTable)18 DiscoveryNode (org.opensearch.cluster.node.DiscoveryNode)16 ShardRouting (org.opensearch.cluster.routing.ShardRouting)16 ClusterSettings (org.opensearch.common.settings.ClusterSettings)16 UnassignedInfo (org.opensearch.cluster.routing.UnassignedInfo)14 Settings (org.opensearch.common.settings.Settings)13 RoutingNode (org.opensearch.cluster.routing.RoutingNode)11 ShardRoutingState (org.opensearch.cluster.routing.ShardRoutingState)11 ClusterInfoService (org.opensearch.cluster.ClusterInfoService)9 AllocateUnassignedDecision (org.opensearch.cluster.routing.allocation.AllocateUnassignedDecision)9 AllocationService (org.opensearch.cluster.routing.allocation.AllocationService)9 MoveDecision (org.opensearch.cluster.routing.allocation.MoveDecision)9