boolean replacePendingCheckpointById ( AbstractCheckpointStats completedOrFailed ) { checkArgument ( ! completedOrFailed . getStatus ( ) . isInProgress ( ) , "Not allowed to replace with in progress checkpoints." ) ; if ( readOnly ) { throw new UnsupportedOperationException ( "Can't create a snapshot of a read-only history." ) ; } // Update the latest checkpoint stats if ( completedOrFailed . getStatus ( ) . isCompleted ( ) ) { CompletedCheckpointStats completed = ( CompletedCheckpointStats ) completedOrFailed ; if ( completed . getProperties ( ) . isSavepoint ( ) && ( latestSavepoint == null || completed . getCheckpointId ( ) > latestSavepoint . getCheckpointId ( ) ) ) { latestSavepoint = completed ; } else if ( latestCompletedCheckpoint == null || completed . getCheckpointId ( ) > latestCompletedCheckpoint . getCheckpointId ( ) ) { latestCompletedCheckpoint = completed ; } } else if ( completedOrFailed . getStatus ( ) . isFailed ( ) ) { FailedCheckpointStats failed = ( FailedCheckpointStats ) completedOrFailed ; if ( latestFailedCheckpoint == null || failed . getCheckpointId ( ) > latestFailedCheckpoint . getCheckpointId ( ) ) { latestFailedCheckpoint = failed ; } } if ( maxSize == 0 ) { return false ; } long checkpointId = completedOrFailed . getCheckpointId ( ) ; // We start searching from the last inserted position. Since the entries // wrap around the array we search until we are at index 0 and then from // the end of the array until (start pos + 1). int startPos = nextPos == checkpointsArray . length ? checkpointsArray . length - 1 : nextPos - 1 ; for ( int i = startPos ; i >= 0 ; i -- ) { if ( checkpointsArray [ i ] . getCheckpointId ( ) == checkpointId ) { checkpointsArray [ i ] = completedOrFailed ; return true ; } } for ( int i = checkpointsArray . length - 1 ; i > startPos ; i -- ) { if ( checkpointsArray [ i ] . getCheckpointId ( ) == checkpointId ) { checkpointsArray [ i ] = completedOrFailed ; return true ; } } return false ; }
Searches for the in progress checkpoint with the given ID and replaces it with the given completed or failed checkpoint .