private static void copyAndReplaceUncompressedChunks( UncompressedCacheChunk candidateCached, ByteBuffer dest, CacheChunk tcc) { int startPos = dest.position(), startLim = dest.limit(); DiskRangeList next = null; for (int i = 0; i < candidateCached.getCount(); ++i) { BufferChunk chunk = (i == 0) ? candidateCached.getChunk() : (BufferChunk)next; dest.put(chunk.getData()); next = chunk.next; if (i == 0) { chunk.replaceSelfWith(tcc); } else { chunk.removeSelf(); } } int newPos = dest.position(); if (newPos > startLim) { throw new AssertionError("After copying, buffer [" + startPos + ", " + startLim + ") became [" + newPos + ", " + dest.limit() + ")"); } dest.position(startPos); dest.limit(newPos); }
candidateCached = new UncompressedCacheChunk(curBc); } else { candidateCached.addChunk(curBc); candidateCached.setBuffer(targetBuffers[ix]); ByteBuffer dest = candidateCached.getBuffer().getByteBufferRaw(); copyAndReplaceUncompressedChunks(candidateCached, dest, candidateCached); candidateCached.clear(); lastUncompressed = candidateCached; ++ix;
candidateCached = new UncompressedCacheChunk(curBc); } else { candidateCached.addChunk(curBc); candidateCached.setBuffer(targetBuffers[ix]); ByteBuffer dest = candidateCached.getBuffer().getByteBufferRaw(); copyAndReplaceUncompressedChunks(candidateCached, dest, candidateCached, true); candidateCached.clear(); lastUncompressed = candidateCached; ++ix;
private void copyAndReplaceUncompressedChunks(UncompressedCacheChunk candidateCached, ByteBuffer dest, CacheChunk tcc, boolean isValid) { int startPos = dest.position(), startLim = dest.limit(); DiskRangeList next = null; for (int i = 0; i < candidateCached.getCount(); ++i) { BufferChunk chunk = (i == 0) ? candidateCached.getChunk() : (BufferChunk)next; dest.put(chunk.getData()); if (isValid) { trace.logValidUncompresseedChunk(startLim - startPos, chunk); } next = chunk.next; if (i == 0) { chunk.replaceSelfWith(tcc); } else { chunk.removeSelf(); } } int newPos = dest.position(); if (newPos > startLim) { throw new AssertionError("After copying, buffer [" + startPos + ", " + startLim + ") became [" + newPos + ", " + dest.limit() + ")"); } dest.position(startPos); dest.limit(newPos); }
public UncompressedCacheChunk(BufferChunk bc) { super(); init(null, bc.getOffset(), bc.getEnd()); chunk = bc; count = 1; }
@Override public void handleCacheCollision(DataCache cacheWrapper, MemoryBuffer replacementBuffer, List<MemoryBuffer> cacheBuffers) { assert cacheBuffers == null; // This is done at pre-read stage where there's nothing special w/refcounts. Just release. cacheWrapper.getAllocator().deallocate(getBuffer()); // Replace the buffer in our big range list, as well as in current results. this.setBuffer(replacementBuffer); }
public void addChunk(BufferChunk bc) { assert bc.getOffset() == this.getEnd(); this.end = bc.getEnd(); ++count; }
@Override public void handleCacheCollision(DataCache cacheWrapper, MemoryBuffer replacementBuffer, List<MemoryBuffer> cacheBuffers) { assert cacheBuffers == null; // This is done at pre-read stage where there's nothing special w/refcounts. Just release. cacheWrapper.getAllocator().deallocate(getBuffer()); // Replace the buffer in our big range list, as well as in current results. this.setBuffer(replacementBuffer); }
public void addChunk(BufferChunk bc) { assert bc.getOffset() == this.getEnd(); this.end = bc.getEnd(); ++count; }