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


Java ByteSizeValue.bytes方法代碼示例

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


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

示例1: FileInfo

import org.elasticsearch.common.unit.ByteSizeValue; //導入方法依賴的package包/類
/**
 * Constructs a new instance of file info
 *
 * @param name         file name as stored in the blob store
 * @param metaData  the files meta data
 * @param partSize     size of the single chunk
 */
public FileInfo(String name, StoreFileMetaData metaData, ByteSizeValue partSize) {
    this.name = name;
    this.metadata = metaData;

    long partBytes = Long.MAX_VALUE;
    if (partSize != null) {
        partBytes = partSize.bytes();
    }

    long totalLength = metaData.length();
    long numberOfParts = totalLength / partBytes;
    if (totalLength % partBytes > 0) {
        numberOfParts++;
    }
    if (numberOfParts == 0) {
        numberOfParts++;
    }
    this.numberOfParts = numberOfParts;
    this.partSize = partSize;
    this.partBytes = partBytes;
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:29,代碼來源:BlobStoreIndexShardSnapshot.java

示例2: MemoryCircuitBreaker

import org.elasticsearch.common.unit.ByteSizeValue; //導入方法依賴的package包/類
/**
 * Create a circuit breaker that will break if the number of estimated
 * bytes grows above the limit. All estimations will be multiplied by
 * the given overheadConstant. Uses the given oldBreaker to initialize
 * the starting offset.
 * @param limit circuit breaker limit
 * @param overheadConstant constant multiplier for byte estimations
 * @param oldBreaker the previous circuit breaker to inherit the used value from (starting offset)
 */
public MemoryCircuitBreaker(ByteSizeValue limit, double overheadConstant, MemoryCircuitBreaker oldBreaker, ESLogger logger) {
    this.memoryBytesLimit = limit.bytes();
    this.overheadConstant = overheadConstant;
    if (oldBreaker == null) {
        this.used = new AtomicLong(0);
        this.trippedCount = new AtomicLong(0);
    } else {
        this.used = oldBreaker.used;
        this.trippedCount = oldBreaker.trippedCount;
    }
    this.logger = logger;
    if (logger.isTraceEnabled()) {
        logger.trace("Creating MemoryCircuitBreaker with a limit of {} bytes ({}) and a overhead constant of {}",
                this.memoryBytesLimit, limit, this.overheadConstant);
    }
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:26,代碼來源:MemoryCircuitBreaker.java

示例3: BulkProcessor

import org.elasticsearch.common.unit.ByteSizeValue; //導入方法依賴的package包/類
BulkProcessor(Client client, BackoffPolicy backoffPolicy, Listener listener, @Nullable String name, int concurrentRequests, int bulkActions, ByteSizeValue bulkSize, @Nullable TimeValue flushInterval) {
    this.bulkActions = bulkActions;
    this.bulkSize = bulkSize.bytes();

    this.bulkRequest = new BulkRequest();
    this.bulkRequestHandler = (concurrentRequests == 0) ? BulkRequestHandler.syncHandler(client, backoffPolicy, listener) : BulkRequestHandler.asyncHandler(client, backoffPolicy, listener, concurrentRequests);

    if (flushInterval != null) {
        this.scheduler = (ScheduledThreadPoolExecutor) Executors.newScheduledThreadPool(1, EsExecutors.daemonThreadFactory(client.settings(), (name != null ? "[" + name + "]" : "") + "bulk_processor"));
        this.scheduler.setExecuteExistingDelayedTasksAfterShutdownPolicy(false);
        this.scheduler.setContinueExistingPeriodicTasksAfterShutdownPolicy(false);
        this.scheduledFuture = this.scheduler.scheduleWithFixedDelay(new Flush(), flushInterval.millis(), flushInterval.millis(), TimeUnit.MILLISECONDS);
    } else {
        this.scheduler = null;
        this.scheduledFuture = null;
    }
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:18,代碼來源:BulkProcessor.java

示例4: getRateLimiter

import org.elasticsearch.common.unit.ByteSizeValue; //導入方法依賴的package包/類
/**
 * Configures RateLimiter based on repository and global settings
 *
 * @param repositorySettings repository settings
 * @param setting            setting to use to configure rate limiter
 * @param defaultRate        default limiting rate
 * @return rate limiter or null of no throttling is needed
 */
private RateLimiter getRateLimiter(RepositorySettings repositorySettings, String setting, ByteSizeValue defaultRate) {
    ByteSizeValue maxSnapshotBytesPerSec = repositorySettings.settings().getAsBytesSize(setting,
            settings.getAsBytesSize(setting, defaultRate));
    if (maxSnapshotBytesPerSec.bytes() <= 0) {
        return null;
    } else {
        return new RateLimiter.SimpleRateLimiter(maxSnapshotBytesPerSec.mbFrac());
    }
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:18,代碼來源:BlobStoreRepository.java

示例5: validate

import org.elasticsearch.common.unit.ByteSizeValue; //導入方法依賴的package包/類
private ByteSizeValue validate(ByteSizeValue num) {
    if (num.bytes() < setting.minValue() || num.bytes() > setting.maxValue()) {
        throw invalidException();
    }
    return num;
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:7,代碼來源:SettingsAppliers.java

示例6: onRefreshSettings

import org.elasticsearch.common.unit.ByteSizeValue; //導入方法依賴的package包/類
@Override
public void onRefreshSettings(Settings settings) {

    // Fielddata settings
    ByteSizeValue newFielddataMax = settings.getAsMemory(FIELDDATA_CIRCUIT_BREAKER_LIMIT_SETTING, null);
    Double newFielddataOverhead = settings.getAsDouble(FIELDDATA_CIRCUIT_BREAKER_OVERHEAD_SETTING, null);
    if (newFielddataMax != null || newFielddataOverhead != null) {
        long newFielddataLimitBytes = newFielddataMax == null ? HierarchyCircuitBreakerService.this.fielddataSettings.getLimit() : newFielddataMax.bytes();
        newFielddataOverhead = newFielddataOverhead == null ? HierarchyCircuitBreakerService.this.fielddataSettings.getOverhead() : newFielddataOverhead;

        BreakerSettings newFielddataSettings = new BreakerSettings(CircuitBreaker.FIELDDATA, newFielddataLimitBytes, newFielddataOverhead,
                HierarchyCircuitBreakerService.this.fielddataSettings.getType());
        registerBreaker(newFielddataSettings);
        HierarchyCircuitBreakerService.this.fielddataSettings = newFielddataSettings;
        logger.info("Updated breaker settings fielddata: {}", newFielddataSettings);
    }

    // Request settings
    ByteSizeValue newRequestMax = settings.getAsMemory(REQUEST_CIRCUIT_BREAKER_LIMIT_SETTING, null);
    Double newRequestOverhead = settings.getAsDouble(REQUEST_CIRCUIT_BREAKER_OVERHEAD_SETTING, null);
    if (newRequestMax != null || newRequestOverhead != null) {
        long newRequestLimitBytes = newRequestMax == null ? HierarchyCircuitBreakerService.this.requestSettings.getLimit() : newRequestMax.bytes();
        newRequestOverhead = newRequestOverhead == null ? HierarchyCircuitBreakerService.this.requestSettings.getOverhead() : newRequestOverhead;

        BreakerSettings newRequestSettings = new BreakerSettings(CircuitBreaker.REQUEST, newRequestLimitBytes, newRequestOverhead,
                HierarchyCircuitBreakerService.this.requestSettings.getType());
        registerBreaker(newRequestSettings);
        HierarchyCircuitBreakerService.this.requestSettings = newRequestSettings;
        logger.info("Updated breaker settings request: {}", newRequestSettings);
    }

    // Parent settings
    long oldParentMax = HierarchyCircuitBreakerService.this.parentSettings.getLimit();
    ByteSizeValue newParentMax = settings.getAsMemory(TOTAL_CIRCUIT_BREAKER_LIMIT_SETTING, null);
    if (newParentMax != null && (newParentMax.bytes() != oldParentMax)) {
        BreakerSettings newParentSettings = new BreakerSettings(CircuitBreaker.PARENT, newParentMax.bytes(), 1.0, CircuitBreaker.Type.PARENT);
        validateSettings(new BreakerSettings[]{newParentSettings});
        HierarchyCircuitBreakerService.this.parentSettings = newParentSettings;
        logger.info("Updated breaker settings parent: {}", newParentSettings);
    }
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:42,代碼來源:HierarchyCircuitBreakerService.java

示例7: updateBufferSize

import org.elasticsearch.common.unit.ByteSizeValue; //導入方法依賴的package包/類
/**
 * Change the indexing and translog buffer sizes.  If {@code IndexWriter} is currently using more than
 * the new buffering indexing size then we do a refresh to free up the heap.
 */
public void updateBufferSize(ByteSizeValue shardIndexingBufferSize, ByteSizeValue shardTranslogBufferSize) {

    final EngineConfig config = engineConfig;
    final ByteSizeValue preValue = config.getIndexingBufferSize();

    config.setIndexingBufferSize(shardIndexingBufferSize);

    Engine engine = engineUnsafe();
    if (engine == null) {
        logger.debug("updateBufferSize: engine is not initialized yet; skipping");
        return;
    }

    // update engine if it is already started.
    if (preValue.bytes() != shardIndexingBufferSize.bytes()) {
        // so we push changes these changes down to IndexWriter:
        engine.onSettingsChanged();

        long iwBytesUsed = engine.indexWriterRAMBytesUsed();

        String message = LoggerMessageFormat.format("updating index_buffer_size from [{}] to [{}]; IndexWriter now using [{}] bytes",
                preValue, shardIndexingBufferSize, iwBytesUsed);

        if (iwBytesUsed > shardIndexingBufferSize.bytes()) {
            // our allowed buffer was changed to less than we are currently using; we ask IW to refresh
            // so it clears its buffers (otherwise it won't clear until the next indexing/delete op)
            logger.debug(message + "; now refresh to clear IndexWriter memory");

            // TODO: should IW have an API to move segments to disk, but not refresh?  Its flush method is protected...
            try {
                refresh("update index buffer");
            } catch (Throwable e) {
                logger.warn("failed to refresh after decreasing index buffer", e);
            }
        } else {
            logger.debug(message);
        }
    }
    engine.getTranslog().updateBuffer(shardTranslogBufferSize);
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:45,代碼來源:IndexShard.java

示例8: buildTable

import org.elasticsearch.common.unit.ByteSizeValue; //導入方法依賴的package包/類
private Table buildTable(RestRequest request, final ClusterStateResponse state, final NodesStatsResponse stats) {
    final ObjectIntScatterMap<String> allocs = new ObjectIntScatterMap<>();

    for (ShardRouting shard : state.getState().routingTable().allShards()) {
        String nodeId = "UNASSIGNED";

        if (shard.assignedToNode()) {
            nodeId = shard.currentNodeId();
        }

        allocs.addTo(nodeId, 1);
    }

    Table table = getTableWithHeader(request);

    for (NodeStats nodeStats : stats.getNodes()) {
        DiscoveryNode node = nodeStats.getNode();

        int shardCount = allocs.getOrDefault(node.id(), 0);

        ByteSizeValue total = nodeStats.getFs().getTotal().getTotal();
        ByteSizeValue avail = nodeStats.getFs().getTotal().getAvailable();
        //if we don't know how much we use (non data nodes), it means 0
        long used = 0;
        short diskPercent = -1;
        if (total.bytes() > 0) {
            used = total.bytes() - avail.bytes();
            if (used >= 0 && avail.bytes() >= 0) {
                diskPercent = (short) (used * 100 / (used + avail.bytes()));
            }
        }

        table.startRow();
        table.addCell(shardCount);
        table.addCell(nodeStats.getIndices().getStore().getSize());
        table.addCell(used < 0 ? null : new ByteSizeValue(used));
        table.addCell(avail.bytes() < 0 ? null : avail);
        table.addCell(total.bytes() < 0 ? null : total);
        table.addCell(diskPercent < 0 ? null : diskPercent);
        table.addCell(node.getHostName());
        table.addCell(node.getHostAddress());
        table.addCell(node.name());
        table.endRow();
    }

    final String UNASSIGNED = "UNASSIGNED";
    if (allocs.containsKey(UNASSIGNED)) {
        table.startRow();
        table.addCell(allocs.get(UNASSIGNED));
        table.addCell(null);
        table.addCell(null);
        table.addCell(null);
        table.addCell(null);
        table.addCell(null);
        table.addCell(null);
        table.addCell(null);
        table.addCell(UNASSIGNED);
        table.endRow();
    }

    return table;
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:63,代碼來源:RestAllocationAction.java

示例9: onRefreshSettings

import org.elasticsearch.common.unit.ByteSizeValue; //導入方法依賴的package包/類
@Override
public void onRefreshSettings(Settings settings) {
    String newLowWatermark = settings.get(CLUSTER_ROUTING_ALLOCATION_LOW_DISK_WATERMARK,
            DiskThresholdDecider.this.settings.get(
                    CLUSTER_ROUTING_ALLOCATION_LOW_DISK_WATERMARK,
                    DEFAULT_LOW_DISK_WATERMARK));
    String newHighWatermark = settings.get(CLUSTER_ROUTING_ALLOCATION_HIGH_DISK_WATERMARK,
            DiskThresholdDecider.this.settings.get(
                    CLUSTER_ROUTING_ALLOCATION_HIGH_DISK_WATERMARK,
                    DEFAULT_HIGH_DISK_WATERMARK));
    Boolean newRelocationsSetting = settings.getAsBoolean(CLUSTER_ROUTING_ALLOCATION_INCLUDE_RELOCATIONS,
            DiskThresholdDecider.this.settings.getAsBoolean(
                    CLUSTER_ROUTING_ALLOCATION_INCLUDE_RELOCATIONS,
                    DEFAULT_INCLUDE_RELOCATIONS));
    Boolean newEnableSetting =  settings.getAsBoolean(
            CLUSTER_ROUTING_ALLOCATION_DISK_THRESHOLD_ENABLED,
            DiskThresholdDecider.this.settings.getAsBoolean(
                    CLUSTER_ROUTING_ALLOCATION_DISK_THRESHOLD_ENABLED,
                    DEFAULT_THRESHOLD_ENABLED));

    TimeValue newRerouteInterval = settings.getAsTime(CLUSTER_ROUTING_ALLOCATION_REROUTE_INTERVAL, null);

    if (newEnableSetting != null && newEnableSetting != DiskThresholdDecider.this.enabled) {
        logger.info("updating [{}] from [{}] to [{}]", CLUSTER_ROUTING_ALLOCATION_DISK_THRESHOLD_ENABLED,
                DiskThresholdDecider.this.enabled, newEnableSetting);
        DiskThresholdDecider.this.enabled = newEnableSetting;
    }
    if (newRelocationsSetting != null && newRelocationsSetting != DiskThresholdDecider.this.includeRelocations) {
        logger.info("updating [{}] from [{}] to [{}]", CLUSTER_ROUTING_ALLOCATION_INCLUDE_RELOCATIONS,
                DiskThresholdDecider.this.includeRelocations, newRelocationsSetting);
        DiskThresholdDecider.this.includeRelocations = newRelocationsSetting;
    }
    if (newLowWatermark != null) {
        if (!validWatermarkSetting(newLowWatermark, CLUSTER_ROUTING_ALLOCATION_LOW_DISK_WATERMARK)) {
            throw new ElasticsearchParseException("unable to parse low watermark [{}]", newLowWatermark);
        }
        Double newFreeDiskThresholdLow = 100.0 - thresholdPercentageFromWatermark(newLowWatermark);
        ByteSizeValue newFreeBytesThresholdLow = thresholdBytesFromWatermark(newLowWatermark, CLUSTER_ROUTING_ALLOCATION_LOW_DISK_WATERMARK);
        if (!freeDiskThresholdLow.equals(newFreeDiskThresholdLow)
                || freeBytesThresholdLow.bytes() != newFreeBytesThresholdLow.bytes()) {
            logger.info("updating [{}] to [{}]", CLUSTER_ROUTING_ALLOCATION_LOW_DISK_WATERMARK, newLowWatermark);
            DiskThresholdDecider.this.freeDiskThresholdLow = newFreeDiskThresholdLow;
            DiskThresholdDecider.this.freeBytesThresholdLow = newFreeBytesThresholdLow;
        }
    }
    if (newHighWatermark != null) {
        if (!validWatermarkSetting(newHighWatermark, CLUSTER_ROUTING_ALLOCATION_HIGH_DISK_WATERMARK)) {
            throw new ElasticsearchParseException("unable to parse high watermark [{}]", newHighWatermark);
        }
        Double newFreeDiskThresholdHigh = 100.0 - thresholdPercentageFromWatermark(newHighWatermark);
        ByteSizeValue newFreeBytesThresholdHigh = thresholdBytesFromWatermark(newHighWatermark, CLUSTER_ROUTING_ALLOCATION_HIGH_DISK_WATERMARK);
        if (!freeDiskThresholdHigh.equals(newFreeDiskThresholdHigh)
                || freeBytesThresholdHigh.bytes() != newFreeBytesThresholdHigh.bytes()) {
            logger.info("updating [{}] to [{}]", CLUSTER_ROUTING_ALLOCATION_HIGH_DISK_WATERMARK, newHighWatermark);
            DiskThresholdDecider.this.freeDiskThresholdHigh = 100.0 - thresholdPercentageFromWatermark(newHighWatermark);
            DiskThresholdDecider.this.freeBytesThresholdHigh = thresholdBytesFromWatermark(newHighWatermark, CLUSTER_ROUTING_ALLOCATION_HIGH_DISK_WATERMARK);
        }
    }
    if (newRerouteInterval != null) {
        logger.info("updating [{}] to [{}]", CLUSTER_ROUTING_ALLOCATION_REROUTE_INTERVAL, newRerouteInterval);
        DiskThresholdDecider.this.rerouteInterval = newRerouteInterval;
    }
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:64,代碼來源:DiskThresholdDecider.java


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