/** * @return the number of bytes currently allocated by this {@link Allocator} */ public long bytesUsed() { return bytesUsed.get(); }
/** * @return the number of bytes currently allocated by this {@link Allocator} */ public long bytesUsed() { return bytesUsed.get(); }
long bytesUsed() { return bytesUsed.get() + pendingUpdates.bytesUsed.get(); }
/** * Syntactic sugar for {@link #setBaseline(long)} using {@link Counter#get()} * on the clock passed to the constructor. */ public void setBaseline() { setBaseline(clock.get()); }
/** * Removes the given number of byte blocks from the buffer if possible. * * @param num * the number of byte blocks to remove * @return the number of actually removed buffers */ public int freeBlocks(int num) { assert num >= 0 : "free blocks must be >= 0 but was: "+ num; final int stop; final int count; if (num > freeBlocks) { stop = 0; count = freeBlocks; } else { stop = freeBlocks - num; count = num; } while (freeBlocks > stop) { freeByteBlocks[--freeBlocks] = null; } bytesUsed.addAndGet(-count*blockSize); assert bytesUsed.get() >= 0; return count; } }
/** * Removes the given number of int blocks from the buffer if possible. * * @param num * the number of int blocks to remove * @return the number of actually removed buffers */ public int freeBlocks(int num) { assert num >= 0 : "free blocks must be >= 0 but was: "+ num; final int stop; final int count; if (num > freeBlocks) { stop = 0; count = freeBlocks; } else { stop = freeBlocks - num; count = num; } while (freeBlocks > stop) { freeByteBlocks[--freeBlocks] = null; } bytesUsed.addAndGet(-count*blockSize*Integer.BYTES); assert bytesUsed.get() >= 0; return count; } }
@Override public void recycleByteBlocks(byte[][] blocks, int start, int end) { final int numBlocks = Math.min(maxBufferedBlocks - freeBlocks, end - start); final int size = freeBlocks + numBlocks; if (size >= freeByteBlocks.length) { final byte[][] newBlocks = new byte[ArrayUtil.oversize(size, RamUsageEstimator.NUM_BYTES_OBJECT_REF)][]; System.arraycopy(freeByteBlocks, 0, newBlocks, 0, freeBlocks); freeByteBlocks = newBlocks; } final int stop = start + numBlocks; for (int i = start; i < stop; i++) { freeByteBlocks[freeBlocks++] = blocks[i]; blocks[i] = null; } for (int i = stop; i < end; i++) { blocks[i] = null; } bytesUsed.addAndGet(-(end - stop) * blockSize); assert bytesUsed.get() >= 0; }
@Override public void recycleIntBlocks(int[][] blocks, int start, int end) { final int numBlocks = Math.min(maxBufferedBlocks - freeBlocks, end - start); final int size = freeBlocks + numBlocks; if (size >= freeByteBlocks.length) { final int[][] newBlocks = new int[ArrayUtil.oversize(size, RamUsageEstimator.NUM_BYTES_OBJECT_REF)][]; System.arraycopy(freeByteBlocks, 0, newBlocks, 0, freeBlocks); freeByteBlocks = newBlocks; } final int stop = start + numBlocks; for (int i = start; i < stop; i++) { freeByteBlocks[freeBlocks++] = blocks[i]; blocks[i] = null; } for (int i = stop; i < end; i++) { blocks[i] = null; } bytesUsed.addAndGet(-(end - stop) * (blockSize * Integer.BYTES)); assert bytesUsed.get() >= 0; }
@Override public void collect(int doc) throws IOException { final long time = clock.get(); if (time - timeout > 0L) { if (greedy) { //System.out.println(this+" greedy: before failing, collecting doc: "+(docBase + doc)+" "+(time-t0)); in.collect(doc); } //System.out.println(this+" failing on: "+(docBase + doc)+" "+(time-t0)); throw new TimeExceededException( timeout-t0, time-t0, docBase + doc ); } //System.out.println(this+" collecting: "+(docBase + doc)+" "+(time-t0)); in.collect(doc); }
@Override public LeafCollector getLeafCollector(LeafReaderContext context) throws IOException { this.docBase = context.docBase; if (Long.MIN_VALUE == t0) { setBaseline(); } final long time = clock.get(); if (time - timeout > 0L) { throw new TimeExceededException(timeout - t0, time - t0, -1); } return new FilterLeafCollector(collector.getLeafCollector(context)) { @Override public void collect(int doc) throws IOException { final long time = clock.get(); if (time - timeout > 0L) { if (greedy) { //System.out.println(this+" greedy: before failing, collecting doc: "+(docBase + doc)+" "+(time-t0)); in.collect(doc); } //System.out.println(this+" failing on: "+(docBase + doc)+" "+(time-t0)); throw new TimeExceededException( timeout-t0, time-t0, docBase + doc ); } //System.out.println(this+" collecting: "+(docBase + doc)+" "+(time-t0)); in.collect(doc); } }; }
if (bufferBytesUsed.get() > ramBufferSize.bytes) { break;
synchronized long getTranslogRefCount(long gen) { final Counter counter = translogRefCounts.get(gen); return counter == null ? 0 : counter.get(); } }
/** * releases a generation that was acquired by {@link #acquireTranslogGen(long)} */ private synchronized void releaseTranslogGen(long translogGen) { Counter current = translogRefCounts.get(translogGen); if (current == null || current.get() <= 0) { throw new IllegalArgumentException("translog gen [" + translogGen + "] wasn't acquired"); } if (current.addAndGet(-1) == 0) { translogRefCounts.remove(translogGen); } }
/** * @return the number of bytes currently allocated by this {@link Allocator} */ public long bytesUsed() { return bytesUsed.get(); }
/** * Return the memory usage of this object in bytes. */ public long ramBytesUsed() { return bytesUsed.get(); }
/** * @return the number of bytes currently allocated by this {@link Allocator} */ public long bytesUsed() { return bytesUsed.get(); }
synchronized long getTranslogRefCount(long gen) { final Counter counter = translogRefCounts.get(gen); return counter == null ? 0 : counter.get(); } }
/** * releases a generation that was acquired by {@link #acquireTranslogGen(long)} */ private synchronized void releaseTranslogGen(long translogGen) { Counter current = translogRefCounts.get(translogGen); if (current == null || current.get() <= 0) { throw new IllegalArgumentException("translog gen [" + translogGen + "] wasn't acquired"); } if (current.addAndGet(-1) == 0) { translogRefCounts.remove(translogGen); } }
if (timeoutSet) { final Counter counter = searchContext.timeEstimateCounter(); final long startTime = counter.get(); final long timeout = searchContext.timeout().millis(); final long maxTime = startTime + timeout; timeoutRunnable = () -> { final long time = counter.get(); if (time > maxTime) { throw new TimeExceededException();