Esempio n. 1
0
        public ReplicationInfo(IServerInformation main)
            : base(main, Name)
        {
            if (main == null)
            {
                throw new ArgumentNullException(nameof(main));
            }

            Role = GetType <ReplicationRole>("role");
            if (Role == ReplicationRole.Slave)
            {
                LastSync               = GetType <long>("master_last_io_seconds_ago");
                MasterLinkStatus       = GetType <MasterLinkStatus>("master_link_status");
                SlaveReplOffset        = GetType <long>("slave_repl_offset");
                IsMasterSyncInProgress = GetType <byte>("master_sync_in_progress");
            }
            else if (Role == ReplicationRole.Master)
            {
                MasterReplOffset = GetType <long>("master_repl_offset");
                ConnectedSlaves  = GetType <int>("connected_slaves");
                if (ConnectedSlaves != null)
                {
                    Slaves = new SlaveInformation[ConnectedSlaves.Value];
                    for (int i = 0; i < ConnectedSlaves.Value; i++)
                    {
                        Slaves[i] = SlaveInformation.Parse(GetType($"slave{i}"));
                    }
                }
            }
        }
Esempio n. 2
0
        public static SlaveInformation Parse(string line)
        {
            if (string.IsNullOrEmpty(line))
            {
                throw new ArgumentException("Value cannot be null or empty.", nameof(line));
            }

            var blocks = line.Split(',').Select(item => item.Split('='))
                         .ToDictionary(item => item[0], item => item[1], StringComparer.OrdinalIgnoreCase);

            if (blocks.Count < 5)
            {
                throw new ArgumentOutOfRangeException(nameof(line), "Invalid information: " + line);
            }

            SlaveInformation information = new SlaveInformation();

            information.EndPoint = new IPEndPoint(IPAddress.Parse(blocks["ip"]), int.Parse(blocks["port"]));
            information.State    = blocks["state"];
            information.Offset   = long.Parse(blocks["offset"]);
            information.Lag      = int.Parse(blocks["lag"]);
            return(information);
        }