Search in sources :

Example 76 with ByteSizeValue

use of org.elasticsearch.common.unit.ByteSizeValue in project elasticsearch by elastic.

the class RecoverySourceHandler method sendSnapshot.

/**
     * Send the given snapshot's operations with a sequence number greater than the specified staring sequence number to this handler's
     * target node.
     * <p>
     * Operations are bulked into a single request depending on an operation count limit or size-in-bytes limit.
     *
     * @param startingSeqNo the sequence number for which only operations with a sequence number greater than this will be sent
     * @param snapshot      the translog snapshot to replay operations from
     * @return the total number of translog operations that were sent
     * @throws IOException if an I/O exception occurred reading the translog snapshot
     */
protected int sendSnapshot(final long startingSeqNo, final Translog.Snapshot snapshot) throws IOException {
    int ops = 0;
    long size = 0;
    int totalOperations = 0;
    final List<Translog.Operation> operations = new ArrayList<>();
    if (snapshot.totalOperations() == 0) {
        logger.trace("no translog operations to send");
    }
    // send operations in batches
    Translog.Operation operation;
    while ((operation = snapshot.next()) != null) {
        if (shard.state() == IndexShardState.CLOSED) {
            throw new IndexShardClosedException(request.shardId());
        }
        cancellableThreads.checkForCancel();
        // if we are doing a sequence-number-based recovery, we have to skip older ops for which no sequence number was assigned, and
        // any ops before the starting sequence number
        final long seqNo = operation.seqNo();
        if (startingSeqNo >= 0 && (seqNo == SequenceNumbersService.UNASSIGNED_SEQ_NO || seqNo < startingSeqNo))
            continue;
        operations.add(operation);
        ops++;
        size += operation.estimateSize();
        totalOperations++;
        // check if this request is past bytes threshold, and if so, send it off
        if (size >= chunkSizeInBytes) {
            cancellableThreads.execute(() -> recoveryTarget.indexTranslogOperations(operations, snapshot.totalOperations()));
            if (logger.isTraceEnabled()) {
                logger.trace("sent batch of [{}][{}] (total: [{}]) translog operations", ops, new ByteSizeValue(size), snapshot.totalOperations());
            }
            ops = 0;
            size = 0;
            operations.clear();
        }
    }
    // send the leftover operations
    if (!operations.isEmpty()) {
        cancellableThreads.execute(() -> recoveryTarget.indexTranslogOperations(operations, snapshot.totalOperations()));
    }
    if (logger.isTraceEnabled()) {
        logger.trace("sent final batch of [{}][{}] (total: [{}]) translog operations", ops, new ByteSizeValue(size), snapshot.totalOperations());
    }
    return totalOperations;
}
Also used : IndexShardClosedException(org.elasticsearch.index.shard.IndexShardClosedException) ArrayList(java.util.ArrayList) ByteSizeValue(org.elasticsearch.common.unit.ByteSizeValue) Translog(org.elasticsearch.index.translog.Translog)

Example 77 with ByteSizeValue

use of org.elasticsearch.common.unit.ByteSizeValue in project elasticsearch by elastic.

the class ChildMemoryCircuitBreaker method limit.

private long limit(long bytes, String label) {
    // Otherwise, check the addition and commit the addition, looping if
    long newUsed;
    // there are conflicts. May result in additional logging, but it's
    // trace logging and shouldn't be counted on for additions.
    long currentUsed;
    do {
        currentUsed = this.used.get();
        newUsed = currentUsed + bytes;
        long newUsedWithOverhead = (long) (newUsed * overheadConstant);
        if (logger.isTraceEnabled()) {
            logger.trace("[{}] Adding [{}][{}] to used bytes [new used: [{}], limit: {} [{}], estimate: {} [{}]]", this.name, new ByteSizeValue(bytes), label, new ByteSizeValue(newUsed), memoryBytesLimit, new ByteSizeValue(memoryBytesLimit), newUsedWithOverhead, new ByteSizeValue(newUsedWithOverhead));
        }
        if (memoryBytesLimit > 0 && newUsedWithOverhead > memoryBytesLimit) {
            logger.warn("[{}] New used memory {} [{}] for data of [{}] would be larger than configured breaker: {} [{}], breaking", this.name, newUsedWithOverhead, new ByteSizeValue(newUsedWithOverhead), label, memoryBytesLimit, new ByteSizeValue(memoryBytesLimit));
            circuitBreak(label, newUsedWithOverhead);
        }
    // Attempt to set the new used value, but make sure it hasn't changed
    // underneath us, if it has, keep trying until we are able to set it
    } while (!this.used.compareAndSet(currentUsed, newUsed));
    return newUsed;
}
Also used : ByteSizeValue(org.elasticsearch.common.unit.ByteSizeValue)

