@Override public long index() throws IORuntimeException { if (this.wire.headerNumber() == Long.MIN_VALUE) { try { wire.headerNumber(queue.rollCycle().toIndex(cycle, store.lastSequenceNumber(StoreAppender.this))); long headerNumber0 = wire.headerNumber(); assert (((AbstractWire) this.wire).isInsideHeader()); return isMetaData() ? headerNumber0 : headerNumber0 + 1; } catch (IOException e) { throw new IORuntimeException(e); } } return isMetaData() ? Long.MIN_VALUE : this.wire.headerNumber() + 1; }
boolean checkWritePositionHeaderNumber() { if (wire == null || wire.headerNumber() == Long.MIN_VALUE) return true; try { long pos = position; long seq1 = queue.rollCycle().toSequenceNumber(wire.headerNumber() + 1) - 1; long seq2 = store.sequenceForPosition(this, pos, true); if (seq1 != seq2) { // System.out.println(queue.dump()); String message = "~~~~~~~~~~~~~~ " + "thread: " + Thread.currentThread().getName() + " pos: " + pos + " header: " + wire.headerNumber() + " seq1: " + seq1 + " seq2: " + seq2; //System.err.println(message); new AssertionError(message).printStackTrace(); throw new AssertionError(message); } } catch (Exception e) { Jvm.fatal().on(getClass(), e); throw Jvm.rethrow(e); } return true; }
private void resetPosition() throws UnrecoverableTimeoutException { try { if (store == null || wire == null) return; position(store.writePosition()); assert position == 0 || Wires.isReadyData(wire.bytes().readVolatileInt(position)); final long headerNumber = store.lastSequenceNumber(this); wire.headerNumber(queue.rollCycle().toIndex(cycle, headerNumber + 1) - 1); assert wire.headerNumber() != -1 || checkIndex(wire.headerNumber(), position); } catch (@NotNull BufferOverflowException | StreamCorruptedException e) { throw new AssertionError(e); } assert checkWritePositionHeaderNumber(); }
rollCycleTo(cycle); boolean rollbackDontClose = index != wire.headerNumber() + 1; if (rollbackDontClose) { if (index > wire.headerNumber() + 1) throw new IllegalStateException("Unable to move to index " + Long.toHexString(index) + " beyond the end of the queue");
lastIndex(wire.headerNumber()); store.writePosition(position); if (lastIndex != Long.MIN_VALUE) } else if (wire != null) { isClosed = true; writeBytesInternal(wire.headerNumber(), wire.bytes()); wire = StoreAppender.this.wire;
final long targetHeaderNumber = wire.headerNumber() + 1; String msgStart = "Unable to write a header at header number: 0x" + Long.toHexString(targetHeaderNumber) + " position: " + offset; if (Wires.isNotComplete(num)) {
private long writeHeader(@NotNull Wire wire, int safeLength) { Bytes<?> bytes = wire.bytes(); // writePosition points at the last record in the queue, so we can just skip it and we're ready for write long pos = position; long lastPos = store.writePosition(); if (pos < lastPos) { // queue moved since we last touched it - recalculate header number try { wire.headerNumber(queue.rollCycle().toIndex(cycle, store.lastSequenceNumber(this))); } catch (StreamCorruptedException ex) { Jvm.warn().on(getClass(), "Couldn't find last sequence", ex); } } int header = bytes.readVolatileInt(lastPos); assert header != NOT_INITIALIZED; lastPos += lengthOf(bytes.readVolatileInt(lastPos)) + SPB_HEADER_SIZE; bytes.writePosition(lastPos); return wire.enterHeader(safeLength); }
@Override public void writeBytes(@NotNull BytesStore bytes) throws UnrecoverableTimeoutException { writeLock.lock(); try { int cycle = queue.cycle(); if (this.cycle != cycle || wire == null) rollCycleTo(cycle); position(writeHeader(wire, (int) queue.overlapSize())); assert ((AbstractWire) wire).isInsideHeader(); beforeAppend(wire, wire.headerNumber() + 1); Bytes<?> wireBytes = wire.bytes(); wireBytes.write(bytes); if (padToCacheLines == Padding.WORD) wireBytes.writeSkip((-wireBytes.writePosition()) & 0x3); wire.updateHeader(position, false, 0); lastIndex(wire.headerNumber()); lastPosition = position; lastCycle = cycle; store.writePosition(position); writeIndexForPosition(lastIndex, position); } catch (StreamCorruptedException e) { throw new AssertionError(e); } finally { writeLock.unlock(); } }
@Override public long index() throws IORuntimeException { if (this.wire.headerNumber() == Long.MIN_VALUE) { try { wire.headerNumber(queue.rollCycle().toIndex(cycle, store.lastSequenceNumber(StoreAppender.this))); long headerNumber0 = wire.headerNumber(); assert (((AbstractWire) this.wire).isInsideHeader()); return isMetaData() ? headerNumber0 : headerNumber0 + 1; } catch (IOException e) { throw new IORuntimeException(e); } } return isMetaData() ? Long.MIN_VALUE : this.wire.headerNumber() + 1; }
boolean checkWritePositionHeaderNumber() { if (wire == null || wire.headerNumber() == Long.MIN_VALUE) return true; try { long pos = position; long seq1 = queue.rollCycle().toSequenceNumber(wire.headerNumber() + 1) - 1; long seq2 = store.sequenceForPosition(this, pos, true); if (seq1 != seq2) { // System.out.println(queue.dump()); String message = "~~~~~~~~~~~~~~ " + "thread: " + Thread.currentThread().getName() + " pos: " + pos + " header: " + wire.headerNumber() + " seq1: " + seq1 + " seq2: " + seq2; //System.err.println(message); new AssertionError(message).printStackTrace(); throw new AssertionError(message); } } catch (Exception e) { Jvm.fatal().on(getClass(), e); throw Jvm.rethrow(e); } return true; }
private void resetPosition() throws UnrecoverableTimeoutException { try { if (store == null || wire == null) return; position(store.writePosition()); assert position == 0 || Wires.isReadyData(wire.bytes().readVolatileInt(position)); final long headerNumber = store.lastSequenceNumber(this); wire.headerNumber(queue.rollCycle().toIndex(cycle, headerNumber + 1) - 1); assert wire.headerNumber() != -1 || checkIndex(wire.headerNumber(), position); } catch (@NotNull BufferOverflowException | StreamCorruptedException e) { throw new AssertionError(e); } assert checkWritePositionHeaderNumber(); }
rollCycleTo(cycle); boolean rollbackDontClose = index != wire.headerNumber() + 1; if (rollbackDontClose) { if (index > wire.headerNumber() + 1) throw new IllegalStateException("Unable to move to index " + Long.toHexString(index) + " beyond the end of the queue");
lastIndex(wire.headerNumber()); store.writePosition(position); if (lastIndex != Long.MIN_VALUE) } else if (wire != null) { isClosed = true; writeBytesInternal(wire.headerNumber(), wire.bytes()); wire = StoreAppender.this.wire;
final long targetHeaderNumber = wire.headerNumber() + 1; String msgStart = "Unable to write a header at header number: 0x" + Long.toHexString(targetHeaderNumber) + " position: " + offset; if (Wires.isNotComplete(num)) {
private long writeHeader(@NotNull Wire wire, int safeLength) { Bytes<?> bytes = wire.bytes(); // writePosition points at the last record in the queue, so we can just skip it and we're ready for write long pos = position; long lastPos = store.writePosition(); if (pos < lastPos) { // queue moved since we last touched it - recalculate header number try { wire.headerNumber(queue.rollCycle().toIndex(cycle, store.lastSequenceNumber(this))); } catch (StreamCorruptedException ex) { Jvm.warn().on(getClass(), "Couldn't find last sequence", ex); } } int header = bytes.readVolatileInt(lastPos); assert header != NOT_INITIALIZED; lastPos += lengthOf(bytes.readVolatileInt(lastPos)) + SPB_HEADER_SIZE; bytes.writePosition(lastPos); return wire.enterHeader(safeLength); }
@Override public void writeBytes(@NotNull BytesStore bytes) throws UnrecoverableTimeoutException { writeLock.lock(); try { int cycle = queue.cycle(); if (wire == null) setWireIfNull(cycle); if (this.cycle != cycle) rollCycleTo(cycle); position(writeHeader(wire, (int) queue.overlapSize())); assert ((AbstractWire) wire).isInsideHeader(); beforeAppend(wire, wire.headerNumber() + 1); Bytes<?> wireBytes = wire.bytes(); wireBytes.write(bytes); if (padToCacheLines == Padding.WORD) wireBytes.writeSkip((-wireBytes.writePosition()) & 0x3); wire.updateHeader(position, false, 0); lastIndex(wire.headerNumber()); lastPosition = position; lastCycle = cycle; store.writePosition(position); writeIndexForPosition(lastIndex, position); } catch (StreamCorruptedException e) { throw new AssertionError(e); } finally { writeLock.unlock(); } }