예제 #1
0
        public static void SafeFileReplace(string currentFilePath, string newFilePath, string backupFilePath, string traceType)
        {
            if (FabricFile.Exists(backupFilePath))
            {
                FabricFile.Delete(backupFilePath);
            }
            if (FabricFile.Exists(backupFilePath))
            {
                TestableAssertHelper.FailInvalidData(traceType, "CheckpointFileHelper.SafeFileReplace", "!FabricFile.Exists(backupFilePath) : {0}", backupFilePath);
            }

            // Previous replace could have failed in the middle before the next metadata table file got renamed to current.
            if (!FabricFile.Exists(currentFilePath))
            {
                FabricFile.Move(newFilePath, currentFilePath);
            }
            else
            {
                FabricFile.Replace(newFilePath, currentFilePath, backupFilePath, ignoreMetadataErrors: false);
            }

            if (FabricFile.Exists(backupFilePath))
            {
                FabricFile.Delete(backupFilePath);
            }
            if (FabricFile.Exists(backupFilePath))
            {
                TestableAssertHelper.FailInvalidData(traceType, "CheckpointFileHelper.SafeFileReplace", "!FabricFile.Exists(backupFilePath) : {0}", backupFilePath);
            }
        }
예제 #2
0
        /// <summary>
        /// Drain all the dequeuers.
        /// Would be called during ChangeRole (to S, None), Abort, Close.
        /// </summary>
        /// <param name="cause">The DrainCause</param>
        private void DrainDequeuers(DequeuerState cause)
        {
            TaskCompletionSource <ConditionalValue <IListElement <T> > > tcs;
            Exception exc = null;

            switch (cause)
            {
            case DequeuerState.Aborting:
            case DequeuerState.Closing:
                exc = new FabricObjectClosedException(string.Format("Dequeue was canceled as the queue is {0}. Please dispose the current transaction and retry the operation with a new transaction.", cause));
                break;

            case DequeuerState.ChangeRoleFromPrimary:
                exc = new FabricNotPrimaryException("Dequeue was canceled as the role is no longer primary. Please dispose the current transaction and retry the operation with a new transaction.");
                break;

            default:
                TestableAssertHelper.FailInvalidData(
                    this.traceType,
                    "DataStore.DrainDequeuers",
                    "DequeueScheduler.DrainDequeuers : Invalid DrainQueue cause : {0}",
                    cause);
                break;     // unreachable
            }

            lock (this.updateLatch)
            {
                this.dequeuersState = cause;
            }

            while (this.dequeuerQueue.TryDequeue(out tcs))
            {
                tcs.TrySetException(exc);
            }
        }
예제 #3
0
 public async Task ReadAsync()
 {
     if (this.ListElements != null)
     {
         TestableAssertHelper.FailInvalidData(this.traceType, "Checkpoint.ReadAsync", "this.ListElements == null");
     }
     this.ListElements = await this.ReadListElementsAsync().ConfigureAwait(false);
 }
예제 #4
0
        public static bool TryDeleteCopyFile(string directory, string traceType)
        {
            var filePath = GetCopyFilePath(directory);

            if (!FabricFile.Exists(filePath))
            {
                return(false);
            }

            FabricFile.Delete(filePath);
            if (FabricFile.Exists(filePath))
            {
                TestableAssertHelper.FailInvalidData(traceType, "CheckpointFileHelper.TryDeleteCopyFile", "!FabricFile.Exists(filePath).  filePath: {0}", filePath);
            }
            return(true);
        }
예제 #5
0
        private async Task VerifyAsync()
        {
            // Read from disk to verify
            var res = await TryReadCheckpointFile(this.directory, this.FileName, this.valueSerializer, this.traceType).ConfigureAwait(false);

            if (!res.HasValue)
            {
                throw new InvalidDataException(string.Format("Checkpoint file '{0}' not found.", Path.Combine(this.directory, this.FileName)));
            }

            if ((this.CurrentCheckpoint == null) != (res.Value.CurrentCheckpoint == null))
            {
                TestableAssertHelper.FailInvalidData(
                    this.traceType,
                    "CheckpointManager.VerifyAsync",
                    "Disagreement on checkpoint existing.  In-Memory: {0}  On-Disk: {1}",
                    this.CurrentCheckpoint != null ? this.CurrentCheckpoint.FilePath : "null",
                    res.Value.CurrentCheckpoint != null ? res.Value.CurrentCheckpoint.FilePath : "null");
            }

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