Class WriteOperationTracker
java.lang.Object
io.netty.channel.uring.WriteOperationTracker
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 Summary
FieldsModifier and TypeFieldDescriptionprivate WriteOperation[]private intprivate short[]private intprivate static final InternalLoggerprivate static final intprivate longprivate LongObjectHashMap<WriteOperation> private WriteOperation[]private final WriteOperation -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) voidabandon(long id, byte opCode) Ends the slot identified byid/opCodewithout it seeing a completion CQE: the submission itself failed, so the kernel never saw the SQE and no CQE will ever arrive for it.private voidabandonOverflow(long id, byte opCode) (package private) voidEnds the stream slot without it ever seeing a completion CQE, for the same reason asabandon(long, byte): the submission itself failed.(package private) voidcomplete(long id, byte opCode, int flags) Applies a completion CQE to the slot identified byid/opCode.private voidcompleteOverflow(long id, byte opCode, int flags) (package private) voidcompleteStream(int flags) Applies a completion CQE to the stream slot.private static WriteOperation[]ensureCapacity(WriteOperation[] operations, short id) (package private) booleanWhether the stream slot is active.private static WriteOperationmatching(WriteOperation[] operations, short id, byte opCode) private WriteOperationmatchingOverflow(long id, byte opCode) (package private) shortnextId()Returns a write-operation id that no in-flight write owns, or0when every id is held by a write that has not seen its terminal CQE yet.(package private) longReturns 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.(package private) intThe number of write operations parked in the overflow map.private WriteOperationoverflowSlot(long id) (package private) voidrecord(long id, byte opCode, ReferenceCounted reference) Registers a write whose id came fromnextId()ornextZeroCopyId().(package private) voidrecord(long id, byte opCode, ReferenceCounted[] references, int count) Registers a write of multiple references whose id came fromnextId()ornextZeroCopyId().(package private) voidrecordForeign(short id, byte opCode, ReferenceCounted reference) Registers a write whose id is owned by another allocator, such as theMsgHdrMemoryArrayindex used by the datagram sendmsg path.private voidrecordOverflow(long id, byte opCode, ReferenceCounted reference) private voidrecordOverflow(long id, byte opCode, ReferenceCounted[] references, int count) (package private) voidrecordStream(byte opCode, ReferenceCounted reference) Records a single reference on the non-zero-copy stream write slot.(package private) voidrecordStream(byte opCode, ReferenceCounted[] references, int count) Records multiple references (e.g.private voidrecycleId(short id) (package private) voidAbandons every active slot across all four members and empties them, viaWriteOperation.abandon()on each: a release for a slotretainAll()retained, a plain discard for one it never reached.private static voidreleaseArray(WriteOperation[] operations) private void(package private) voidRetains 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.private static voidretainArray(WriteOperation[] operations) private voidprivate voidretainOverflowReference(long id, byte opCode) (package private) voidretainReferences(long id, byte opCode) Retains the references held by the active slot identified byid/opCode, if any.private voidprivate static WriteOperationslot(WriteOperation[] operations, short id)
-
Field Details
-
logger
-
MAX_POOLED_ID
private static final int MAX_POOLED_ID- See Also:
-
pooled
-
foreign
-
freeIds
private short[] freeIds -
freeIdCount
private int freeIdCount -
issuedIds
private int issuedIds -
nextOverflowId
private long nextOverflowId -
overflow
-
single
-
-
Constructor Details
-
WriteOperationTracker
WriteOperationTracker()
-
-
Method Details
-
nextId
short nextId()Returns a write-operation id that no in-flight write owns, or0when 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
Registers a write whose id came fromnextId()ornextZeroCopyId(). 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
-
record
Registers a write of multiple references whose id came fromnextId()ornextZeroCopyId(). Copiesreferences, so the caller may reuse the array. -
recordOverflow
-
recordForeign
Registers a write whose id is owned by another allocator, such as theMsgHdrMemoryArrayindex 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 byid/opCodewithout 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 throughreleaseAll()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 byid/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 byid/opCode, if any. Called from the zero-copy completion path, whereIORING_CQE_F_MOREsays the kernel still owns the memory until the follow-upIORING_CQE_F_NOTIF. The shutdown path usesretainAll()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
Records a single reference on the non-zero-copy stream write slot. No id, no array, no opcode match. -
recordStream
Records multiple references (e.g. writev) on the non-zero-copy stream write slot. Copiesreferences. -
abandonStream
void abandonStream()Ends the stream slot without it ever seeing a completion CQE, for the same reason asabandon(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 throughreleaseAll()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 asoverflowCount(). -
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, viaWriteOperation.abandon()on each: a release for a slotretainAll()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
-
slot
-
overflowSlot
-
matchingOverflow
-
matching
-
recycleId
private void recycleId(short id) -
retainArray
-
retainOverflow
private void retainOverflow() -
retainSingle
private void retainSingle() -
releaseArray
-
releaseOverflow
private void releaseOverflow()
-