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


Java RoutingAllocation.clusterInfo方法代码示例

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


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

示例1: sizeOfRelocatingShards

import org.elasticsearch.cluster.routing.allocation.RoutingAllocation; //导入方法依赖的package包/类
/**
 * Returns the size of all shards that are currently being relocated to
 * the node, but may not be finished transferring yet.
 *
 * If subtractShardsMovingAway is true then the size of shards moving away is subtracted from the total size of all shards
 */
static long sizeOfRelocatingShards(RoutingNode node, RoutingAllocation allocation,
                                   boolean subtractShardsMovingAway, String dataPath) {
    ClusterInfo clusterInfo = allocation.clusterInfo();
    long totalSize = 0;
    for (ShardRouting routing : node.shardsWithState(ShardRoutingState.RELOCATING, ShardRoutingState.INITIALIZING)) {
        String actualPath = clusterInfo.getDataPath(routing);
        if (dataPath.equals(actualPath)) {
            if (routing.initializing() && routing.relocatingNodeId() != null) {
                totalSize += getExpectedShardSize(routing, allocation, 0);
            } else if (subtractShardsMovingAway && routing.relocating()) {
                totalSize -= getExpectedShardSize(routing, allocation, 0);
            }
        }
    }
    return totalSize;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:23,代码来源:DiskThresholdDecider.java

示例2: getExpectedShardSize

import org.elasticsearch.cluster.routing.allocation.RoutingAllocation; //导入方法依赖的package包/类
/**
 * Returns the expected shard size for the given shard or the default value provided if not enough information are available
 * to estimate the shards size.
 */
public static long getExpectedShardSize(ShardRouting shard, RoutingAllocation allocation, long defaultValue) {
    final IndexMetaData metaData = allocation.metaData().getIndexSafe(shard.index());
    final ClusterInfo info = allocation.clusterInfo();
    if (metaData.getMergeSourceIndex() != null && shard.active() == false &&
        shard.recoverySource().getType() == RecoverySource.Type.LOCAL_SHARDS) {
        // in the shrink index case we sum up the source index shards since we basically make a copy of the shard in
        // the worst case
        long targetShardSize = 0;
        final Index mergeSourceIndex = metaData.getMergeSourceIndex();
        final IndexMetaData sourceIndexMeta = allocation.metaData().getIndexSafe(mergeSourceIndex);
        final Set<ShardId> shardIds = IndexMetaData.selectShrinkShards(shard.id(), sourceIndexMeta, metaData.getNumberOfShards());
        for (IndexShardRoutingTable shardRoutingTable : allocation.routingTable().index(mergeSourceIndex.getName())) {
            if (shardIds.contains(shardRoutingTable.shardId())) {
                targetShardSize += info.getShardSize(shardRoutingTable.primaryShard(), 0);
            }
        }
        return targetShardSize == 0 ? defaultValue : targetShardSize;
    } else {
        return info.getShardSize(shard, defaultValue);
    }

}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:27,代码来源:DiskThresholdDecider.java

示例3: getDiskUsage

import org.elasticsearch.cluster.routing.allocation.RoutingAllocation; //导入方法依赖的package包/类
private DiskUsage getDiskUsage(RoutingNode node, RoutingAllocation allocation,  Map<String, DiskUsage> usages) {
    ClusterInfo clusterInfo = allocation.clusterInfo();
    DiskUsage usage = usages.get(node.nodeId());
    if (usage == null) {
        // If there is no usage, and we have other nodes in the cluster,
        // use the average usage for all nodes as the usage for this node
        usage = averageUsage(node, usages);
        if (logger.isDebugEnabled()) {
            logger.debug("unable to determine disk usage for {}, defaulting to average across nodes [{} total] [{} free] [{}% free]",
                    node.nodeId(), usage.getTotalBytes(), usage.getFreeBytes(), usage.getFreeDiskAsPercentage());
        }
    }

    if (includeRelocations) {
        long relocatingShardsSize = sizeOfRelocatingShards(node, clusterInfo, true, usage.getPath());
        DiskUsage usageIncludingRelocations = new DiskUsage(node.nodeId(), node.node().name(), usage.getPath(),
                usage.getTotalBytes(), usage.getFreeBytes() - relocatingShardsSize);
        if (logger.isTraceEnabled()) {
            logger.trace("usage without relocations: {}", usage);
            logger.trace("usage with relocations: [{} bytes] {}", relocatingShardsSize, usageIncludingRelocations);
        }
        usage = usageIncludingRelocations;
    }
    return usage;
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:26,代码来源:DiskThresholdDecider.java

示例4: earlyTerminate

import org.elasticsearch.cluster.routing.allocation.RoutingAllocation; //导入方法依赖的package包/类
private Decision earlyTerminate(RoutingAllocation allocation, ImmutableOpenMap<String, DiskUsage> usages) {
    // Always allow allocation if the decider is disabled
    if (diskThresholdSettings.isEnabled() == false) {
        return allocation.decision(Decision.YES, NAME, "the disk threshold decider is disabled");
    }

    // Allow allocation regardless if only a single data node is available
    if (allocation.nodes().getDataNodes().size() <= 1) {
        if (logger.isTraceEnabled()) {
            logger.trace("only a single data node is present, allowing allocation");
        }
        return allocation.decision(Decision.YES, NAME, "there is only a single data node present");
    }

    // Fail open there is no info available
    final ClusterInfo clusterInfo = allocation.clusterInfo();
    if (clusterInfo == null) {
        if (logger.isTraceEnabled()) {
            logger.trace("cluster info unavailable for disk threshold decider, allowing allocation.");
        }
        return allocation.decision(Decision.YES, NAME, "the cluster info is unavailable");
    }

    // Fail open if there are no disk usages available
    if (usages.isEmpty()) {
        if (logger.isTraceEnabled()) {
            logger.trace("unable to determine disk usages for disk-aware allocation, allowing allocation");
        }
        return allocation.decision(Decision.YES, NAME, "disk usages are unavailable");
    }
    return null;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:33,代码来源:DiskThresholdDecider.java

示例5: earlyTerminate

import org.elasticsearch.cluster.routing.allocation.RoutingAllocation; //导入方法依赖的package包/类
private Decision earlyTerminate(RoutingAllocation allocation, final Map<String, DiskUsage> usages) {
    // Always allow allocation if the decider is disabled
    if (!enabled) {
        return allocation.decision(Decision.YES, NAME, "disk threshold decider disabled");
    }

    // Allow allocation regardless if only a single data node is available
    if (allocation.nodes().dataNodes().size() <= 1) {
        if (logger.isTraceEnabled()) {
            logger.trace("only a single data node is present, allowing allocation");
        }
        return allocation.decision(Decision.YES, NAME, "only a single data node is present");
    }

    // Fail open there is no info available
    final ClusterInfo clusterInfo = allocation.clusterInfo();
    if (clusterInfo == null) {
        if (logger.isTraceEnabled()) {
            logger.trace("cluster info unavailable for disk threshold decider, allowing allocation.");
        }
        return allocation.decision(Decision.YES, NAME, "cluster info unavailable");
    }

    // Fail open if there are no disk usages available
    if (usages.isEmpty()) {
        if (logger.isTraceEnabled()) {
            logger.trace("unable to determine disk usages for disk-aware allocation, allowing allocation");
        }
        return allocation.decision(Decision.YES, NAME, "disk usages unavailable");
    }
    return null;
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:33,代码来源:DiskThresholdDecider.java

示例6: canRemain

import org.elasticsearch.cluster.routing.allocation.RoutingAllocation; //导入方法依赖的package包/类
@Override
public Decision canRemain(ShardRouting shardRouting, RoutingNode node, RoutingAllocation allocation) {
    if (shardRouting.currentNodeId().equals(node.nodeId()) == false) {
        throw new IllegalArgumentException("Shard [" + shardRouting + "] is not allocated on node: [" + node.nodeId() + "]");
    }
    final ClusterInfo clusterInfo = allocation.clusterInfo();
    final ImmutableOpenMap<String, DiskUsage> usages = clusterInfo.getNodeLeastAvailableDiskUsages();
    final Decision decision = earlyTerminate(allocation, usages);
    if (decision != null) {
        return decision;
    }

    // subtractLeavingShards is passed as true here, since this is only for shards remaining, we will *eventually* have enough disk
    // since shards are moving away. No new shards will be incoming since in canAllocate we pass false for this check.
    final DiskUsage usage = getDiskUsage(node, allocation, usages, true);
    final String dataPath = clusterInfo.getDataPath(shardRouting);
    // If this node is already above the high threshold, the shard cannot remain (get it off!)
    final double freeDiskPercentage = usage.getFreeDiskAsPercentage();
    final long freeBytes = usage.getFreeBytes();
    if (logger.isTraceEnabled()) {
        logger.trace("node [{}] has {}% free disk ({} bytes)", node.nodeId(), freeDiskPercentage, freeBytes);
    }
    if (dataPath == null || usage.getPath().equals(dataPath) == false) {
        return allocation.decision(Decision.YES, NAME,
                "this shard is not allocated on the most utilized disk and can remain");
    }
    if (freeBytes < diskThresholdSettings.getFreeBytesThresholdHigh().getBytes()) {
        if (logger.isDebugEnabled()) {
            logger.debug("less than the required {} free bytes threshold ({} bytes free) on node {}, shard cannot remain",
                    diskThresholdSettings.getFreeBytesThresholdHigh(), freeBytes, node.nodeId());
        }
        return allocation.decision(Decision.NO, NAME,
            "the shard cannot remain on this node because it is above the high watermark cluster setting [%s=%s] " +
                "and there is less than the required [%s] free space on node, actual free: [%s]",
            CLUSTER_ROUTING_ALLOCATION_HIGH_DISK_WATERMARK_SETTING.getKey(),
            diskThresholdSettings.getHighWatermarkRaw(),
            diskThresholdSettings.getFreeBytesThresholdHigh(), new ByteSizeValue(freeBytes));
    }
    if (freeDiskPercentage < diskThresholdSettings.getFreeDiskThresholdHigh()) {
        if (logger.isDebugEnabled()) {
            logger.debug("less than the required {}% free disk threshold ({}% free) on node {}, shard cannot remain",
                    diskThresholdSettings.getFreeDiskThresholdHigh(), freeDiskPercentage, node.nodeId());
        }
        return allocation.decision(Decision.NO, NAME,
            "the shard cannot remain on this node because it is above the high watermark cluster setting [%s=%s] " +
                "and there is less than the required [%s%%] free disk on node, actual free: [%s%%]",
            CLUSTER_ROUTING_ALLOCATION_HIGH_DISK_WATERMARK_SETTING.getKey(),
            diskThresholdSettings.getHighWatermarkRaw(),
            diskThresholdSettings.getFreeDiskThresholdHigh(), freeDiskPercentage);
    }

    return allocation.decision(Decision.YES, NAME,
            "there is enough disk on this node for the shard to remain, free: [%s]", new ByteSizeValue(freeBytes));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:55,代码来源:DiskThresholdDecider.java

示例7: canRemain

import org.elasticsearch.cluster.routing.allocation.RoutingAllocation; //导入方法依赖的package包/类
@Override
public Decision canRemain(ShardRouting shardRouting, RoutingNode node, RoutingAllocation allocation) {
    if (shardRouting.currentNodeId().equals(node.nodeId()) == false) {
        throw new IllegalArgumentException("Shard [" + shardRouting + "] is not allocated on node: [" + node.nodeId() + "]");
    }
    final ClusterInfo clusterInfo = allocation.clusterInfo();
    final Map<String, DiskUsage> usages = clusterInfo.getNodeLeastAvailableDiskUsages();
    final Decision decision = earlyTerminate(allocation, usages);
    if (decision != null) {
        return decision;
    }

    final DiskUsage usage = getDiskUsage(node, allocation, usages);
    final String dataPath = clusterInfo.getDataPath(shardRouting);
    // If this node is already above the high threshold, the shard cannot remain (get it off!)
    final double freeDiskPercentage = usage.getFreeDiskAsPercentage();
    final long freeBytes = usage.getFreeBytes();
    if (logger.isTraceEnabled()) {
        logger.trace("node [{}] has {}% free disk ({} bytes)", node.nodeId(), freeDiskPercentage, freeBytes);
    }
    if (dataPath == null || usage.getPath().equals(dataPath) == false) {
        return allocation.decision(Decision.YES, NAME, "shard is not allocated on the most utilized disk");
    }
    if (freeBytes < freeBytesThresholdHigh.bytes()) {
        if (logger.isDebugEnabled()) {
            logger.debug("less than the required {} free bytes threshold ({} bytes free) on node {}, shard cannot remain",
                    freeBytesThresholdHigh, freeBytes, node.nodeId());
        }
        return allocation.decision(Decision.NO, NAME, "after allocation less than required [%s] free on node, free: [%s]",
                freeBytesThresholdHigh, new ByteSizeValue(freeBytes));
    }
    if (freeDiskPercentage < freeDiskThresholdHigh) {
        if (logger.isDebugEnabled()) {
            logger.debug("less than the required {}% free disk threshold ({}% free) on node {}, shard cannot remain",
                    freeDiskThresholdHigh, freeDiskPercentage, node.nodeId());
        }
        return allocation.decision(Decision.NO, NAME, "after allocation less than required [%s%%] free disk on node, free: [%s%%]",
                freeDiskThresholdHigh, freeDiskPercentage);
    }

    return allocation.decision(Decision.YES, NAME, "enough disk for shard to remain on node, free: [%s]", new ByteSizeValue(freeBytes));
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:43,代码来源:DiskThresholdDecider.java


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