protected void releaseIndexBytes() { if (indexBytes != null) { if (builder.syncOnRoll()) { indexBytes.force(); } indexBytes.release(); indexBytes = null; } }
protected void releaseDataBytes() { if (dataBytes != null) { if (builder.syncOnRoll()) { dataBytes.force(); } dataBytes.release(); dataBytes = null; } } }
@Override public void finish() { if (finished) throw new IllegalStateException("Not started"); super.finish(); if (index != IndexedChronicle.this.size()) { throw new ConcurrentModificationException("Chronicle appended by more than one Appender at the same time, index=" + index + ", size=" + chronicle().size()); } // push out the entry is available. This is what the reader polls. // System.out.println(Long.toHexString(indexPositionAddr - indexStartAddr + indexStart) + "= " + (int) (dataPosition() - dataPositionAtStartOfLine)); long offsetInBlock = positionAddr - dataStartAddr; assert offsetInBlock >= 0 && offsetInBlock <= dataBlockSize; int relativeOffset = (int) (dataStartOffset + offsetInBlock - indexBaseForLine); assert relativeOffset >= 0; writeIndexEntry(relativeOffset); indexPositionAddr += 4; index++; IndexedChronicle.this.incrSize(); if ((indexPositionAddr & cacheLineMask) == 0 && indexPositionAddr - indexStartAddr < indexBlockSize) { indexBaseForLine += relativeOffset; appendStartOfLine(); } if (nextSynchronous) { assert dataBuffer != null; dataBuffer.force(); assert indexBuffer != null; indexBuffer.force(); } }
@Override public void finish() { super.finish(); if (index != IndexedChronicle.this.size()) throw new ConcurrentModificationException("Chronicle appended by more than one Appender at the same time, index=" + index + ", size=" + chronicle().size()); // push out the entry is available. This is what the reader polls. // System.out.println(Long.toHexString(indexPositionAddr - indexStartAddr + indexStart) + "= " + (int) (dataPosition() - dataPositionAtStartOfLine)); long offsetInBlock = positionAddr - dataStartAddr; assert offsetInBlock >= 0 && offsetInBlock <= dataBlockSize; int relativeOffset = (int) (dataStartOffset + offsetInBlock - indexBaseForLine); assert relativeOffset > 0; writeIndexEntry(relativeOffset); indexPositionAddr += 4; index++; IndexedChronicle.this.incrSize(); if ((indexPositionAddr & cacheLineMask) == 0 && indexPositionAddr - indexStartAddr < indexBlockSize) { indexBaseForLine += relativeOffset; appendStartOfLine(); } if (nextSynchronous) { assert dataBuffer != null; dataBuffer.force(); assert indexBuffer != null; indexBuffer.force(); } }
public static long append(final VanillaMappedBytes bytes, final long indexValue, final boolean synchronous) { // Position can be changed by another thread, so take a snapshot each loop so that // buffer overflows are not generated when advancing to the next position. // As a result, the position could step backwards when this method is called concurrently, // but the compareAndSwapLong call ensures that data is never overwritten. if(bytes != null) { boolean endOfFile = false; while (!endOfFile) { final long position = bytes.position(); endOfFile = (bytes.limit() - position) < 8; if (!endOfFile) { if (bytes.compareAndSwapLong(position, 0L, indexValue)) { if (synchronous) { bytes.force(); } return position; } bytes.position(position + 8); } } } return -1; }
public static long append(final VanillaMappedBytes bytes, final long indexValue, final boolean synchronous) { // Position can be changed by another thread, so take a snapshot each loop // so that buffer overflows are not generated when advancing to the next // position. As a result, the position could step backwards when this method // is called concurrently, but the compareAndSwapLong call ensures that // data is never overwritten. if (bytes != null) { boolean endOfFile = false; long position = bytes.position(); while (!endOfFile) { endOfFile = (bytes.limit() - position) < 8; if (!endOfFile) { if (bytes.compareAndSwapLong(position, 0L, indexValue)) { bytes.lazyPosition(position + 8); if (synchronous) { bytes.force(); } return position; } } position += 8; } } return -1; }
dataBytes.force();
dataBytes.force();