/// <summary> /// Creates a checkpoint for a given sequence point. /// </summary> public Task <BoolResult> CreateCheckpointAsync(OperationContext context, EventSequencePoint sequencePoint) { context = context.CreateNested(); string checkpointId = "Unknown"; long checkpointSize = 0; return(context.PerformOperationAsync( _tracer, async() => { bool successfullyUpdatedIncrementalState = false; try { // Creating a working temporary directory using (new DisposableDirectory(_fileSystem, _checkpointStagingDirectory)) { // NOTE(jubayard): this needs to be done previous to checkpointing, because we always // fetch the latest version's size in this way. This implies there may be some difference // between the reported value and the actual size on disk: updates will get in in-between. // The better alternative is to actually open the checkpoint and ask, but it seems like too // much. checkpointSize = _database.GetContentDatabaseSizeBytes().GetValueOrDefault(-1); // Saving checkpoint for the database into the temporary folder _database.SaveCheckpoint(context, _checkpointStagingDirectory).ThrowIfFailure(); if (_configuration.UseIncrementalCheckpointing) { checkpointId = await CreateCheckpointIncrementalAsync(context, sequencePoint); successfullyUpdatedIncrementalState = true; } else { checkpointId = await CreateFullCheckpointAsync(context, sequencePoint); } return BoolResult.Success; } } finally { ClearIncrementalCheckpointStateIfNeeded(context, successfullyUpdatedIncrementalState); } }, extraStartMessage: $"SequencePoint=[{sequencePoint}]", extraEndMessage: result => $"SequencePoint=[{sequencePoint}] Id=[{checkpointId}] SizeMb=[{(checkpointSize < 0 ? checkpointSize:checkpointSize*1e-6)}]")); }