Example 78 with ByteSizeValue

use of org.elasticsearch.common.unit.ByteSizeValue in project elasticsearch by elastic.

the class ChildMemoryCircuitBreaker method circuitBreak.

/**
     * Method used to trip the breaker, delegates to the parent to determine
     * whether to trip the breaker or not
     */
@Override
public void circuitBreak(String fieldName, long bytesNeeded) {
    this.trippedCount.incrementAndGet();
    final String message = "[" + this.name + "] Data too large, data for [" + fieldName + "]" + " would be [" + bytesNeeded + "/" + new ByteSizeValue(bytesNeeded) + "]" + ", which is larger than the limit of [" + memoryBytesLimit + "/" + new ByteSizeValue(memoryBytesLimit) + "]";
    logger.debug("{}", message);
    throw new CircuitBreakingException(message, bytesNeeded, memoryBytesLimit);
}
Also used : ByteSizeValue(org.elasticsearch.common.unit.ByteSizeValue)

Example 79 with ByteSizeValue

use of org.elasticsearch.common.unit.ByteSizeValue in project elasticsearch by elastic.

the class MemoryCircuitBreaker method circuitBreak.

/**
     * Method used to trip the breaker
     */
@Override
public void circuitBreak(String fieldName, long bytesNeeded) throws CircuitBreakingException {
    this.trippedCount.incrementAndGet();
    final String message = "[" + getName() + "] Data too large, data for field [" + fieldName + "]" + " would be [" + bytesNeeded + "/" + new ByteSizeValue(bytesNeeded) + "]" + ", which is larger than the limit of [" + memoryBytesLimit + "/" + new ByteSizeValue(memoryBytesLimit) + "]";
    logger.debug("{}", message);
    throw new CircuitBreakingException(message, bytesNeeded, memoryBytesLimit);
}
Also used : ByteSizeValue(org.elasticsearch.common.unit.ByteSizeValue)

Example 80 with ByteSizeValue

use of org.elasticsearch.common.unit.ByteSizeValue in project elasticsearch by elastic.

the class IndicesSegmentResponse method toXContent.

static void toXContent(XContentBuilder builder, Accountable tree) throws IOException {
    builder.startObject();
    builder.field(Fields.DESCRIPTION, tree.toString());
    builder.byteSizeField(Fields.SIZE_IN_BYTES, Fields.SIZE, new ByteSizeValue(tree.ramBytesUsed()));
    Collection<Accountable> children = tree.getChildResources();
    if (children.isEmpty() == false) {
        builder.startArray(Fields.CHILDREN);
        for (Accountable child : children) {
            toXContent(builder, child);
        }
        builder.endArray();
    }
    builder.endObject();
}
Also used : ByteSizeValue(org.elasticsearch.common.unit.ByteSizeValue) Accountable(org.apache.lucene.util.Accountable)

Aggregations

ByteSizeValue (org.elasticsearch.common.unit.ByteSizeValue)145 Settings (org.elasticsearch.common.settings.Settings)23 Test (org.junit.Test)21 IOException (java.io.IOException)16 CountDownLatch (java.util.concurrent.CountDownLatch)13 ArrayList (java.util.ArrayList)11 TimeValue (org.elasticsearch.common.unit.TimeValue)11 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)9 Matchers.containsString (org.hamcrest.Matchers.containsString)9 List (java.util.List)8 AtomicReference (java.util.concurrent.atomic.AtomicReference)8 Path (java.nio.file.Path)7 Translog (org.elasticsearch.index.translog.Translog)7 Arrays (java.util.Arrays)6 Collections (java.util.Collections)6 Collectors (java.util.stream.Collectors)6 BulkProcessor (org.elasticsearch.action.bulk.BulkProcessor)6 BulkRequest (org.elasticsearch.action.bulk.BulkRequest)6 BytesArray (org.elasticsearch.common.bytes.BytesArray)6 Matchers.equalTo (org.hamcrest.Matchers.equalTo)6