public void ChangeRole(ReplicaRole newRole) { //// AppTrace.TraceMsg(TraceLogEventType.Information, "OperationFetcher.ChangeRole", "ChangeRole from {0} to {1}", this.role, newRole); //// what are the state transistions possible? ReplicaRole oldRole = this.role; this.role = newRole; if (oldRole == ReplicaRole.None && newRole == ReplicaRole.IdleSecondary) { if (this.drainQueuesInParallel) { OperationFetcher.DrainQueueAsyncHelper(this.copyOperationQueue); OperationFetcher.DrainQueueAsyncHelper(this.replicationOperationQueue); } else { OperationFetcher.DrainQueueAsyncHelper(this.copyOperationQueue).ContinueWith(copyQueueDrainTask => { //// AppTrace.TraceMsg(TraceLogEventType.Verbose, "OperationFetcher.QueueDrain", "Starting replication queue"); if (this.role == ReplicaRole.None) { //// AppTrace.TraceMsg(TraceLogEventType.Information, "OperationFetcher.QueueDrain", "ReplicaRole is None so not draining replication queue"); return; } OperationFetcher.DrainQueueAsyncHelper(this.replicationOperationQueue); }); } } else if (oldRole == ReplicaRole.IdleSecondary && newRole == ReplicaRole.ActiveSecondary) { // No-Op } else if (oldRole == ReplicaRole.ActiveSecondary && newRole == ReplicaRole.Primary) { // No-Op } else if (oldRole == ReplicaRole.Primary && newRole == ReplicaRole.ActiveSecondary) { OperationFetcher.DrainQueueAsyncHelper(this.replicationOperationQueue); } else if (oldRole == ReplicaRole.None && newRole == ReplicaRole.Primary) { // No-op } else if (newRole == ReplicaRole.None) { // No-Op } else { // AppTrace.TraceMsg(TraceLogEventType.Error, "OperationFetcher.ChangeRole", "Invalid state change"); ReleaseAssert.Failfast(string.Format(CultureInfo.InvariantCulture, "Invalid State Change from {0} to {1}", oldRole, newRole)); } }
public Instance(bool drainInParallel = false) { this.DrainInParallel = drainInParallel; this.ReplicationQueue = new TQueue() { Name = "Replication" }; this.CopyQueue = new TQueue() { Name = "Copy" }; this.Fetcher = new OperationFetcher(this.CopyQueue, this.ReplicationQueue, this.DrainInParallel); }
private static Task DrainQueueAsyncHelper(IOperationQueue queue) { return(queue.DrainAsync().ContinueWith(t => OperationFetcher.LogQueueDrainCompletion(t, queue.Name), TaskContinuationOptions.ExecuteSynchronously)); }