public boolean installSnapshot ( SnapshotEntry snapshot ) { long commitIndex = state . commitIndex ( ) ; if ( commitIndex > snapshot . index ( ) ) { logger . info ( "Ignored stale " + snapshot + ", commit index at: " + commitIndex ) ; return false ; } else if ( commitIndex == snapshot . index ( ) ) { logger . info ( "Ignored " + snapshot + " since commit index is same." ) ; return true ; } state . commitIndex ( snapshot . index ( ) ) ; int truncated = state . log ( ) . setSnapshot ( snapshot ) ; if ( truncated > 0 ) { logger . info ( truncated + " entries are truncated to install " + snapshot ) ; } raftIntegration . restoreSnapshot ( snapshot . operation ( ) , snapshot . index ( ) ) ; // If I am installing a snapshot, it means I am still present in the last member list, // but it is possible that the last entry I appended before the snapshot could be a membership change. // Because of this, I need to update my status. // Nevertheless, I may not be present in the restored member list, which is ok. setStatus ( ACTIVE ) ; state . restoreGroupMembers ( snapshot . groupMembersLogIndex ( ) , snapshot . groupMembers ( ) ) ; printMemberState ( ) ; state . lastApplied ( snapshot . index ( ) ) ; invalidateFuturesUntil ( snapshot . index ( ) , new StaleAppendRequestException ( state . leader ( ) ) ) ; logger . info ( snapshot + " is installed." ) ; return true ; }
Restores the snapshot sent by the leader if it s not applied before .