private void close() { // attempt to close once atomically if (closed.compareAndSet(false, true) == false) { throw new IllegalStateException("Channel is already closed"); } inFlightRequestsBreaker(circuitBreakerService).addWithoutBreaking(-contentLength); }
private void release(boolean isExceptionResponse) { if (released.compareAndSet(false, true)) { assert (releaseBy = new Exception()) != null; // easier to debug if it's already closed transport.getInFlightRequestBreaker().addWithoutBreaking(-reservedBytes); } else if (isExceptionResponse == false) { // only fail if we are not sending an error - we might send the error triggered by the previous // sendResponse call throw new IllegalStateException("reserved bytes are already released", releaseBy); } }
@Override public void onRemoval(ShardId shardId, String fieldName, boolean wasEvicted, long sizeInBytes) { assert sizeInBytes >= 0 : "When reducing circuit breaker, it should be adjusted with a number higher or " + "equal to 0 and not [" + sizeInBytes + "]"; circuitBreakerService.getBreaker(CircuitBreaker.FIELDDATA).addWithoutBreaking(-sizeInBytes); } });
/** * Adjust the circuit breaker now that terms have been loaded, getting * the actual used either from the parameter (if estimation worked for * the entire set), or from the TermsEnum if it has been wrapped in a * RamAccountingTermsEnum. * * @param termsEnum terms that were loaded * @param actualUsed actual field data memory usage */ @Override public void afterLoad(TermsEnum termsEnum, long actualUsed) { if (termsEnum instanceof RamAccountingTermsEnum) { estimatedBytes = ((RamAccountingTermsEnum) termsEnum).getTotalBytes(); } breaker.addWithoutBreaking(-(estimatedBytes - actualUsed)); }
breaker.addWithoutBreaking(delta); breaker.addWithoutBreaking(delta); breaker.addWithoutBreaking(delta);
/** Called upon release of the aggregator. */ @Override public void close() { try { doClose(); } finally { this.breakerService.getBreaker(CircuitBreaker.REQUEST).addWithoutBreaking(-this.requestBytesUsed); } }
/** * Increment or decrement the number of bytes that have been allocated to service * this request and potentially trigger a {@link CircuitBreakingException}. The * number of bytes allocated is automatically decremented with the circuit breaker * service on closure of this aggregator. * If memory has been returned, decrement it without tripping the breaker. * For performance reasons subclasses should not call this millions of times * each with small increments and instead batch up into larger allocations. * * @param bytes the number of bytes to register or negative to deregister the bytes * @return the cumulative size in bytes allocated by this aggregator to service this request */ protected long addRequestCircuitBreakerBytes(long bytes) { // Only use the potential to circuit break if bytes are being incremented if (bytes > 0) { this.breakerService .getBreaker(CircuitBreaker.REQUEST) .addEstimateBytesAndMaybeBreak(bytes, "<agg [" + name + "]>"); } else { this.breakerService .getBreaker(CircuitBreaker.REQUEST) .addWithoutBreaking(bytes); } this.requestBytesUsed += bytes; return requestBytesUsed; } /**
/** * Build global ordinals for the provided {@link IndexReader}. */ public static IndexOrdinalsFieldData build(final IndexReader indexReader, IndexOrdinalsFieldData indexFieldData, IndexSettings indexSettings, CircuitBreakerService breakerService, Logger logger, Function<SortedSetDocValues, ScriptDocValues<?>> scriptFunction) throws IOException { assert indexReader.leaves().size() > 1; long startTimeNS = System.nanoTime(); final AtomicOrdinalsFieldData[] atomicFD = new AtomicOrdinalsFieldData[indexReader.leaves().size()]; final SortedSetDocValues[] subs = new SortedSetDocValues[indexReader.leaves().size()]; for (int i = 0; i < indexReader.leaves().size(); ++i) { atomicFD[i] = indexFieldData.load(indexReader.leaves().get(i)); subs[i] = atomicFD[i].getOrdinalsValues(); } final OrdinalMap ordinalMap = OrdinalMap.build(null, subs, PackedInts.DEFAULT); final long memorySizeInBytes = ordinalMap.ramBytesUsed(); breakerService.getBreaker(CircuitBreaker.FIELDDATA).addWithoutBreaking(memorySizeInBytes); if (logger.isDebugEnabled()) { logger.debug( "global-ordinals [{}][{}] took [{}]", indexFieldData.getFieldName(), ordinalMap.getValueCount(), new TimeValue(System.nanoTime() - startTimeNS, TimeUnit.NANOSECONDS) ); } return new GlobalOrdinalsIndexFieldData(indexSettings, indexFieldData.getFieldName(), atomicFD, ordinalMap, memorySizeInBytes, scriptFunction ); }
final long ramBytesUsed = segmentReader.ramBytesUsed(); breaker.addWithoutBreaking(ramBytesUsed); segmentReader.getCoreCacheHelper().addClosedListener(k -> breaker.addWithoutBreaking(-ramBytesUsed));
inFlightRequestsBreaker(circuitBreakerService).addEstimateBytesAndMaybeBreak(contentLength, "<http_request>"); } else { inFlightRequestsBreaker(circuitBreakerService).addWithoutBreaking(contentLength);
@Override public void release() { long memSize = keys == null ? 0 : keys.length * 4l; // Release - do not allocate a new minimal buffer assigned = 0; hasEmptyKey = false; keys = null; // Adjust breaker breaker.addWithoutBreaking(-memSize); }
getInFlightRequestBreaker().addEstimateBytesAndMaybeBreak(messageLengthBytes, "<transport_request>"); } else { getInFlightRequestBreaker().addWithoutBreaking(messageLengthBytes);
private void close() { // attempt to close once atomically if (closed.compareAndSet(false, true) == false) { throw new IllegalStateException("Channel is already closed"); } inFlightRequestsBreaker(circuitBreakerService).addWithoutBreaking(-contentLength); }
private void close() { // attempt to close once atomically if (closed.compareAndSet(false, true) == false) { throw new IllegalStateException("Channel is already closed"); } inFlightRequestsBreaker(circuitBreakerService).addWithoutBreaking(-contentLength); }
@Override public void onRemoval(ShardId shardId, String fieldName, boolean wasEvicted, long sizeInBytes) { assert sizeInBytes >= 0 : "When reducing circuit breaker, it should be adjusted with a number higher or equal to 0 and not [" + sizeInBytes + "]"; circuitBreakerService.getBreaker(CircuitBreaker.FIELDDATA).addWithoutBreaking(-sizeInBytes); }
@Override public void afterLoad(@Nullable TermsEnum termsEnum, long actualUsed) { breaker.addWithoutBreaking(actualUsed); } }
private void close() { // attempt to close once atomically if (closed.compareAndSet(false, true) == false) { throw new IllegalStateException("Channel is already closed"); } sourceTransport.inFlightRequestsBreaker().addWithoutBreaking(-reservedBytes); }
private void release(boolean isExceptionResponse) { if (released.compareAndSet(false, true)) { assert (releaseBy = new Exception()) != null; // easier to debug if it's already closed transport.getInFlightRequestBreaker().addWithoutBreaking(-reservedBytes); } else if (isExceptionResponse == false) { // only fail if we are not sending an error - we might send the error triggered by the previous // sendResponse call throw new IllegalStateException("reserved bytes are already released", releaseBy); } }
/** Called upon release of the aggregator. */ @Override public void close() { try { doClose(); } finally { this.breakerService.getBreaker(CircuitBreaker.REQUEST).addWithoutBreaking(-this.requestBytesUsed); } }
/** Called upon release of the aggregator. */ @Override public void close() { try { doClose(); } finally { if (!this.failed) { this.breakerService.getBreaker(CircuitBreaker.REQUEST).addWithoutBreaking(-DEFAULT_WEIGHT); } } }