예제 #1
0
        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);
        }
예제 #2
0
        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}%");
            }
        }
예제 #3
0
        private void Track(ReplicationProgress progress)
        {
            if (progress == null)
            {
                return;
            }

            foreach (var record in progress.GenerateProgress())
            {
                logging(record);
            }
        }
예제 #4
0
        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()));
        }
예제 #5
0
        public static ReplicationProgress CreateInActive()
        {
            ReplicationProgress instance = new ReplicationProgress();

            return(instance);
        }