private void drainCommands ( long sequenceNumber , RaftSession session ) { // First we need to drain any commands that exist in the queue *prior* to the next sequence number. This is // possible if commands from the prior term are committed after a leader change. long nextSequence = session . nextRequestSequence ( ) ; for ( long i = sequenceNumber ; i < nextSequence ; i ++ ) { PendingCommand nextCommand = session . removeCommand ( i ) ; if ( nextCommand != null ) { commitCommand ( nextCommand . request ( ) , nextCommand . future ( ) ) ; } } // Finally, drain any commands that are sequenced in the session. PendingCommand nextCommand = session . removeCommand ( nextSequence ) ; while ( nextCommand != null ) { commitCommand ( nextCommand . request ( ) , nextCommand . future ( ) ) ; session . setRequestSequence ( nextSequence ) ; nextSequence = session . nextRequestSequence ( ) ; nextCommand = session . removeCommand ( nextSequence ) ; } }
Sequentially drains pending commands from the session s command request queue .