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


Java ShardRouting.isSameAllocation方法代码示例

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


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

示例1: updateFailedShardsCache

import org.elasticsearch.cluster.routing.ShardRouting; //导入方法依赖的package包/类
/**
 * Removes shard entries from the failed shards cache that are no longer allocated to this node by the master.
 * Sends shard failures for shards that are marked as actively allocated to this node but don't actually exist on the node.
 * Resends shard failures for shards that are still marked as allocated to this node but previously failed.
 *
 * @param state new cluster state
 */
private void updateFailedShardsCache(final ClusterState state) {
    RoutingNode localRoutingNode = state.getRoutingNodes().node(state.nodes().getLocalNodeId());
    if (localRoutingNode == null) {
        failedShardsCache.clear();
        return;
    }

    DiscoveryNode masterNode = state.nodes().getMasterNode();

    // remove items from cache which are not in our routing table anymore and resend failures that have not executed on master yet
    for (Iterator<Map.Entry<ShardId, ShardRouting>> iterator = failedShardsCache.entrySet().iterator(); iterator.hasNext(); ) {
        ShardRouting failedShardRouting = iterator.next().getValue();
        ShardRouting matchedRouting = localRoutingNode.getByShardId(failedShardRouting.shardId());
        if (matchedRouting == null || matchedRouting.isSameAllocation(failedShardRouting) == false) {
            iterator.remove();
        } else {
            if (masterNode != null) { // TODO: can we remove this? Is resending shard failures the responsibility of shardStateAction?
                String message = "master " + masterNode + " has not removed previously failed shard. resending shard failure";
                logger.trace("[{}] re-sending failed shard [{}], reason [{}]", matchedRouting.shardId(), matchedRouting, message);
                shardStateAction.localShardFailed(matchedRouting, message, null, SHARD_STATE_ACTION_LISTENER, state);
            }
        }
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:32,代码来源:IndicesClusterStateService.java

示例2: 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

示例3: updateRoutingEntry

import org.elasticsearch.cluster.routing.ShardRouting; //导入方法依赖的package包/类
/**
 * Updates the shards routing entry. This mutate the shards internal state depending
 * on the changes that get introduced by the new routing value. This method will persist shard level metadata
 * unless explicitly disabled.
 */
public void updateRoutingEntry(final ShardRouting newRouting, final boolean persistState) {
    final ShardRouting currentRouting = this.shardRouting;
    if (!newRouting.shardId().equals(shardId())) {
        throw new IllegalArgumentException("Trying to set a routing entry with shardId [" + newRouting.shardId() + "] on a shard with" +
                " shardId [" + shardId() + "]");
    }
    if ((currentRouting == null || newRouting.isSameAllocation(currentRouting)) == false) {
        throw new IllegalArgumentException("Trying to set a routing entry with a different allocation. Current " + currentRouting +
                ", new " + newRouting);
    }
    try {
        if (engineUnsafe() != null) {
            if (engineUnsafe() instanceof DLBasedEngine) {
                ((DLBasedEngine)engineUnsafe()).setIsPrimaryInRouting(newRouting.primary());
            }
        }
        if (currentRouting != null) {
            if (!newRouting.primary() && currentRouting.primary()) {
                logger.warn("suspect illegal state: trying to move shard from primary mode to replica mode");
            }
            // if its the same routing except for some metadata info, return
            if (currentRouting.equalsIgnoringMetaData(newRouting)) {
                this.shardRouting = newRouting; // might have a new version
                return;
            }
        }

        if (state == IndexShardState.POST_RECOVERY) {
            // if the state is started or relocating (cause it might move right away from started to relocating)
            // then move to STARTED
            if (newRouting.state() == ShardRoutingState.STARTED || newRouting.state() == ShardRoutingState.RELOCATING) {
                // we want to refresh *before* we move to internal STARTED state
                try {
                    engine().refresh("cluster_state_started");
                } catch (Throwable t) {
                    logger.debug("failed to refresh due to move to cluster wide started", t);
                }

                boolean movedToStarted = false;
                synchronized (mutex) {
                    // do the check under a mutex, so we make sure to only change to STARTED if in POST_RECOVERY
                    if (state == IndexShardState.POST_RECOVERY) {
                        changeState(IndexShardState.STARTED, "global state is [" + newRouting.state() + "]");
                        movedToStarted = true;
                    } else {
                        logger.debug("state [{}] not changed, not in POST_RECOVERY, global state is [{}]", state, newRouting.state());
                    }
                }
                if (movedToStarted) {
                    indicesLifecycle.afterIndexShardStarted(this);
                }
            }
        }
        this.shardRouting = newRouting;
        indicesLifecycle.shardRoutingChanged(this, currentRouting, newRouting);
    } finally {
        if (persistState) {
            persistMetadata(newRouting, currentRouting);
        }
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:67,代码来源:IndexShard.java


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