예제 #1
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()));
        }