当前位置: 首页>>代码示例>>Java>>正文


Java RoutingAllocation类代码示例

本文整理汇总了Java中org.elasticsearch.cluster.routing.allocation.RoutingAllocation的典型用法代码示例。如果您正苦于以下问题:Java RoutingAllocation类的具体用法?Java RoutingAllocation怎么用?Java RoutingAllocation使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


RoutingAllocation类属于org.elasticsearch.cluster.routing.allocation包,在下文中一共展示了RoutingAllocation类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testDelayedAllocation

import org.elasticsearch.cluster.routing.allocation.RoutingAllocation; //导入依赖的package包/类
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"));
    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"));
    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()));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:22,代码来源:ReplicaShardAllocatorTests.java

示例2: canMove

import org.elasticsearch.cluster.routing.allocation.RoutingAllocation; //导入依赖的package包/类
private Decision canMove(ShardRouting shardRouting, RoutingAllocation allocation) {
    if (!enableRelocation && shardRouting.primary()) {
        // Only primary shards are snapshotted

        SnapshotsInProgress snapshotsInProgress = allocation.routingNodes().custom(SnapshotsInProgress.TYPE);
        if (snapshotsInProgress == null) {
            // Snapshots are not running
            return allocation.decision(Decision.YES, NAME, "no snapshots are currently running");
        }

        for (SnapshotsInProgress.Entry snapshot : snapshotsInProgress.entries()) {
            SnapshotsInProgress.ShardSnapshotStatus shardSnapshotStatus = snapshot.shards().get(shardRouting.shardId());
            if (shardSnapshotStatus != null && !shardSnapshotStatus.state().completed() && shardSnapshotStatus.nodeId() != null && shardSnapshotStatus.nodeId().equals(shardRouting.currentNodeId())) {
                logger.trace("Preventing snapshotted shard [{}] to be moved from node [{}]", shardRouting.shardId(), shardSnapshotStatus.nodeId());
                return allocation.decision(Decision.NO, NAME, "snapshot for shard [%s] is currently running on node [%s]",
                        shardRouting.shardId(), shardSnapshotStatus.nodeId());
            }
        }
    }
    return allocation.decision(Decision.YES, NAME, "shard not primary or relocation disabled");
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:22,代码来源:SnapshotInProgressAllocationDecider.java

示例3: execute

import org.elasticsearch.cluster.routing.allocation.RoutingAllocation; //导入依赖的package包/类
@Override
public BatchResult<ShardRoutingEntry> execute(ClusterState currentState, List<ShardRoutingEntry> tasks) throws Exception {
    BatchResult.Builder<ShardRoutingEntry> batchResultBuilder = BatchResult.builder();
    List<FailedRerouteAllocation.FailedShard> shardRoutingsToBeApplied = new ArrayList<>(tasks.size());
    for (ShardRoutingEntry task : tasks) {
        shardRoutingsToBeApplied.add(new FailedRerouteAllocation.FailedShard(task.shardRouting, task.message, task.finderNodeId, task.failure));
    }
    ClusterState maybeUpdatedState = currentState;
    try {
        RoutingAllocation.Result result = allocationService.applyFailedShards(currentState, shardRoutingsToBeApplied);
        if (result.changed()) {
            maybeUpdatedState = ClusterState.builder(currentState).routingResult(result).build();
        }
        batchResultBuilder.successes(tasks);
    } catch (Throwable t) {
        batchResultBuilder.failures(tasks, t);
    }
    return batchResultBuilder.build(maybeUpdatedState);
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:20,代码来源:ShardStateAction.java

示例4: testUnassignedShardAndEmptyNodesInRoutingTable

import org.elasticsearch.cluster.routing.allocation.RoutingAllocation; //导入依赖的package包/类
public void testUnassignedShardAndEmptyNodesInRoutingTable() throws Exception {
    internalCluster().startNode();
    createIndex("a");
    ensureSearchable("a");
    ClusterState current = clusterService().state();
    GatewayAllocator allocator = internalCluster().getInstance(GatewayAllocator.class);

    AllocationDeciders allocationDeciders = new AllocationDeciders(Settings.EMPTY, Collections.emptyList());
    RoutingNodes routingNodes = new RoutingNodes(
            ClusterState.builder(current)
                    .routingTable(RoutingTable.builder(current.routingTable()).remove("a").addAsRecovery(current.metaData().index("a")).build())
                    .nodes(DiscoveryNodes.EMPTY_NODES)
                    .build(), false
    );
    RoutingAllocation routingAllocation = new RoutingAllocation(allocationDeciders, routingNodes, current, ClusterInfo.EMPTY, System.nanoTime(), false);
    allocator.allocateUnassigned(routingAllocation);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:18,代码来源:RareClusterStateIT.java

示例5: testDontForceAllocateOnThrottleDecision

import org.elasticsearch.cluster.routing.allocation.RoutingAllocation; //导入依赖的package包/类
/**
 * Tests that when the nodes with prior copies of the given shard return a THROTTLE decision,
 * then we do not force allocate to that node but instead throttle.
 */
public void testDontForceAllocateOnThrottleDecision() {
    testAllocator.addData(node1, "allocId1", randomBoolean());
    AllocationDeciders deciders = new AllocationDeciders(Settings.EMPTY, Arrays.asList(
        // since we have a NO decision for allocating a shard (because the second decider returns a NO decision),
        // the allocator will see if it can force assign the primary, and in this case,
        // the TestAllocateDecision's decision for force allocating is to THROTTLE (using
        // the default behavior) so despite the other decider's decision to return YES for
        // force allocating the shard, we still THROTTLE due to the decision from TestAllocateDecision
        new TestAllocateDecision(Decision.THROTTLE), getNoDeciderThatAllowsForceAllocate()
    ));
    RoutingAllocation allocation = routingAllocationWithOnePrimaryNoReplicas(deciders, CLUSTER_RECOVERED, "allocId1");
    testAllocator.allocateUnassigned(allocation);
    assertThat(allocation.routingNodesChanged(), equalTo(true));
    List<ShardRouting> ignored = allocation.routingNodes().unassigned().ignored();
    assertEquals(ignored.size(), 1);
    assertEquals(ignored.get(0).unassignedInfo().getLastAllocationStatus(), AllocationStatus.DECIDERS_THROTTLED);
    assertTrue(allocation.routingNodes().shardsWithState(ShardRoutingState.INITIALIZING).isEmpty());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:23,代码来源:PrimaryShardAllocatorTests.java

示例6: buildNodesToAllocate

import org.elasticsearch.cluster.routing.allocation.RoutingAllocation; //导入依赖的package包/类
/**
 * Based on the nodes and versions, build the list of yes/no/throttle nodes that the shard applies to.
 */
private NodesToAllocate buildNodesToAllocate(ShardRouting shard, RoutingAllocation allocation, NodesAndVersions nodesAndVersions) {
    List<DiscoveryNode> yesNodes = new ArrayList<>();
    List<DiscoveryNode> throttledNodes = new ArrayList<>();
    List<DiscoveryNode> noNodes = new ArrayList<>();
    for (DiscoveryNode discoNode : nodesAndVersions.nodes) {
        RoutingNode node = allocation.routingNodes().node(discoNode.id());
        if (node == null) {
            continue;
        }

        Decision decision = allocation.deciders().canAllocate(shard, node, allocation);
        if (decision.type() == Decision.Type.THROTTLE) {
            throttledNodes.add(discoNode);
        } else if (decision.type() == Decision.Type.NO) {
            noNodes.add(discoNode);
        } else {
            yesNodes.add(discoNode);
        }
    }
    return new NodesToAllocate(Collections.unmodifiableList(yesNodes), Collections.unmodifiableList(throttledNodes), Collections.unmodifiableList(noNodes));
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:25,代码来源:PrimaryShardAllocator.java

示例7: canAllocate

import org.elasticsearch.cluster.routing.allocation.RoutingAllocation; //导入依赖的package包/类
@Override
public Decision canAllocate(ShardRouting shardRouting, RoutingAllocation allocation) {
    Decision.Multi ret = new Decision.Multi();
    for (AllocationDecider allocationDecider : allocations) {
        Decision decision = allocationDecider.canAllocate(shardRouting, allocation);
        // short track if a NO is returned.
        if (decision == Decision.NO) {
            if (!allocation.debugDecision()) {
                return decision;
            } else {
                ret.add(decision);
            }
        } else if (decision != Decision.ALWAYS) {
            ret.add(decision);
        }
    }
    return ret;
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:19,代码来源:AllocationDeciders.java

示例8: decideSameNode

import org.elasticsearch.cluster.routing.allocation.RoutingAllocation; //导入依赖的package包/类
private Decision decideSameNode(ShardRouting shardRouting, RoutingNode node, RoutingAllocation allocation,
                                Iterable<ShardRouting> assignedShards) {
    for (ShardRouting assignedShard : assignedShards) {
        if (node.nodeId().equals(assignedShard.currentNodeId())) {
            if (assignedShard.isSameAllocation(shardRouting)) {
                return allocation.decision(Decision.NO, NAME,
                    "the shard cannot be allocated to the node on which it already exists [%s]",
                    shardRouting.toString());
            } else {
                return allocation.decision(Decision.NO, NAME,
                    "the shard cannot be allocated to the same node on which a copy of the shard already exists [%s]",
                    assignedShard.toString());
            }
        }
    }
    return allocation.decision(Decision.YES, NAME, "the shard does not exist on the same node");
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:18,代码来源:SameShardAllocationDecider.java

示例9: shouldIndexFilter

import org.elasticsearch.cluster.routing.allocation.RoutingAllocation; //导入依赖的package包/类
private Decision shouldIndexFilter(IndexMetaData indexMd, RoutingNode node, RoutingAllocation allocation) {
    if (indexMd.requireFilters() != null) {
        if (!indexMd.requireFilters().match(node.node())) {
            return allocation.decision(Decision.NO, NAME, "node does not match index required filters [%s]", indexMd.requireFilters());
        }
    }
    if (indexMd.includeFilters() != null) {
        if (!indexMd.includeFilters().match(node.node())) {
            return allocation.decision(Decision.NO, NAME, "node does not match index include filters [%s]", indexMd.includeFilters());
        }
    }
    if (indexMd.excludeFilters() != null) {
        if (indexMd.excludeFilters().match(node.node())) {
            return allocation.decision(Decision.NO, NAME, "node matches index exclude filters [%s]", indexMd.excludeFilters());
        }
    }
    return null;
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:19,代码来源:FilterAllocationDecider.java

示例10: canAllocate

import org.elasticsearch.cluster.routing.allocation.RoutingAllocation; //导入依赖的package包/类
@Override
public Decision canAllocate(ShardRouting shardRouting, RoutingAllocation allocation) {
    Decision.Multi ret = new Decision.Multi();
    for (AllocationDecider allocationDecider : allocations) {
        Decision decision = allocationDecider.canAllocate(shardRouting, allocation);
        // short track if a NO is returned.
        if (decision == Decision.NO) {
            if (!allocation.debugDecision()) {
                return decision;
            } else {
                ret.add(decision);
            }
        } else if (decision != Decision.ALWAYS
                    && (allocation.getDebugMode() != EXCLUDE_YES_DECISIONS || decision.type() != Decision.Type.YES)) {
            ret.add(decision);
        }
    }
    return ret;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:20,代码来源:AllocationDeciders.java

示例11: explainShard

import org.elasticsearch.cluster.routing.allocation.RoutingAllocation; //导入依赖的package包/类
public static ClusterAllocationExplanation explainShard(ShardRouting shardRouting, RoutingAllocation allocation,
                                                        ClusterInfo clusterInfo, boolean includeYesDecisions,
                                                        GatewayAllocator gatewayAllocator, ShardsAllocator shardAllocator) {
    allocation.setDebugMode(includeYesDecisions ? DebugMode.ON : DebugMode.EXCLUDE_YES_DECISIONS);

    ShardAllocationDecision shardDecision;
    if (shardRouting.initializing() || shardRouting.relocating()) {
        shardDecision = ShardAllocationDecision.NOT_TAKEN;
    } else {
        AllocateUnassignedDecision allocateDecision = shardRouting.unassigned() ?
            gatewayAllocator.decideUnassignedShardAllocation(shardRouting, allocation) : AllocateUnassignedDecision.NOT_TAKEN;
        if (allocateDecision.isDecisionTaken() == false) {
            shardDecision = shardAllocator.decideShardAllocation(shardRouting, allocation);
        } else {
            shardDecision = new ShardAllocationDecision(allocateDecision, MoveDecision.NOT_TAKEN);
        }
    }

    return new ClusterAllocationExplanation(shardRouting,
        shardRouting.currentNodeId() != null ? allocation.nodes().get(shardRouting.currentNodeId()) : null,
        shardRouting.relocatingNodeId() != null ? allocation.nodes().get(shardRouting.relocatingNodeId()) : null,
        clusterInfo, shardDecision);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:24,代码来源:TransportClusterAllocationExplainAction.java

示例12: onePrimaryOnNode1And1ReplicaRecovering

import org.elasticsearch.cluster.routing.allocation.RoutingAllocation; //导入依赖的package包/类
private RoutingAllocation onePrimaryOnNode1And1ReplicaRecovering(AllocationDeciders deciders) {
    ShardRouting primaryShard = TestShardRouting.newShardRouting(shardId, node1.getId(), true, ShardRoutingState.STARTED);
    MetaData metaData = MetaData.builder()
            .put(IndexMetaData.builder(shardId.getIndexName()).settings(settings(Version.CURRENT))
                .numberOfShards(1).numberOfReplicas(1)
                .putInSyncAllocationIds(0, Sets.newHashSet(primaryShard.allocationId().getId())))
            .build();
    RoutingTable routingTable = RoutingTable.builder()
            .add(IndexRoutingTable.builder(shardId.getIndex())
                            .addIndexShard(new IndexShardRoutingTable.Builder(shardId)
                                    .addShard(primaryShard)
                                    .addShard(TestShardRouting.newShardRouting(shardId, node2.getId(), null, false, ShardRoutingState.INITIALIZING, new UnassignedInfo(UnassignedInfo.Reason.CLUSTER_RECOVERED, null)))
                                    .build())
            )
            .build();
    ClusterState state = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY))
            .metaData(metaData)
            .routingTable(routingTable)
            .nodes(DiscoveryNodes.builder().add(node1).add(node2).add(node3)).build();
    return new RoutingAllocation(deciders, new RoutingNodes(state, false), state, ClusterInfo.EMPTY, System.nanoTime(), false);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:22,代码来源:ReplicaShardAllocatorTests.java

示例13: testShardLockObtainFailedExceptionPreferOtherValidCopies

import org.elasticsearch.cluster.routing.allocation.RoutingAllocation; //导入依赖的package包/类
/**
 * Tests that when one node returns a ShardLockObtainFailedException and another properly loads the store, it will
 * select the second node as target
 */
public void testShardLockObtainFailedExceptionPreferOtherValidCopies() {
    String allocId1 = randomAsciiOfLength(10);
    String allocId2 = randomAsciiOfLength(10);
    final RoutingAllocation allocation = routingAllocationWithOnePrimaryNoReplicas(yesAllocationDeciders(), CLUSTER_RECOVERED,
        allocId1, allocId2);;
    testAllocator.addData(node1, allocId1, randomBoolean(),
        new ShardLockObtainFailedException(shardId, "test"));
    testAllocator.addData(node2, allocId2, randomBoolean(), null);
    testAllocator.allocateUnassigned(allocation);
    assertThat(allocation.routingNodesChanged(), equalTo(true));
    assertThat(allocation.routingNodes().unassigned().ignored().isEmpty(), equalTo(true));
    assertThat(allocation.routingNodes().shardsWithState(ShardRoutingState.INITIALIZING).size(), equalTo(1));
    assertThat(allocation.routingNodes().shardsWithState(ShardRoutingState.INITIALIZING).get(0).currentNodeId(), equalTo(node2.getId()));
    // check that allocation id is reused
    assertThat(allocation.routingNodes().shardsWithState(ShardRoutingState.INITIALIZING).get(0).allocationId().getId(), equalTo(allocId2));
    assertClusterHealthStatus(allocation, ClusterHealthStatus.YELLOW);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:22,代码来源:PrimaryShardAllocatorTests.java

示例14: getRestoreRoutingAllocation

import org.elasticsearch.cluster.routing.allocation.RoutingAllocation; //导入依赖的package包/类
private RoutingAllocation getRestoreRoutingAllocation(AllocationDeciders allocationDeciders, String... allocIds) {
    MetaData metaData = MetaData.builder()
        .put(IndexMetaData.builder(shardId.getIndexName()).settings(settings(Version.CURRENT)).numberOfShards(1).numberOfReplicas(0)
            .putInSyncAllocationIds(0, Sets.newHashSet(allocIds)))
        .build();

    final Snapshot snapshot = new Snapshot("test", new SnapshotId("test", UUIDs.randomBase64UUID()));
    RoutingTable routingTable = RoutingTable.builder()
        .addAsRestore(metaData.index(shardId.getIndex()), new SnapshotRecoverySource(snapshot, Version.CURRENT, shardId.getIndexName()))
        .build();
    ClusterState state = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY))
        .metaData(metaData)
        .routingTable(routingTable)
        .nodes(DiscoveryNodes.builder().add(node1).add(node2).add(node3)).build();
    return new RoutingAllocation(allocationDeciders, new RoutingNodes(state, false), state, null, System.nanoTime(), false);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:17,代码来源:PrimaryShardAllocatorTests.java

示例15: canMove

import org.elasticsearch.cluster.routing.allocation.RoutingAllocation; //导入依赖的package包/类
private Decision canMove(ShardRouting shardRouting, RoutingAllocation allocation) {
    if (shardRouting.primary()) {
        // Only primary shards are snapshotted

        SnapshotsInProgress snapshotsInProgress = allocation.custom(SnapshotsInProgress.TYPE);
        if (snapshotsInProgress == null) {
            // Snapshots are not running
            return allocation.decision(Decision.YES, NAME, "no snapshots are currently running");
        }

        for (SnapshotsInProgress.Entry snapshot : snapshotsInProgress.entries()) {
            SnapshotsInProgress.ShardSnapshotStatus shardSnapshotStatus = snapshot.shards().get(shardRouting.shardId());
            if (shardSnapshotStatus != null && !shardSnapshotStatus.state().completed() && shardSnapshotStatus.nodeId() != null &&
                    shardSnapshotStatus.nodeId().equals(shardRouting.currentNodeId())) {
                if (logger.isTraceEnabled()) {
                    logger.trace("Preventing snapshotted shard [{}] from being moved away from node [{}]",
                            shardRouting.shardId(), shardSnapshotStatus.nodeId());
                }
                return allocation.decision(Decision.THROTTLE, NAME,
                    "waiting for snapshotting of shard [%s] to complete on this node [%s]",
                    shardRouting.shardId(), shardSnapshotStatus.nodeId());
            }
        }
    }
    return allocation.decision(Decision.YES, NAME, "the shard is not being snapshotted");
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:27,代码来源:SnapshotInProgressAllocationDecider.java


注:本文中的org.elasticsearch.cluster.routing.allocation.RoutingAllocation类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。