Beispiel #1
0
        /// <summary>
        /// Create a new <see cref="RecoveryPointMetadataFile"/> and write it to the given file.
        /// </summary>
        /// <returns>Task that represents the asynchronous operation.</returns>
        public static async Task <RecoveryPointMetadataFile> CreateAsync(
            string fileName,
            DateTime backupTime,
            Guid backupId,
            Guid parentBackupId,
            Guid backupChainId,
            Epoch epochOfLastBackupRecord,
            long lsnOfLastBackupRecord,
            string backupLocation,
            string parentBackupLocation,
            ServicePartitionInformation partitionInformation,
            string serviceManifestVersion,
            CancellationToken cancellationToken)
        {
            // Create the file with asynchronous flag and 4096 cache size (C# default).
            using (var filestream = FabricFile.Open(
                       fileName,
                       FileMode.CreateNew,
                       FileAccess.Write,
                       FileShare.Read,
                       4096,
                       FileOptions.Asynchronous))
            {
                BackupRestoreUtility.SetIoPriorityHint(filestream.SafeFileHandle, Kernel32Types.PRIORITY_HINT.IoPriorityHintLow);

                var recoveryPointMetadataFile = new RecoveryPointMetadataFile(fileName);
                recoveryPointMetadataFile.properties = new RecoveryPointMetadataFileProperties
                {
                    BackupTime              = backupTime,
                    BackupLocation          = backupLocation,
                    ParentBackupLocation    = parentBackupLocation,
                    BackupId                = backupId,
                    ParentBackupId          = parentBackupId,
                    BackupChainId           = backupChainId,
                    EpochOfLastBackupRecord = epochOfLastBackupRecord,
                    LsnOfLastBackupRecord   = lsnOfLastBackupRecord,
                    PartitionInformation    = partitionInformation,
                    ServiceManifestVersion  = serviceManifestVersion,
                };

                // Write the properties.
                var propertiesHandle =
                    await FileBlock.WriteBlockAsync(filestream, writer => recoveryPointMetadataFile.properties.Write(writer)).ConfigureAwait(false);

                cancellationToken.ThrowIfCancellationRequested();

                // Write the footer.
                recoveryPointMetadataFile.footer = new FileFooter(propertiesHandle, Version);
                await FileBlock.WriteBlockAsync(filestream, writer => recoveryPointMetadataFile.footer.Write(writer)).ConfigureAwait(false);

                cancellationToken.ThrowIfCancellationRequested();

                // Flush to underlying stream.
                await filestream.FlushAsync(cancellationToken).ConfigureAwait(false);

                return(recoveryPointMetadataFile);
            }
        }