- final StackedSegment fastSegment = firstSegment;
- final long calcOffset = xid - fastSegment.getBaseXid();
- Preconditions.checkArgument(calcOffset >= 0, "Commit of XID %s does not match up with base XID %s", xid, fastSegment.getBaseXid());
-
- Verify.verify(calcOffset <= Integer.MAX_VALUE);
- final int fastOffset = (int) calcOffset;
-
- final OutboundQueueEntry entry;
- if (fastOffset >= StackedSegment.SEGMENT_SIZE) {
- LOG.debug("Queue {} falling back to slow commit of XID {} at offset {}", this, xid, fastOffset);
-
- final StackedSegment segment;
- final int slowOffset;
- synchronized (unflushedSegments) {
- final StackedSegment slowSegment = firstSegment;
- final long slowCalcOffset = xid - slowSegment.getBaseXid();
- Verify.verify(slowCalcOffset >= 0 && slowCalcOffset <= Integer.MAX_VALUE);
- slowOffset = (int) slowCalcOffset;
-
- LOG.debug("Queue {} recalculated offset of XID {} to {}", this, xid, slowOffset);
- segment = unflushedSegments.get(slowOffset / StackedSegment.SEGMENT_SIZE);
- }
-
- final int segOffset = slowOffset % StackedSegment.SEGMENT_SIZE;
- entry = segment.getEntry(segOffset);
- LOG.debug("Queue {} slow commit of XID {} completed at offset {} (segment {} offset {})", this, xid, slowOffset, segment, segOffset);
- } else {
- entry = fastSegment.getEntry(fastOffset);
- }