Class WriteOperationTracker

java.lang.Object
io.netty.channel.uring.WriteOperationTracker

final class WriteOperationTracker extends Object
Owns every in-flight write operation a channel tracks, across the four namespaces a channel can have live at once: a pooled slot array (ids this class hands out itself), an overflow map (a long-id fallback once the pooled range is exhausted), a foreign slot array (ids an allocator this class does not own hands the caller, such as a MsgHdrMemoryArray index), and a single slot for the one non-zero-copy write a stream channel can have outstanding at a time. One instance per channel, created unconditionally in the channel constructor.
  • Field Details

  • Constructor Details

    • WriteOperationTracker

      WriteOperationTracker()
  • Method Details

    • nextId

      short nextId()
      Returns a write-operation id that no in-flight write owns, or 0 when every id is held by a write that has not seen its terminal CQE yet. Released ids come back through a free list, so this does not search.
    • nextZeroCopyId

      long nextZeroCopyId()
      Returns a write-operation id for a zero-copy write, falling back to a long id outside the short range once every short id is held by an in-flight write, so the write still gets submitted instead of being deferred. Never returns 0.
    • record

      void record(long id, byte opCode, ReferenceCounted reference)
      Registers a write whose id came from nextId() or nextZeroCopyId(). A pooled id goes back to the free list once the terminal CQE arrives; an overflow id is never reused, its map entry is simply dropped.
    • recordOverflow

      private void recordOverflow(long id, byte opCode, ReferenceCounted reference)
    • record

      void record(long id, byte opCode, ReferenceCounted[] references, int count)
      Registers a write of multiple references whose id came from nextId() or nextZeroCopyId(). Copies references, so the caller may reuse the array.
    • recordOverflow

      private void recordOverflow(long id, byte opCode, ReferenceCounted[] references, int count)
    • recordForeign

      void recordForeign(short id, byte opCode, ReferenceCounted reference)
      Registers a write whose id is owned by another allocator, such as the MsgHdrMemoryArray index used by the datagram sendmsg path. That id lives in its own slot array and never enters the free list.
    • abandon

      void abandon(long id, byte opCode)
      Ends the slot identified by id/opCode without it seeing a completion CQE: the submission itself failed, so the kernel never saw the SQE and no CQE will ever arrive for it. A pooled id goes back to the free list, an overflow entry is dropped. Deregistration ends its slots through releaseAll() instead.
    • abandonOverflow

      private void abandonOverflow(long id, byte opCode)
    • complete

      void complete(long id, byte opCode, int flags)
      Applies a completion CQE to the slot identified by id/opCode. A terminated pooled slot's id is recycled back to the free list; a terminated overflow slot is removed from the map.
    • completeOverflow

      private void completeOverflow(long id, byte opCode, int flags)
    • retainReferences

      void retainReferences(long id, byte opCode)
      Retains the references held by the active slot identified by id/opCode, if any. Called from the zero-copy completion path, where IORING_CQE_F_MORE says the kernel still owns the memory until the follow-up IORING_CQE_F_NOTIF. The shutdown path uses retainAll() instead.
    • retainOverflowReference

      private void retainOverflowReference(long id, byte opCode)
    • overflowCount

      int overflowCount()
      The number of write operations parked in the overflow map. Test-only: no production caller, used to assert completions and abandons drop their entry.
    • recordStream

      void recordStream(byte opCode, ReferenceCounted reference)
      Records a single reference on the non-zero-copy stream write slot. No id, no array, no opcode match.
    • recordStream

      void recordStream(byte opCode, ReferenceCounted[] references, int count)
      Records multiple references (e.g. writev) on the non-zero-copy stream write slot. Copies references.
    • abandonStream

      void abandonStream()
      Ends the stream slot without it ever seeing a completion CQE, for the same reason as abandon(long, byte): the submission itself failed. A no-op if the slot is inactive. There is no id, so there is no opcode match either -- the slot simply finishes. Deregistration ends this slot through releaseAll() instead.
    • completeStream

      void completeStream(int flags)
      Applies a completion CQE to the stream slot.
    • isStreamActive

      boolean isStreamActive()
      Whether the stream slot is active. Test-only: no production caller, used to assert completions and abandons leave it inactive, same as overflowCount().
    • retainAll

      void retainAll()
      Retains every active slot's references across all four members (pooled, foreign, overflow, single) right before a shutdown, so a write completion that races the shutdown still finds a live reference to release instead of one the outbound buffer already dropped.
    • releaseAll

      void releaseAll()
      Abandons every active slot across all four members and empties them, via WriteOperation.abandon() on each: a release for a slot retainAll() retained, a plain discard for one it never reached. Named for the former, more consequential case -- the one this method exists to guard against -- rather than the latter, more common one. No further completion arrives once a channel is deregistered, so references a shutdown retained on a slot would otherwise leak forever.
    • ensureCapacity

      private static WriteOperation[] ensureCapacity(WriteOperation[] operations, short id)
    • slot

      private static WriteOperation slot(WriteOperation[] operations, short id)
    • overflowSlot

      private WriteOperation overflowSlot(long id)
    • matchingOverflow

      private WriteOperation matchingOverflow(long id, byte opCode)
    • matching

      private static WriteOperation matching(WriteOperation[] operations, short id, byte opCode)
    • recycleId

      private void recycleId(short id)
    • retainArray

      private static void retainArray(WriteOperation[] operations)
    • retainOverflow

      private void retainOverflow()
    • retainSingle

      private void retainSingle()
    • releaseArray

      private static void releaseArray(WriteOperation[] operations)
    • releaseOverflow

      private void releaseOverflow()