Пример #1
0
        /// <summary>
        /// Opens a <see cref="ValueCheckpointFile"/> from the given file.
        /// The file stream will be disposed when the checkpoint file is disposed.
        /// </summary>
        /// <param name="filename">The file to open that contains an existing checkpoint file.</param>
        /// <param name="traceType">Tracing information.</param>
        public static async Task <ValueCheckpointFile> OpenAsync(string filename, string traceType)
        {
            FabricEvents.Events.ValueCheckpointFileAsyncOpen(traceType, DiskConstants.state_opening, filename);
            Diagnostics.Assert(FabricFile.Exists(filename), traceType, "File name {0} does not exist", filename);

            ValueCheckpointFile checkpointFile = null;

            try
            {
                checkpointFile = new ValueCheckpointFile(filename);
                await checkpointFile.ReadMetadataAsync().ConfigureAwait(false);
            }
            catch (Exception)
            {
                // Ensure the checkpoint file get disposed quickly if we get an exception.
                if (checkpointFile != null)
                {
                    checkpointFile.Dispose();
                }

                throw;
            }

            FabricEvents.Events.ValueCheckpointFileAsyncOpen(traceType, DiskConstants.state_complete, filename);
            return(checkpointFile);
        }
Пример #2
0
        /// <summary>
        /// Opens a TStore checkpoint from the given file name.
        /// </summary>
        /// <param name="filename">The file to open that contains an existing checkpoint.</param>
        /// <param name="traceType">Tracing information.</param>
        /// <param name="isValueReferenceType"></param>
        public static async Task <CheckpointFile> OpenAsync(string filename, string traceType, bool isValueReferenceType)
        {
            KeyCheckpointFile   keyFile   = null;
            ValueCheckpointFile valueFile = null;

            try
            {
                keyFile = await KeyCheckpointFile.OpenAsync(filename + KeyCheckpointFile.FileExtension, traceType, isValueReferenceType).ConfigureAwait(false);

                valueFile = await ValueCheckpointFile.OpenAsync(filename + ValueCheckpointFile.FileExtension, traceType).ConfigureAwait(false);

                return(new CheckpointFile(filename, keyFile, valueFile, traceType));
            }
            catch (Exception)
            {
                // Ensure the key and value files get disposed quickly if we get an exception.
                // Normally the CheckpointFile would dispose them, but it may not get constructed.
                if (keyFile != null)
                {
                    keyFile.Dispose();
                }
                if (valueFile != null)
                {
                    valueFile.Dispose();
                }

                throw;
            }
        }