public static ReplicationProgress CreateActive(HostStatus master, params HostStatus[] slaves) { if (master == null) { throw new ArgumentNullException(nameof(master)); } if (slaves == null) { throw new ArgumentNullException(nameof(slaves)); } if (slaves.Length == 0) { throw new ArgumentException("Value cannot be an empty collection.", nameof(slaves)); } ReplicationProgress instance = new ReplicationProgress(); instance.IsActive = true; instance.Master = master; instance.Slaves = slaves; instance.InSync = slaves.All(item => item.Offset == master.Offset); return(instance); }
public static IEnumerable <string> GenerateProgress(this ReplicationProgress progress) { if (progress.Slaves == null) { yield break; } foreach (var progressSlave in progress.Slaves) { yield return($"Replication progress from [{progress.Master.EndPoint}] to [{progressSlave.EndPoint}] Progress - {progressSlave.Offset / (double)progress.Master.Offset * 100:F2}%"); } }
private void Track(ReplicationProgress progress) { if (progress == null) { return; } foreach (var record in progress.GenerateProgress()) { logging(record); } }
private ReplicationProgress TimerEvent(long timer) { if (master == null || !master.IsActive) { return(ReplicationProgress.CreateInActive()); } var info = master.GetInfo(ReplicationInfo.Name).ToArray(); if (info.Length != 1) { string message = "Do not support zero or multiple masters replication: " + info.Length; log.LogError(message); throw new InvalidOperationException(message); } var information = info[0]; var masterOffset = information.Replication.MasterReplOffset; if (information.Replication.Role != ReplicationRole.Master || masterOffset == null || information.Replication.Slaves == null || information.Replication.Slaves.Length < slave.GetServers().Count()) { log.LogDebug("Replication - Inactive"); return(ReplicationProgress.CreateInActive()); } var slaves = GetSlaveInformation(information); log.LogDebug("Replication - Active"); return(ReplicationProgress.CreateActive( new HostStatus(masterEndPoint, masterOffset.Value), slaves.ToArray())); }
public static ReplicationProgress CreateInActive() { ReplicationProgress instance = new ReplicationProgress(); return(instance); }