public boolean keepAlive ( long index , long timestamp , RaftSession session , long commandSequence , long eventIndex ) { // If the service has been deleted, just return false to ignore the keep-alive. if ( deleted ) { return false ; } // Update the state machine index/timestamp. tick ( index , timestamp ) ; // The session may have been closed by the time this update was executed on the service thread. if ( session . getState ( ) != Session . State . CLOSED ) { // Update the session's timestamp to prevent it from being expired. session . setLastUpdated ( timestamp ) ; // Clear results cached in the session. session . clearResults ( commandSequence ) ; // Resend missing events starting from the last received event index. session . resendEvents ( eventIndex ) ; // Update the session's request sequence number. The command sequence number will be applied // iff the existing request sequence number is less than the command sequence number. This must // be applied to ensure that request sequence numbers are reset after a leader change since leaders // track request sequence numbers in local memory. session . resetRequestSequence ( commandSequence ) ; // Update the sessions' command sequence number. The command sequence number will be applied // iff the existing sequence number is less than the keep-alive command sequence number. This should // not be the case under normal operation since the command sequence number in keep-alive requests // represents the highest sequence for which a client has received a response (the command has already // been completed), but since the log compaction algorithm can exclude individual entries from replication, // the command sequence number must be applied for keep-alive requests to reset the sequence number in // the event the last command for the session was cleaned/compacted from the log. session . setCommandSequence ( commandSequence ) ; // Complete the future. return true ; } else { return false ; } }
Keeps the given session alive .