Beispiel #1
0
        public async Task <bool> WriteNextAsync(OperationData operationData)
        {
            if (this.isDisposed)
            {
                throw new FabricObjectClosedException();
            }

            if (operationData == null)
            {
                throw new ArgumentNullException("operationData");
            }

            if (operationData.Count != 1)
            {
                throw new ArgumentException(string.Format("Unexpected operationData count: {0}", operationData.Count));
            }

            ArraySegment <byte> dataSegment;

            using (var enumerator = operationData.GetEnumerator())
            {
                bool res = enumerator.MoveNext();
                if (!res)
                {
                    throw new InvalidDataException("operationData enumeration is empty");
                }

                dataSegment = enumerator.Current;
            }

            if (dataSegment.Count <= 0)
            {
                throw new ArgumentException("Empty operationData data segment.");
            }

            // the first chunk should contain only metadata (the version), so at least one chunk will follow
            if (this.isFirstChunk)
            {
                this.isFirstChunk = false;
                await this.fileStream.WriteAsync(dataSegment.Array, dataSegment.Offset, dataSegment.Count).ConfigureAwait(false);

                return(false);
            }

            // subsequent chunks should be checkpoint frames
            return(await CheckpointFileHelper.WriteFrameAsync(dataSegment, this.fileStream, this.traceType).ConfigureAwait(false));

            // todo: trace
        }
        public async Task ReplaceCurrentAsync()
        {
            if (this.FileName != NewCheckpointManagerFileName)
            {
                TestableAssertHelper.FailInvalidOperation(
                    this.traceType,
                    "CheckpointManager.ReplaceCurrentAsync",
                    "this.FileName == NewCheckpointManagerFileName; expected: {0} actual: {1}",
                    NewCheckpointManagerFileName, this.FileName);
            }

            await this.VerifyAsync().ConfigureAwait(false);

            var currentFilePath = Path.Combine(this.directory, CurrentCheckpointManagerFileName);
            var backupFilePath  = Path.Combine(this.directory, BackupCheckpointManagerFileName);
            var newFilePath     = Path.Combine(this.directory, NewCheckpointManagerFileName);

            CheckpointFileHelper.SafeFileReplace(currentFilePath, newFilePath, backupFilePath, this.traceType);

            this.FileName = CurrentCheckpointManagerFileName;
        }