Class IoUringIoHandler

java.lang.Object
io.netty.channel.uring.IoUringIoHandler
All Implemented Interfaces:
IoHandler

public final class IoUringIoHandler extends java.lang.Object implements IoHandler
IoHandler which is implemented in terms of the Linux-specific io_uring API.
  • Field Details

    • logger

      private static final InternalLogger logger
    • WAKEUP_CLOSED

      private static final int WAKEUP_CLOSED
      See Also:
    • ringBuffer

      private final RingBuffer ringBuffer
    • registeredIoUringBufferRing

      private final IntObjectMap<IoUringBufferRing> registeredIoUringBufferRing
    • registrations

    • inet4AddressArray

      private final byte[] inet4AddressArray
    • inet6AddressArray

      private final byte[] inet6AddressArray
    • eventfdAsyncNotify

      private final java.util.concurrent.atomic.AtomicBoolean eventfdAsyncNotify
    • wakeupWriters

      private final java.util.concurrent.atomic.AtomicInteger wakeupWriters
    • eventfd

      private final FileDescriptor eventfd
    • eventfdReadBufCleanable

      private final CleanableDirectBuffer eventfdReadBufCleanable
    • eventfdReadBuf

      private final java.nio.ByteBuffer eventfdReadBuf
    • eventfdReadBufAddress

      private final long eventfdReadBufAddress
    • timeoutMemoryCleanable

      private final CleanableDirectBuffer timeoutMemoryCleanable
    • timeoutMemory

      private final java.nio.ByteBuffer timeoutMemory
    • timeoutMemoryAddress

      private final long timeoutMemoryAddress
    • iovArray

      private final IoUringSharedIovArray iovArray
    • eventfdReadSubmitted

      private long eventfdReadSubmitted
    • eventFdClosing

      private boolean eventFdClosing
    • shuttingDown

      private volatile boolean shuttingDown
    • closeCompleted

      private boolean closeCompleted
    • pendingOps

      private final PendingOpMap pendingOps
    • nextRegistrationId

      private int nextRegistrationId
    • INVALID_ID

      private static final long INVALID_ID
      See Also:
    • EVENTFD_TOKEN

      private static final long EVENTFD_TOKEN
    • RINGFD_TOKEN

      private static final long RINGFD_TOKEN
    • KERNEL_TIMESPEC_SIZE

      private static final int KERNEL_TIMESPEC_SIZE
      See Also:
    • KERNEL_TIMESPEC_TV_SEC_FIELD

      private static final int KERNEL_TIMESPEC_TV_SEC_FIELD
      See Also:
    • KERNEL_TIMESPEC_TV_NSEC_FIELD

      private static final int KERNEL_TIMESPEC_TV_NSEC_FIELD
      See Also:
    • executor

      private final ThreadAwareExecutor executor
    • completionCallback

      private final CompletionCallback completionCallback
  • Constructor Details

  • Method Details

    • initialize

      public void initialize()
      Description copied from interface: IoHandler
      Initialize this IoHandler.
      Specified by:
      initialize in interface IoHandler
    • run

      public int run(IoHandlerContext context)
      Description copied from interface: IoHandler
      Run the IO handled by this IoHandler. The IoHandlerContext should be used to ensure we not execute too long and so block the processing of other task that are scheduled on the ThreadAwareExecutor. This is done by taking IoHandlerContext.delayNanos(long) or IoHandlerContext.deadlineNanos() into account.
      Specified by:
      run in interface IoHandler
      Parameters:
      context - the IoHandlerContext.
      Returns:
      the number of IoHandle for which I/O was handled. Internal events such as wakeups and timer expirations must not be included in this count.
    • submitIfFullAndGetRemaining

      int submitIfFullAndGetRemaining()
    • needSubmit

      private boolean needSubmit(int sqFlags)
    • processCompletionsAndHandleOverflow

      private int processCompletionsAndHandleOverflow(SubmissionQueue submissionQueue, CompletionQueue completionQueue, CompletionCallback callback)
    • submitAndClearNow

      private int submitAndClearNow(SubmissionQueue submissionQueue)
    • submitAndClearNow0

      private int submitAndClearNow0(SubmissionQueue submissionQueue)
    • newBufferRing

      private static IoUringBufferRing newBufferRing(int ringFd, IoUringBufferRingConfig bufferRingConfig) throws Errors.NativeIoException
      Throws:
      Errors.NativeIoException
    • findBufferRing

      IoUringBufferRing findBufferRing(short bgId)
    • handleLoopException

      private static void handleLoopException(java.lang.Throwable throwable)
    • handle

      private boolean handle(int res, int flags, long udata, java.nio.ByteBuffer extraCqeData)
    • handleFastPath

      private void handleFastPath(int res, int flags, long udata, java.nio.ByteBuffer extraCqeData)
    • handleSlowPath

      private void handleSlowPath(int res, int flags, long udata, java.nio.ByteBuffer extraCqeData)
    • traceCompletion

      private void traceCompletion(IoUringIoHandler.DefaultIoUringIoRegistration registration, int registrationId, byte op, int res)
    • handleEventFdRead

      private void handleEventFdRead()
    • submitEventFdRead

      private void submitEventFdRead()
    • submitAndWaitWithTimeout

      private int submitAndWaitWithTimeout(SubmissionQueue submissionQueue, boolean linkTimeout, long timeoutNanoSeconds)
    • prepareToDestroy

      public void prepareToDestroy()
      Description copied from interface: IoHandler
      Prepare to destroy this IoHandler. This method will be called before IoHandler.destroy() and may be called multiple times.
      Specified by:
      prepareToDestroy in interface IoHandler
    • destroy

      public void destroy()
      Description copied from interface: IoHandler
      Destroy the IoHandler and free all its resources. Once destroyed using the IoHandler will cause undefined behaviour.
      Specified by:
      destroy in interface IoHandler
    • drainEventFd

      private void drainEventFd()
    • completeRingClose

      private void completeRingClose()
    • register

      public IoRegistration register(IoHandle handle) throws java.lang.Exception
      Description copied from interface: IoHandler
      Register a IoHandle for IO.
      Specified by:
      register in interface IoHandler
      Parameters:
      handle - the IoHandle to register.
      Throws:
      java.lang.Exception - thrown if an error happens during registration.
    • nextRegistrationId

      private int nextRegistrationId()
    • cast

      private static IoUringIoHandle cast(IoHandle handle)
    • wakeup

      public void wakeup()
      Description copied from interface: IoHandler
      Wakeup the IoHandler, which means if any operation blocks it should be unblocked and return as soon as possible.
      Specified by:
      wakeup in interface IoHandler
    • closeWakeupGate

      private void closeWakeupGate()
    • isCompatible

      public boolean isCompatible(java.lang.Class<? extends IoHandle> handleType)
      Description copied from interface: IoHandler
      Returns true if the given type is compatible with this IoHandler and so can be registered, false otherwise.
      Specified by:
      isCompatible in interface IoHandler
      Parameters:
      handleType - the type of the IoHandle.
      Returns:
      if compatible of not.
    • iovArray

      IovArray iovArray()
    • inet4AddressArray

      byte[] inet4AddressArray()
      byte[] that can be used as temporary storage to encode the ipv4 address
    • inet6AddressArray

      byte[] inet6AddressArray()
      byte[] that can be used as temporary storage to encode the ipv6 address
    • newFactory

      public static IoHandlerFactory newFactory()
      Create a new IoHandlerFactory that can be used to create IoUringIoHandlers.
      Returns:
      factory
    • newFactory

      public static IoHandlerFactory newFactory(int ringSize)
      Create a new IoHandlerFactory that can be used to create IoUringIoHandlers. Each IoUringIoHandler will use a ring of size ringSize.
      Parameters:
      ringSize - the size of the ring.
      Returns:
      factory
    • newFactory

      public static IoHandlerFactory newFactory(IoUringIoHandlerConfig config)
      Create a new IoHandlerFactory that can be used to create IoUringIoHandlers. Each IoUringIoHandler will use same option
      Parameters:
      config - the io_uring configuration
      Returns:
      factory