internal protected void EnableWriteOnReplicas(string viewName, string headStorageAccountName) { // Assert (headStorageAccountName != null) if (!ReplicaChain.Any() || ReplicaChain[0].StorageAccountName != headStorageAccountName) { return; } // First, enable Write on all replicas foreach (ReplicaInfo replica in GetCurrentReplicaChain()) { replica.Status = ReplicaStatus.ReadWrite; } // Then, set the head to WriteOnly ReplicaChain[0].Status = ReplicaStatus.WriteOnly; // one replica chain ? Force to ReadWrite if (GetCurrentReplicaChain().Count == 1) { ReplicaChain[0].Status = ReplicaStatus.ReadWrite; } // Update view id ViewId++; }
internal protected void MoveReplicaToHeadAndSetViewToReadOnly(string viewName, string storageAccountName) { // Assert (storageAccountName != null) int matchIndex = ReplicaChain.FindIndex(r => r.StorageAccountName == storageAccountName); if (matchIndex == -1) { return; } // - Ensure its status is *None* ReplicaInfo candidateReplica = ReplicaChain[matchIndex]; var oldStatus = candidateReplica.Status; candidateReplica.Status = ReplicaStatus.None; // First check it will be possible to modify the sequence foreach (ReplicaInfo replica in GetCurrentReplicaChain()) { // Change is not possible if (replica.Status == ReplicaStatus.WriteOnly) { // Restore previous status candidateReplica.Status = oldStatus; var msg = string.Format("View:\'{0}\' : can't set a WriteOnly replica to ReadOnly !!!", viewName); ReplicatedTableLogger.LogError(msg); throw new Exception(msg); } } // Do the change ... // - Move it to the front of the chain ReplicaChain.RemoveAt(matchIndex); ReplicaChain.Insert(0, candidateReplica); // Set all active replicas to *ReadOnly* foreach (ReplicaInfo replica in GetCurrentReplicaChain()) { replica.Status = ReplicaStatus.ReadOnly; } // Update view id ViewId++; // Reset 'ReadViewTailIndex' => user has to set it again ResetReadViewTailIndex(); }
internal protected void EnableReadWriteOnReplica(string viewName, string headStorageAccountName) { if (!ReplicaChain.Any() || ReplicaChain[0].StorageAccountName != headStorageAccountName || ReplicaChain[0].Status != ReplicaStatus.WriteOnly) { return; } ReplicaChain[0].Status = ReplicaStatus.ReadWrite; // Update view id ViewId++; }
internal protected void MoveReplicaToHeadAndSetViewToReadOnly(string viewName, string storageAccountName) { // Assert (storageAccountName != null) int matchIndex = ReplicaChain.FindIndex(r => r.StorageAccountName == storageAccountName); if (matchIndex == -1) { return; } // - Ensure its status is *None* ReplicaInfo candidateReplica = ReplicaChain[matchIndex]; candidateReplica.Status = ReplicaStatus.None; // - Move it to the front of the chain ReplicaChain.RemoveAt(matchIndex); ReplicaChain.Insert(0, candidateReplica); // Set all active replicas to *ReadOnly* foreach (ReplicaInfo replica in GetCurrentReplicaChain()) { if (replica.Status == ReplicaStatus.WriteOnly) { var msg = string.Format("View:\'{0}\' : can't set a WriteOnly replica to ReadOnly !!!", viewName); ReplicatedTableLogger.LogError(msg); throw new Exception(msg); } replica.Status = ReplicaStatus.ReadOnly; } // Update view id ViewId++; }
/// <summary> /// List of active Replicas i.e. RO / WO / RW /// </summary> /// <returns></returns> public List <ReplicaInfo> GetCurrentReplicaChain() { return(ReplicaChain.Where(r => r.Status != ReplicaStatus.None).ToList()); }