0 Replies Latest reply on Nov 21, 2009 10:51 AM by clebert.suconic

    AIO Ordering

    clebert.suconic

      As you guys known, libaio can't guarantee ordering over the callbacks.

      When you send a callback to AIO, the response could come in an aleatory order from the native layer.

      NIO don't have that problem, as it will always guarantee flushing at the correct ordering.


      AIO is actually mostly ordered. It will eventually deliver the callbacks out of order.


      So, to fix that... each write on AIO will now have a long associated. This is the signature of the native method after my changes:

      private native void write(long handle, long sequence,long position, long size,ByteBuffer buffer,AIOCallback aioPackage)
      


      The Poller thread will then call this method on AsynchronousFileImpl as soon as libaio is done with the write:

      private void callbackDone(final AIOCallback callback, final long sequence, final ByteBuffer buffer)




      if the callback is at the expected sequence (which will be most of the time):


      if (sequence == nextReadSequence)
       {
       nextReadSequence++;
       callback.done();
       flushCallbacks();
      



      if not, it will hold the callback on a PriorityQueue:

      The queue will be emptied properly as soon as the proper sequence arrives.



      This is just to guarantee AIO having the same semantics on answering callbacks as NIO.