Example #1
0
        // notify thread entrance
        public void NotifyInstanceSubjectiveDown(Guid uuid, string addr)
        {
            RedisInstanceBase ins = null;

            if (!redisInstancesDict.TryGetValue(addr, out ins))
            {
                return;
            }

            if (Program.amqpAdaptor.Uuid.Equals(uuid))
            {
                //Console.WriteLine("NotifyWatchingMaster ingnore self");
                return;
            }

            Watcher watcher = null;

            lock (watchersDict)
            {
                if (!watchersDict.TryGetValue(uuid, out watcher))
                {
                    watcher = watchersDict[uuid] = new Watcher()
                    {
                        Uuid = uuid,
                    };
                }
            }

            Console.WriteLine("NotifyInstanceSubjectiveDown {0} => {1}", uuid, addr);

            lock (watcher.SubjectiveDownSet)
            {
                watcher.SubjectiveDownSet.Add(addr);
            }
        }
 public virtual void CopyFrom(RedisInstanceBase ins)
 {
     Server   = ins.Server;
     Name     = ins.Name;
     Group    = ins.Group;
     EndPoint = ins.EndPoint;
     RunId    = ins.RunId;
     State    = ins.State;
     LastPing = ins.LastPing;
     Ping     = ins.Ping;
 }
 public virtual void CopyFrom(RedisInstanceBase ins)
 {
     Server = ins.Server;
     Name = ins.Name;
     Group = ins.Group;
     EndPoint = ins.EndPoint;
     RunId = ins.RunId;
     State = ins.State;
     LastPing = ins.LastPing;
     Ping = ins.Ping;
 }
Example #4
0
        private void MuxerInstanceOnConnectionRestored(object sender, ConnectionFailedEventArgs connectionFailedEventArgs)
        {
            var epStr             = connectionFailedEventArgs.EndPoint.ToString();
            RedisInstanceBase ins = null;

            if (!redisInstancesDict.TryGetValue(epStr, out ins))
            {
                return;
            }

            var master = ins as MasterInstance;

            if (master == null)
            {
                return;
            }

            if (ins.Group.Master != ins && Program.zkAdaptor.IsLeader(epStr))
            {
                Console.WriteLine("down {0} to slave of {1}", ins.EndPoint, ins.Group.Master.EndPoint);
                ins.Server.SlaveOf(ins.Group.Master.EndPoint);
                MasterToSlave(master);
            }
        }
Example #5
0
        // every 10s
        private async Task RefreshAllMasters()
        {
            var masters         = groups.Values.Select(g => g.Master);
            var toConnectSlaves = new List <RedisInstanceBase>();

            foreach (var master in masters)
            {
                try
                {
                    if (!master.Server.IsConnected)
                    {
                        continue;
                    }

                    if (master.Server.IsSlave)
                    {
                        Console.WriteLine("master {0} state hasn't been sync, still slave", master.EndPoint);
                        //todo
                        continue;
                    }

                    var val = await master.Server.InfoAsync();

                    foreach (var group in val)
                    {
                        if (group.Key.Equals("Replication"))
                        {
                            var slavesNum = int.Parse(group.First(kv => kv.Key.Equals("connected_slaves")).Value);
                            for (int i = 0; i < slavesNum; i++)
                            {
                                var slaveId   = string.Format("slave{0}", i);
                                var slaveInfo = group.First(kv => kv.Key.Equals(slaveId)).Value;
                                var infos     = slaveInfo.Split(',');

                                var ip = infos[0].Split('=')[1];
                                if (ip.Equals("127.0.0.1"))
                                {
                                    ip = master.EndPoint.ToString().Split(':')[0];
                                }

                                var ep = new IPEndPoint(IPAddress.Parse(ip),
                                                        int.Parse(infos[1].Split('=')[1]));
                                var epStr = ep.ToString();

                                RedisInstanceBase ins = null;
                                if (!redisInstancesDict.TryGetValue(epStr, out ins))
                                {
                                    ins = redisInstancesDict[epStr] = new SlaveInstance(master.Group);
                                    toConnectSlaves.Add(ins);
                                }

                                var slaveIns = ins as SlaveInstance;

                                if (slaveIns == null)
                                {
                                    Console.WriteLine("slave {0} state hasn't been sync, still master", ins.EndPoint);
                                    continue;
                                }

                                slaveIns.OnMasterInfoRefresh(ep, slaveInfo);
                                master.Group.AddSlave(slaveIns);
                            }
                        }
                        else if (group.Key.Equals("Server"))
                        {
                            var runId = group.First(kv => kv.Key.Equals("run_id")).Value;

                            master.RunId = runId;
                        }
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            }

            if (toConnectSlaves.Count > 0)
            {
                ReconfigureConnection(toConnectSlaves);
            }
        }