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


Java ShardRouting类代码示例

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


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

示例1: sendFailShard

import org.elasticsearch.cluster.routing.ShardRouting; //导入依赖的package包/类
private void sendFailShard(ShardRouting shardRouting, String message, @Nullable Exception failure, ClusterState state) {
    try {
        logger.warn(
            (Supplier<?>) () -> new ParameterizedMessage(
                "[{}] marking and sending shard failed due to [{}]", shardRouting.shardId(), message), failure);
        failedShardsCache.put(shardRouting.shardId(), shardRouting);
        shardStateAction.localShardFailed(shardRouting, message, failure, SHARD_STATE_ACTION_LISTENER, state);
    } catch (Exception inner) {
        if (failure != null) inner.addSuppressed(failure);
        logger.warn(
            (Supplier<?>) () -> new ParameterizedMessage(
                "[{}][{}] failed to mark shard as failed (because of [{}])",
                shardRouting.getIndexName(),
                shardRouting.getId(),
                message),
            inner);
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:19,代码来源:IndicesClusterStateService.java

示例2: shardFailed

import org.elasticsearch.cluster.routing.ShardRouting; //导入依赖的package包/类
@Override
public void shardFailed(ShardRouting failedShard, UnassignedInfo unassignedInfo) {
    if (failedShard.primary() && failedShard.initializing()) {
        RecoverySource recoverySource = failedShard.recoverySource();
        if (recoverySource.getType() == RecoverySource.Type.SNAPSHOT) {
            Snapshot snapshot = ((SnapshotRecoverySource) recoverySource).snapshot();
            // mark restore entry for this shard as failed when it's due to a file corruption. There is no need wait on retries
            // to restore this shard on another node if the snapshot files are corrupt. In case where a node just left or crashed,
            // however, we only want to acknowledge the restore operation once it has been successfully restored on another node.
            if (unassignedInfo.getFailure() != null && Lucene.isCorruptionException(unassignedInfo.getFailure().getCause())) {
                changes(snapshot).failedShards.put(failedShard.shardId(), new ShardRestoreStatus(failedShard.currentNodeId(),
                    RestoreInProgress.State.FAILURE, unassignedInfo.getFailure().getCause().getMessage()));
            }
        }
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:17,代码来源:RestoreService.java

示例3: listShardFiles

import org.elasticsearch.cluster.routing.ShardRouting; //导入依赖的package包/类
public List<Path> listShardFiles(ShardRouting routing) throws IOException {
    NodesStatsResponse nodeStatses = client().admin().cluster().prepareNodesStats(routing.currentNodeId()).setFs(true).get();
    ClusterState state = client().admin().cluster().prepareState().get().getState();
    final Index test = state.metaData().index("test").getIndex();
    assertThat(routing.toString(), nodeStatses.getNodes().size(), equalTo(1));
    List<Path> files = new ArrayList<>();
    for (FsInfo.Path info : nodeStatses.getNodes().get(0).getFs()) {
        String path = info.getPath();
        Path file = PathUtils.get(path).resolve("indices/" + test.getUUID() + "/" + Integer.toString(routing.getId()) + "/index");
        if (Files.exists(file)) { // multi data path might only have one path in use
            try (DirectoryStream<Path> stream = Files.newDirectoryStream(file)) {
                for (Path item : stream) {
                    files.add(item);
                }
            }
        }
    }
    return files;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:20,代码来源:CorruptedFileIT.java

示例4: assertFlushResponseEqualsShardStats

import org.elasticsearch.cluster.routing.ShardRouting; //导入依赖的package包/类
private void assertFlushResponseEqualsShardStats(ShardStats[] shardsStats, List<ShardsSyncedFlushResult> syncedFlushResults) {

        for (final ShardStats shardStats : shardsStats) {
            for (final ShardsSyncedFlushResult shardResult : syncedFlushResults) {
                if (shardStats.getShardRouting().getId() == shardResult.shardId().getId()) {
                    for (Map.Entry<ShardRouting, SyncedFlushService.ShardSyncedFlushResponse> singleResponse : shardResult.shardResponses().entrySet()) {
                        if (singleResponse.getKey().currentNodeId().equals(shardStats.getShardRouting().currentNodeId())) {
                            if (singleResponse.getValue().success()) {
                                logger.info("{} sync flushed on node {}", singleResponse.getKey().shardId(), singleResponse.getKey().currentNodeId());
                                assertNotNull(shardStats.getCommitStats().getUserData().get(Engine.SYNC_COMMIT_ID));
                            } else {
                                logger.info("{} sync flush failed for on node {}", singleResponse.getKey().shardId(), singleResponse.getKey().currentNodeId());
                                assertNull(shardStats.getCommitStats().getUserData().get(Engine.SYNC_COMMIT_ID));
                            }
                        }
                    }
                }
            }
        }
    }
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:21,代码来源:FlushIT.java

示例5: initializeUnassignedShard

import org.elasticsearch.cluster.routing.ShardRouting; //导入依赖的package包/类
/**
 * Initializes an unassigned shard on a node and removes it from the unassigned
 *
 * @param allocation the allocation
 * @param routingNodes the routing nodes
 * @param routingNode the node to initialize it to
 * @param shardRouting the shard routing that is to be matched in unassigned shards
 * @param unassignedInfo unassigned info to override
 * @param recoverySource recovery source to override
 */
protected void initializeUnassignedShard(RoutingAllocation allocation, RoutingNodes routingNodes, RoutingNode routingNode,
                                         ShardRouting shardRouting, @Nullable UnassignedInfo unassignedInfo,
                                         @Nullable RecoverySource recoverySource) {
    for (RoutingNodes.UnassignedShards.UnassignedIterator it = routingNodes.unassigned().iterator(); it.hasNext(); ) {
        ShardRouting unassigned = it.next();
        if (!unassigned.equalsIgnoringMetaData(shardRouting)) {
            continue;
        }
        if (unassignedInfo != null || recoverySource != null) {
            unassigned = it.updateUnassigned(unassignedInfo != null ? unassignedInfo : unassigned.unassignedInfo(),
                recoverySource != null ? recoverySource : unassigned.recoverySource(), allocation.changes());
        }
        it.initialize(routingNode.nodeId(), null, allocation.clusterInfo().getShardSize(unassigned, ShardRouting.UNAVAILABLE_EXPECTED_SHARD_SIZE), allocation.changes());
        return;
    }
    assert false : "shard to initialize not found in list of unassigned shards";
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:28,代码来源:AbstractAllocateAllocationCommand.java

示例6: testRandomRouting

import org.elasticsearch.cluster.routing.ShardRouting; //导入依赖的package包/类
public void testRandomRouting() {
    MetaData metaData = MetaData.builder()
            .put(IndexMetaData.builder("test1").settings(settings(Version.CURRENT)).numberOfShards(1).numberOfReplicas(1))
            .put(IndexMetaData.builder("test2").settings(settings(Version.CURRENT)).numberOfShards(1).numberOfReplicas(1))
            .build();

    RoutingTable routingTable = RoutingTable.builder()
            .addAsNew(metaData.index("test1"))
            .addAsNew(metaData.index("test2"))
            .build();

    ShardIterator shardIterator = routingTable.index("test1").shard(0).shardsRandomIt();
    ShardRouting shardRouting1 = shardIterator.nextOrNull();
    assertThat(shardRouting1, notNullValue());
    assertThat(shardIterator.nextOrNull(), notNullValue());
    assertThat(shardIterator.nextOrNull(), nullValue());

    shardIterator = routingTable.index("test1").shard(0).shardsRandomIt();
    ShardRouting shardRouting2 = shardIterator.nextOrNull();
    assertThat(shardRouting2, notNullValue());
    ShardRouting shardRouting3 = shardIterator.nextOrNull();
    assertThat(shardRouting3, notNullValue());
    assertThat(shardIterator.nextOrNull(), nullValue());
    assertThat(shardRouting1, not(sameInstance(shardRouting2)));
    assertThat(shardRouting1, sameInstance(shardRouting3));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:27,代码来源:RoutingIteratorTests.java

示例7: testIterator1

import org.elasticsearch.cluster.routing.ShardRouting; //导入依赖的package包/类
public void testIterator1() {
    MetaData metaData = MetaData.builder()
            .put(IndexMetaData.builder("test1").settings(settings(Version.CURRENT)).numberOfShards(1).numberOfReplicas(2))
            .build();
    RoutingTable routingTable = RoutingTable.builder()
            .addAsNew(metaData.index("test1"))
            .build();

    ShardIterator shardIterator = routingTable.index("test1").shard(0).shardsIt(0);
    assertThat(shardIterator.size(), equalTo(3));
    ShardRouting shardRouting1 = shardIterator.nextOrNull();
    assertThat(shardRouting1, notNullValue());
    assertThat(shardIterator.remaining(), equalTo(2));
    ShardRouting shardRouting2 = shardIterator.nextOrNull();
    assertThat(shardRouting2, notNullValue());
    assertThat(shardIterator.remaining(), equalTo(1));
    assertThat(shardRouting2, not(sameInstance(shardRouting1)));
    ShardRouting shardRouting3 = shardIterator.nextOrNull();
    assertThat(shardRouting3, notNullValue());
    assertThat(shardRouting3, not(sameInstance(shardRouting1)));
    assertThat(shardRouting3, not(sameInstance(shardRouting2)));
    assertThat(shardIterator.nextOrNull(), nullValue());
    assertThat(shardIterator.remaining(), equalTo(0));
    assertThat(shardIterator.nextOrNull(), nullValue());
    assertThat(shardIterator.remaining(), equalTo(0));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:27,代码来源:RoutingIteratorTests.java

示例8: start

import org.elasticsearch.cluster.routing.ShardRouting; //导入依赖的package包/类
public void start() {
    if (nodeIds.size() == 0) {
        try {
            onCompletion();
        } catch (Throwable e) {
            listener.onFailure(e);
        }
    } else {
        int nodeIndex = -1;
        for (Map.Entry<String, List<ShardRouting>> entry : nodeIds.entrySet()) {
            nodeIndex++;
            DiscoveryNode node = nodes.get(entry.getKey());
            sendNodeRequest(node, entry.getValue(), nodeIndex);
        }
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:17,代码来源:TransportBroadcastByNodeAction.java

示例9: shardOperation

import org.elasticsearch.cluster.routing.ShardRouting; //导入依赖的package包/类
@Override
protected ShardStats shardOperation(IndexShardStatsRequest request, ShardRouting shardRouting) {
    IndexService indexService = indicesService.indexServiceSafe(shardRouting.shardId().getIndex());
    IndexShard indexShard = indexService.shardSafe(shardRouting.shardId().id());
    // if we don't have the routing entry yet, we need it stats wise, we treat it as if the shard is not ready yet
    if (indexShard.routingEntry() == null) {
        throw new ShardNotFoundException(indexShard.shardId());
    }

    if (!indexShard.state().equals(IndexShardState.STARTED)) {
        throw new ElasticsearchException(indexShard.shardId().toString() + " state is " + indexShard.state() + ", not started");
    }
    
    CommonStatsFlags flags = new CommonStatsFlags().clear();

    if (request.dl()) {
        flags.set(CommonStatsFlags.Flag.DL);
    }

    return new ShardStats(indexShard.routingEntry(), indexShard.shardPath(), new CommonStats(indexShard, flags), indexShard.commitStats());
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:22,代码来源:TransportIndexShardStatsAction.java

示例10: testRecoveryFailsAfterMovingToRelocatedState

import org.elasticsearch.cluster.routing.ShardRouting; //导入依赖的package包/类
public void testRecoveryFailsAfterMovingToRelocatedState() throws InterruptedException, IOException {
    final IndexShard shard = newStartedShard(true);
    ShardRouting origRouting = shard.routingEntry();
    assertThat(shard.state(), equalTo(IndexShardState.STARTED));
    ShardRouting inRecoveryRouting = ShardRoutingHelper.relocate(origRouting, "some_node");
    shard.updateRoutingEntry(inRecoveryRouting);
    shard.relocated("simulate mark as relocated");
    assertThat(shard.state(), equalTo(IndexShardState.RELOCATED));
    try {
        shard.updateRoutingEntry(origRouting);
        fail("Expected IndexShardRelocatedException");
    } catch (IndexShardRelocatedException expected) {
    }

    closeShards(shard);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:17,代码来源:IndexShardTests.java

示例11: testFindAnyUnassignedShardToExplain

import org.elasticsearch.cluster.routing.ShardRouting; //导入依赖的package包/类
public void testFindAnyUnassignedShardToExplain() {
    // find unassigned primary
    ClusterState clusterState = ClusterStateCreationUtils.state("idx", randomBoolean(), ShardRoutingState.UNASSIGNED);
    ClusterAllocationExplainRequest request = new ClusterAllocationExplainRequest();
    ShardRouting shard = findShardToExplain(request, routingAllocation(clusterState));
    assertEquals(clusterState.getRoutingTable().index("idx").shard(0).primaryShard(), shard);

    // find unassigned replica
    clusterState = ClusterStateCreationUtils.state("idx", randomBoolean(), ShardRoutingState.STARTED, ShardRoutingState.UNASSIGNED);
    request = new ClusterAllocationExplainRequest();
    shard = findShardToExplain(request, routingAllocation(clusterState));
    assertEquals(clusterState.getRoutingTable().index("idx").shard(0).replicaShards().get(0), shard);

    // no unassigned shard to explain
    final ClusterState allStartedClusterState = ClusterStateCreationUtils.state("idx", randomBoolean(),
        ShardRoutingState.STARTED, ShardRoutingState.STARTED);
    final ClusterAllocationExplainRequest anyUnassignedShardsRequest = new ClusterAllocationExplainRequest();
    expectThrows(IllegalStateException.class, () ->
        findShardToExplain(anyUnassignedShardsRequest, routingAllocation(allStartedClusterState)));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:21,代码来源:ClusterAllocationExplainActionTests.java

示例12: testDontForceAllocateOnThrottleDecision

import org.elasticsearch.cluster.routing.ShardRouting; //导入依赖的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

示例13: getExpectedReplicas

import org.elasticsearch.cluster.routing.ShardRouting; //导入依赖的package包/类
private Set<ShardRouting> getExpectedReplicas(ShardId shardId, ClusterState state) {
    Set<ShardRouting> expectedReplicas = new HashSet<>();
    String localNodeId = state.nodes().getLocalNodeId();
    if (state.routingTable().hasIndex(shardId.getIndexName())) {
        for (ShardRouting shardRouting : state.routingTable().shardRoutingTable(shardId)) {
            if (shardRouting.unassigned()) {
                continue;
            }
            if (localNodeId.equals(shardRouting.currentNodeId()) == false) {
                expectedReplicas.add(shardRouting);
            }

            if (shardRouting.relocating() && localNodeId.equals(shardRouting.relocatingNodeId()) == false) {
                expectedReplicas.add(shardRouting.getTargetRelocatingShard());
            }
        }
    }
    return expectedReplicas;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:20,代码来源:ReplicationOperationTests.java

示例14: performOnReplicas

import org.elasticsearch.cluster.routing.ShardRouting; //导入依赖的package包/类
private void performOnReplicas(ReplicaRequest replicaRequest, List<ShardRouting> shards) {
    final String localNodeId = primary.routingEntry().currentNodeId();
    // If the index gets deleted after primary operation, we skip replication
    for (final ShardRouting shard : shards) {
        if (executeOnReplicas == false || shard.unassigned()) {
            if (shard.primary() == false) {
                totalShards.incrementAndGet();
            }
            continue;
        }

        if (shard.currentNodeId().equals(localNodeId) == false) {
            performOnReplica(shard, replicaRequest);
        }

        if (shard.relocating() && shard.relocatingNodeId().equals(localNodeId) == false) {
            performOnReplica(shard.getTargetRelocatingShard(), replicaRequest);
        }
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:21,代码来源:ReplicationOperation.java

示例15: decideSameNode

import org.elasticsearch.cluster.routing.ShardRouting; //导入依赖的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


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