當前位置: 首頁>>代碼示例>>Java>>正文


Java IndexMetaData.getNumberOfReplicas方法代碼示例

本文整理匯總了Java中org.elasticsearch.cluster.metadata.IndexMetaData.getNumberOfReplicas方法的典型用法代碼示例。如果您正苦於以下問題:Java IndexMetaData.getNumberOfReplicas方法的具體用法?Java IndexMetaData.getNumberOfReplicas怎麽用?Java IndexMetaData.getNumberOfReplicas使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.elasticsearch.cluster.metadata.IndexMetaData的用法示例。


在下文中一共展示了IndexMetaData.getNumberOfReplicas方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: initializeAsRestore

import org.elasticsearch.cluster.metadata.IndexMetaData; //導入方法依賴的package包/類
/**
 * Initializes an index, to be restored from snapshot
 */
private Builder initializeAsRestore(IndexMetaData indexMetaData, RestoreSource restoreSource, IntSet ignoreShards, boolean asNew, UnassignedInfo unassignedInfo) {
    if (!shards.isEmpty()) {
        throw new IllegalStateException("trying to initialize an index with fresh shards, but already has shards created");
    }
    for (int shardId = 0; shardId < indexMetaData.getNumberOfShards(); shardId++) {
        IndexShardRoutingTable.Builder indexShardRoutingBuilder = new IndexShardRoutingTable.Builder(new ShardId(indexMetaData.getIndex(), shardId));
        for (int i = 0; i <= indexMetaData.getNumberOfReplicas(); i++) {
            if (asNew && ignoreShards.contains(shardId)) {
                // This shards wasn't completely snapshotted - restore it as new shard
                indexShardRoutingBuilder.addShard(ShardRouting.newUnassigned(index, shardId, null, i == 0, unassignedInfo));
            } else {
                indexShardRoutingBuilder.addShard(ShardRouting.newUnassigned(index, shardId, i == 0 ? restoreSource : null, i == 0, unassignedInfo));
            }
        }
        shards.put(shardId, indexShardRoutingBuilder.build());
    }
    return this;
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:22,代碼來源:IndexRoutingTable.java

示例2: ReplicationGroup

import org.elasticsearch.cluster.metadata.IndexMetaData; //導入方法依賴的package包/類
ReplicationGroup(final IndexMetaData indexMetaData) throws IOException {
    final ShardRouting primaryRouting = this.createShardRouting("s0", true);
    primary = newShard(primaryRouting, indexMetaData, null, this::syncGlobalCheckpoint, getEngineFactory(primaryRouting));
    replicas = new ArrayList<>();
    this.indexMetaData = indexMetaData;
    updateAllocationIDsOnPrimary();
    for (int i = 0; i < indexMetaData.getNumberOfReplicas(); i++) {
        addReplica();
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:11,代碼來源:ESIndexLevelReplicationTestCase.java

示例3: genShardRoutingTable

import org.elasticsearch.cluster.metadata.IndexMetaData; //導入方法依賴的package包/類
public IndexShardRoutingTable genShardRoutingTable(IndexMetaData indexMetaData, int shardId, ShardCounter counter) {
    final String index = indexMetaData.getIndex().getName();
    IndexShardRoutingTable.Builder builder = new IndexShardRoutingTable.Builder(new ShardId(index, "_na_", shardId));
    ShardRouting shardRouting = genShardRouting(index, shardId, true);
    counter.update(shardRouting);
    builder.addShard(shardRouting);
    for (int replicas = indexMetaData.getNumberOfReplicas(); replicas > 0; replicas--) {
        shardRouting = genShardRouting(index, shardId, false);
        counter.update(shardRouting);
        builder.addShard(shardRouting);
    }

    return builder.build();
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:15,代碼來源:RoutingTableGenerator.java

示例4: isEnoughAllocationsFound

import org.elasticsearch.cluster.metadata.IndexMetaData; //導入方法依賴的package包/類
private boolean isEnoughAllocationsFound(ShardRouting shard, IndexMetaData indexMetaData, NodesAndVersions nodesAndVersions) {
    // check if the counts meets the minimum set
    int requiredAllocation = 1;
    // if we restore from a repository one copy is more then enough
    if (shard.restoreSource() == null) {
        try {
            String initialShards = indexMetaData.getSettings().get(INDEX_RECOVERY_INITIAL_SHARDS, settings.get(INDEX_RECOVERY_INITIAL_SHARDS, this.initialShards));
            if ("quorum".equals(initialShards)) {
                if (indexMetaData.getNumberOfReplicas() > 1) {
                    requiredAllocation = ((1 + indexMetaData.getNumberOfReplicas()) / 2) + 1;
                }
            } else if ("quorum-1".equals(initialShards) || "half".equals(initialShards)) {
                if (indexMetaData.getNumberOfReplicas() > 2) {
                    requiredAllocation = ((1 + indexMetaData.getNumberOfReplicas()) / 2);
                }
            } else if ("one".equals(initialShards)) {
                requiredAllocation = 1;
            } else if ("full".equals(initialShards) || "all".equals(initialShards)) {
                requiredAllocation = indexMetaData.getNumberOfReplicas() + 1;
            } else if ("full-1".equals(initialShards) || "all-1".equals(initialShards)) {
                if (indexMetaData.getNumberOfReplicas() > 1) {
                    requiredAllocation = indexMetaData.getNumberOfReplicas();
                }
            } else {
                requiredAllocation = Integer.parseInt(initialShards);
            }
        } catch (Exception e) {
            logger.warn("[{}][{}] failed to derived initial_shards from value {}, ignore allocation for {}", shard.index(), shard.id(), initialShards, shard);
        }
    }

    return nodesAndVersions.allocationsFound >= requiredAllocation;
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:34,代碼來源:PrimaryShardAllocator.java

示例5: initializeEmpty

import org.elasticsearch.cluster.metadata.IndexMetaData; //導入方法依賴的package包/類
/**
 * Initializes a new empty index, with an option to control if its from an API or not.
 */
private Builder initializeEmpty(IndexMetaData indexMetaData, UnassignedInfo unassignedInfo) {
    if (!shards.isEmpty()) {
        throw new IllegalStateException("trying to initialize an index with fresh shards, but already has shards created");
    }
    for (int shardId = 0; shardId < indexMetaData.getNumberOfShards(); shardId++) {
        IndexShardRoutingTable.Builder indexShardRoutingBuilder = new IndexShardRoutingTable.Builder(new ShardId(indexMetaData.getIndex(), shardId));
        for (int i = 0; i <= indexMetaData.getNumberOfReplicas(); i++) {
            indexShardRoutingBuilder.addShard(ShardRouting.newUnassigned(index, shardId, null, i == 0, unassignedInfo));
        }
        shards.put(shardId, indexShardRoutingBuilder.build());
    }
    return this;
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:17,代碼來源:IndexRoutingTable.java

示例6: ClusterIndexHealth

import org.elasticsearch.cluster.metadata.IndexMetaData; //導入方法依賴的package包/類
public ClusterIndexHealth(IndexMetaData indexMetaData, IndexRoutingTable indexRoutingTable) {
    this.index = indexMetaData.getIndex();
    this.numberOfShards = indexMetaData.getNumberOfShards();
    this.numberOfReplicas = indexMetaData.getNumberOfReplicas();
    this.validationFailures = indexRoutingTable.validate(indexMetaData);

    for (IndexShardRoutingTable shardRoutingTable : indexRoutingTable) {
        int shardId = shardRoutingTable.shardId().id();
        shards.put(shardId, new ClusterShardHealth(shardId, shardRoutingTable));
    }

    // update the index status
    status = ClusterHealthStatus.GREEN;

    for (ClusterShardHealth shardHealth : shards.values()) {
        if (shardHealth.isPrimaryActive()) {
            activePrimaryShards++;
        }
        activeShards += shardHealth.getActiveShards();
        relocatingShards += shardHealth.getRelocatingShards();
        initializingShards += shardHealth.getInitializingShards();
        unassignedShards += shardHealth.getUnassignedShards();

        if (shardHealth.getStatus() == ClusterHealthStatus.RED) {
            status = ClusterHealthStatus.RED;
        } else if (shardHealth.getStatus() == ClusterHealthStatus.YELLOW && status != ClusterHealthStatus.RED) {
            // do not override an existing red
            status = ClusterHealthStatus.YELLOW;
        }
    }
    if (!validationFailures.isEmpty()) {
        status = ClusterHealthStatus.RED;
    } else if (shards.isEmpty()) { // might be since none has been created yet (two phase index creation)
        status = ClusterHealthStatus.RED;
    }
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:37,代碼來源:ClusterIndexHealth.java

示例7: ClusterIndexHealth

import org.elasticsearch.cluster.metadata.IndexMetaData; //導入方法依賴的package包/類
public ClusterIndexHealth(final IndexMetaData indexMetaData, final IndexRoutingTable indexRoutingTable) {
    this.index = indexMetaData.getIndex().getName();
    this.numberOfShards = indexMetaData.getNumberOfShards();
    this.numberOfReplicas = indexMetaData.getNumberOfReplicas();

    for (IndexShardRoutingTable shardRoutingTable : indexRoutingTable) {
        int shardId = shardRoutingTable.shardId().id();
        shards.put(shardId, new ClusterShardHealth(shardId, shardRoutingTable));
    }

    // update the index status
    ClusterHealthStatus computeStatus = ClusterHealthStatus.GREEN;
    int computeActivePrimaryShards = 0;
    int computeActiveShards = 0;
    int computeRelocatingShards = 0;
    int computeInitializingShards = 0;
    int computeUnassignedShards = 0;
    for (ClusterShardHealth shardHealth : shards.values()) {
        if (shardHealth.isPrimaryActive()) {
            computeActivePrimaryShards++;
        }
        computeActiveShards += shardHealth.getActiveShards();
        computeRelocatingShards += shardHealth.getRelocatingShards();
        computeInitializingShards += shardHealth.getInitializingShards();
        computeUnassignedShards += shardHealth.getUnassignedShards();

        if (shardHealth.getStatus() == ClusterHealthStatus.RED) {
            computeStatus = ClusterHealthStatus.RED;
        } else if (shardHealth.getStatus() == ClusterHealthStatus.YELLOW && computeStatus != ClusterHealthStatus.RED) {
            // do not override an existing red
            computeStatus = ClusterHealthStatus.YELLOW;
        }
    }
    if (shards.isEmpty()) { // might be since none has been created yet (two phase index creation)
        computeStatus = ClusterHealthStatus.RED;
    }

    this.status = computeStatus;
    this.activePrimaryShards = computeActivePrimaryShards;
    this.activeShards = computeActiveShards;
    this.relocatingShards = computeRelocatingShards;
    this.initializingShards = computeInitializingShards;
    this.unassignedShards = computeUnassignedShards;
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:45,代碼來源:ClusterIndexHealth.java

示例8: underCapacity

import org.elasticsearch.cluster.metadata.IndexMetaData; //導入方法依賴的package包/類
private Decision underCapacity(ShardRouting shardRouting, RoutingNode node, RoutingAllocation allocation, boolean moveToNode) {
    if (awarenessAttributes.length == 0) {
        return allocation.decision(Decision.YES, NAME, "no allocation awareness enabled");
    }

    IndexMetaData indexMetaData = allocation.metaData().index(shardRouting.index());
    int shardCount = indexMetaData.getNumberOfReplicas() + 1; // 1 for primary
    for (String awarenessAttribute : awarenessAttributes) {
        // the node the shard exists on must be associated with an awareness attribute
        if (!node.node().attributes().containsKey(awarenessAttribute)) {
            return allocation.decision(Decision.NO, NAME, "node does not contain awareness attribute: [%s]", awarenessAttribute);
        }

        // build attr_value -> nodes map
        ObjectIntHashMap<String> nodesPerAttribute = allocation.routingNodes().nodesPerAttributesCounts(awarenessAttribute);

        // build the count of shards per attribute value
        ObjectIntHashMap<String> shardPerAttribute = new ObjectIntHashMap<>();
        for (ShardRouting assignedShard : allocation.routingNodes().assignedShards(shardRouting)) {
            if (assignedShard.started() || assignedShard.initializing()) {
                // Note: this also counts relocation targets as that will be the new location of the shard.
                // Relocation sources should not be counted as the shard is moving away
                RoutingNode routingNode = allocation.routingNodes().node(assignedShard.currentNodeId());
                shardPerAttribute.addTo(routingNode.node().attributes().get(awarenessAttribute), 1);
            }
        }

        if (moveToNode) {
            if (shardRouting.assignedToNode()) {
                String nodeId = shardRouting.relocating() ? shardRouting.relocatingNodeId() : shardRouting.currentNodeId();
                if (!node.nodeId().equals(nodeId)) {
                    // we work on different nodes, move counts around
                    shardPerAttribute.putOrAdd(allocation.routingNodes().node(nodeId).node().attributes().get(awarenessAttribute), 0, -1);
                    shardPerAttribute.addTo(node.node().attributes().get(awarenessAttribute), 1);
                }
            } else {
                shardPerAttribute.addTo(node.node().attributes().get(awarenessAttribute), 1);
            }
        }

        int numberOfAttributes = nodesPerAttribute.size();
        String[] fullValues = forcedAwarenessAttributes.get(awarenessAttribute);
        if (fullValues != null) {
            for (String fullValue : fullValues) {
                if (!shardPerAttribute.containsKey(fullValue)) {
                    numberOfAttributes++;
                }
            }
        }
        // TODO should we remove ones that are not part of full list?

        int averagePerAttribute = shardCount / numberOfAttributes;
        int totalLeftover = shardCount % numberOfAttributes;
        int requiredCountPerAttribute;
        if (averagePerAttribute == 0) {
            // if we have more attributes values than shard count, no leftover
            totalLeftover = 0;
            requiredCountPerAttribute = 1;
        } else {
            requiredCountPerAttribute = averagePerAttribute;
        }
        int leftoverPerAttribute = totalLeftover == 0 ? 0 : 1;

        int currentNodeCount = shardPerAttribute.get(node.node().attributes().get(awarenessAttribute));
        // if we are above with leftover, then we know we are not good, even with mod
        if (currentNodeCount > (requiredCountPerAttribute + leftoverPerAttribute)) {
            return allocation.decision(Decision.NO, NAME,
                    "too many shards on node for attribute: [%s], required per attribute: [%d], node count: [%d], leftover: [%d]",
                    awarenessAttribute, requiredCountPerAttribute, currentNodeCount, leftoverPerAttribute);
        }
        // all is well, we are below or same as average
        if (currentNodeCount <= requiredCountPerAttribute) {
            continue;
        }
    }

    return allocation.decision(Decision.YES, NAME, "node meets awareness requirements");
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:79,代碼來源:AwarenessAllocationDecider.java


注:本文中的org.elasticsearch.cluster.metadata.IndexMetaData.getNumberOfReplicas方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。