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


Java ShardRouting.primary方法代码示例

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


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

示例1: canMove

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

示例2: shardFailed

import org.elasticsearch.cluster.routing.ShardRouting; //导入方法依赖的package包/类
@Override
public void shardFailed(ShardRouting failedShard, UnassignedInfo unassignedInfo) {
    if (failedShard.active() && unassignedInfo.getReason() != UnassignedInfo.Reason.NODE_LEFT) {
        removeAllocationId(failedShard);

        if (failedShard.primary()) {
            Updates updates = changes(failedShard.shardId());
            if (updates.firstFailedPrimary == null) {
                // more than one primary can be failed (because of batching, primary can be failed, replica promoted and then failed...)
                updates.firstFailedPrimary = failedShard;
            }
        }
    }

    if (failedShard.active() && failedShard.primary()) {
        increasePrimaryTerm(failedShard.shardId());
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:19,代码来源:IndexMetaDataUpdater.java

示例3: startPrimaries

import org.elasticsearch.cluster.routing.ShardRouting; //导入方法依赖的package包/类
private ClusterState startPrimaries(final ClusterState clusterState, final String indexName) {
    RoutingTable routingTable = clusterState.routingTable();
    IndexRoutingTable indexRoutingTable = routingTable.index(indexName);
    IndexRoutingTable.Builder newIndexRoutingTable = IndexRoutingTable.builder(indexRoutingTable.getIndex());
    for (final ObjectCursor<IndexShardRoutingTable> shardEntry : indexRoutingTable.getShards().values()) {
        final IndexShardRoutingTable shardRoutingTable = shardEntry.value;
        for (ShardRouting shardRouting : shardRoutingTable.getShards()) {
            if (shardRouting.primary()) {
                shardRouting = shardRouting.initialize(randomAsciiOfLength(8), null, shardRouting.getExpectedShardSize())
                                   .moveToStarted();
            }
            newIndexRoutingTable.addShard(shardRouting);
        }
    }
    routingTable = RoutingTable.builder(routingTable).add(newIndexRoutingTable).build();
    return ClusterState.builder(clusterState).routingTable(routingTable).build();
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:18,代码来源:ActiveShardCountTests.java

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

示例5: canAllocate

import org.elasticsearch.cluster.routing.ShardRouting; //导入方法依赖的package包/类
@Override
public Decision canAllocate(ShardRouting shardRouting, RoutingNode node, RoutingAllocation allocation) {
    if (allocation.ignoreDisable()) {
        return allocation.decision(Decision.YES, NAME, "allocation disabling is ignored");
    }
    Settings indexSettings = allocation.routingNodes().metaData().index(shardRouting.index()).getSettings();
    if (shardRouting.primary() && shardRouting.allocatedPostIndexCreate() == false) {
        // if its primary, and it hasn't been allocated post API (meaning its a "fresh newly created shard"), only disable allocation
        // on a special disable allocation flag
        if (indexSettings.getAsBoolean(INDEX_ROUTING_ALLOCATION_DISABLE_NEW_ALLOCATION, disableNewAllocation)) {
            return allocation.decision(Decision.NO, NAME, "new primary allocation is disabled");
        } else {
            return allocation.decision(Decision.YES, NAME, "new primary allocation is enabled");
        }
    }
    if (indexSettings.getAsBoolean(INDEX_ROUTING_ALLOCATION_DISABLE_ALLOCATION, disableAllocation)) {
        return allocation.decision(Decision.NO, NAME, "all allocation is disabled");
    }
    if (indexSettings.getAsBoolean(INDEX_ROUTING_ALLOCATION_DISABLE_REPLICA_ALLOCATION, disableReplicaAllocation)) {
        if (shardRouting.primary()) {
            return allocation.decision(Decision.YES, NAME, "primary allocation is enabled");
        } else {
            return allocation.decision(Decision.NO, NAME, "replica allocation is disabled");
        }
    }
    return allocation.decision(Decision.YES, NAME, "all allocation is enabled");
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:28,代码来源:DisableAllocationDecider.java

示例6: canRebalance

import org.elasticsearch.cluster.routing.ShardRouting; //导入方法依赖的package包/类
@Override
public Decision canRebalance(ShardRouting shardRouting, RoutingAllocation allocation) {
    if (allocation.ignoreDisable()) {
        return allocation.decision(Decision.YES, NAME, "rebalance disabling is ignored");
    }

    Settings indexSettings = allocation.routingNodes().metaData().index(shardRouting.index()).getSettings();
    String enableIndexValue = indexSettings.get(INDEX_ROUTING_REBALANCE_ENABLE);
    final Rebalance enable;
    if (enableIndexValue != null) {
        enable = Rebalance.parse(enableIndexValue);
    } else {
        enable = this.enableRebalance;
    }
    switch (enable) {
        case ALL:
            return allocation.decision(Decision.YES, NAME, "all rebalancing is allowed");
        case NONE:
            return allocation.decision(Decision.NO, NAME, "no rebalancing is allowed");
        case PRIMARIES:
            if (shardRouting.primary()) {
                return allocation.decision(Decision.YES, NAME, "primary rebalancing is allowed");
            } else {
                return allocation.decision(Decision.NO, NAME, "replica rebalancing is forbidden");
            }
        case REPLICAS:
            if (shardRouting.primary() == false) {
                return allocation.decision(Decision.YES, NAME, "replica rebalancing is allowed");
            } else {
                return allocation.decision(Decision.NO, NAME, "primary rebalancing is forbidden");
            }
        default:
            throw new IllegalStateException("Unknown rebalance option");
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:36,代码来源:EnableAllocationDecider.java

示例7: getAllocation

import org.elasticsearch.cluster.routing.ShardRouting; //导入方法依赖的package包/类
private IndicesShardStoresResponse.StoreStatus.Allocation getAllocation(String index, int shardID, DiscoveryNode node) {
    for (ShardRouting shardRouting : routingNodes.node(node.id())) {
        ShardId shardId = shardRouting.shardId();
        if (shardId.id() == shardID && shardId.getIndex().equals(index)) {
            if (shardRouting.primary()) {
                return IndicesShardStoresResponse.StoreStatus.Allocation.PRIMARY;
            } else if (shardRouting.assignedToNode()) {
                return IndicesShardStoresResponse.StoreStatus.Allocation.REPLICA;
            } else {
                return IndicesShardStoresResponse.StoreStatus.Allocation.UNUSED;
            }
        }
    }
    return IndicesShardStoresResponse.StoreStatus.Allocation.UNUSED;
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:16,代码来源:TransportIndicesShardStoresAction.java

示例8: isResponsibleFor

import org.elasticsearch.cluster.routing.ShardRouting; //导入方法依赖的package包/类
/**
 * Is the allocator responsible for allocating the given {@link ShardRouting}?
 */
private static boolean isResponsibleFor(final ShardRouting shard) {
    return shard.primary() == false // must be a replica
               && shard.unassigned() // must be unassigned
               // if we are allocating a replica because of index creation, no need to go and find a copy, there isn't one...
               && shard.unassignedInfo().getReason() != UnassignedInfo.Reason.INDEX_CREATED;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:10,代码来源:ReplicaShardAllocator.java

示例9: canRebalance

import org.elasticsearch.cluster.routing.ShardRouting; //导入方法依赖的package包/类
@Override
public Decision canRebalance(ShardRouting shardRouting, RoutingAllocation allocation) {
    if (allocation.ignoreDisable()) {
        return allocation.decision(Decision.YES, NAME, "allocation is explicitly ignoring any disabling of relocation");
    }

    Settings indexSettings = allocation.metaData().getIndexSafe(shardRouting.index()).getSettings();
    final Rebalance enable;
    final boolean usedIndexSetting;
    if (INDEX_ROUTING_REBALANCE_ENABLE_SETTING.exists(indexSettings)) {
        enable = INDEX_ROUTING_REBALANCE_ENABLE_SETTING.get(indexSettings);
        usedIndexSetting = true;
    } else {
        enable = this.enableRebalance;
        usedIndexSetting = false;
    }
    switch (enable) {
        case ALL:
            return allocation.decision(Decision.YES, NAME, "all rebalancing is allowed");
        case NONE:
            return allocation.decision(Decision.NO, NAME, "no rebalancing is allowed due to %s", setting(enable, usedIndexSetting));
        case PRIMARIES:
            if (shardRouting.primary()) {
                return allocation.decision(Decision.YES, NAME, "primary rebalancing is allowed");
            } else {
                return allocation.decision(Decision.NO, NAME, "replica rebalancing is forbidden due to %s",
                                            setting(enable, usedIndexSetting));
            }
        case REPLICAS:
            if (shardRouting.primary() == false) {
                return allocation.decision(Decision.YES, NAME, "replica rebalancing is allowed");
            } else {
                return allocation.decision(Decision.NO, NAME, "primary rebalancing is forbidden due to %s",
                                            setting(enable, usedIndexSetting));
            }
        default:
            throw new IllegalStateException("Unknown rebalance option");
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:40,代码来源:EnableAllocationDecider.java

示例10: updateRoutingEntry

import org.elasticsearch.cluster.routing.ShardRouting; //导入方法依赖的package包/类
/**
 * In addition to the regular accounting done in
 * {@link IndexShard#updateRoutingEntry(org.elasticsearch.cluster.routing.ShardRouting, boolean)},
 * if this shadow replica needs to be promoted to a primary, the shard is
 * failed in order to allow a new primary to be re-allocated.
 */
@Override
public void updateRoutingEntry(ShardRouting newRouting, boolean persistState) {
    if (newRouting.primary() == true) {// becoming a primary
        throw new IllegalStateException("can't promote shard to primary");
    }
    super.updateRoutingEntry(newRouting, persistState);
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:14,代码来源:ShadowIndexShard.java

示例11: canAllocate

import org.elasticsearch.cluster.routing.ShardRouting; //导入方法依赖的package包/类
@Override
public Decision canAllocate(ShardRouting shardRouting, RoutingNode node, RoutingAllocation allocation) {
    if (allocation.ignoreDisable()) {
        return allocation.decision(Decision.YES, NAME, "allocation disabling is ignored");
    }

    Settings indexSettings = allocation.routingNodes().metaData().index(shardRouting.index()).getSettings();
    String enableIndexValue = indexSettings.get(INDEX_ROUTING_ALLOCATION_ENABLE);
    final Allocation enable;
    if (enableIndexValue != null) {
        enable = Allocation.parse(enableIndexValue);
    } else {
        enable = this.enableAllocation;
    }
    switch (enable) {
        case ALL:
            return allocation.decision(Decision.YES, NAME, "all allocations are allowed");
        case NONE:
            return allocation.decision(Decision.NO, NAME, "no allocations are allowed");
        case NEW_PRIMARIES:
            if (shardRouting.primary() && shardRouting.allocatedPostIndexCreate() == false) {
                return allocation.decision(Decision.YES, NAME, "new primary allocations are allowed");
            } else {
                return allocation.decision(Decision.NO, NAME, "non-new primary allocations are forbidden");
            }
        case PRIMARIES:
            if (shardRouting.primary()) {
                return allocation.decision(Decision.YES, NAME, "primary allocations are allowed");
            } else {
                return allocation.decision(Decision.NO, NAME, "replica allocations are forbidden");
            }
        default:
            throw new IllegalStateException("Unknown allocation option");
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:36,代码来源:EnableAllocationDecider.java

示例12: getAllocationStatus

import org.elasticsearch.cluster.routing.ShardRouting; //导入方法依赖的package包/类
private IndicesShardStoresResponse.StoreStatus.AllocationStatus getAllocationStatus(String index, int shardID, DiscoveryNode node) {
    for (ShardRouting shardRouting : routingNodes.node(node.getId())) {
        ShardId shardId = shardRouting.shardId();
        if (shardId.id() == shardID && shardId.getIndexName().equals(index)) {
            if (shardRouting.primary()) {
                return IndicesShardStoresResponse.StoreStatus.AllocationStatus.PRIMARY;
            } else if (shardRouting.assignedToNode()) {
                return IndicesShardStoresResponse.StoreStatus.AllocationStatus.REPLICA;
            } else {
                return IndicesShardStoresResponse.StoreStatus.AllocationStatus.UNUSED;
            }
        }
    }
    return IndicesShardStoresResponse.StoreStatus.AllocationStatus.UNUSED;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:16,代码来源:TransportIndicesShardStoresAction.java

示例13: highestPrimary

import org.elasticsearch.cluster.routing.ShardRouting; //导入方法依赖的package包/类
public int highestPrimary() {
    if (highestPrimary == -1) {
        int maxId = -1;
        for (ShardRouting shard : shards.keySet()) {
            if (shard.primary()) {
                maxId = Math.max(maxId, shard.id());
            }
        }
        return highestPrimary = maxId;
    }
    return highestPrimary;
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:13,代码来源:BalancedShardsAllocator.java

示例14: getShardStateMetadata

import org.elasticsearch.cluster.routing.ShardRouting; //导入方法依赖的package包/类
ShardStateMetaData getShardStateMetadata(IndexShard shard) {
    ShardRouting shardRouting = shard.routingEntry();
    if (shardRouting == null) {
        return null;
    } else {
        return new ShardStateMetaData(shardRouting.primary(), shard.indexSettings().getUUID(), shardRouting.allocationId());
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:9,代码来源:IndexShardTests.java

示例15: numReplicas

import org.elasticsearch.cluster.routing.ShardRouting; //导入方法依赖的package包/类
public int numReplicas() {
    int count = 0;
    for (ShardRouting msr : routing) {
        if (msr.primary() == false && msr.id()==0) {
            count++;
        }
    }
    return count;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:10,代码来源:CatAllocationTestCase.java


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