public void Can_JoinElectionByUseTheSameZKConnection()
        {
            IZooKeeper zookeeper = new ZooKeeper("127.0.0.1:2181", new TimeSpan(0, 60, 0), null);
            Server     server1   = new Server()
            {
                ShardName = "shard1",
                Host      = "127.0.0.1",
                Port      = 6369,
                paramStr  = "allowAdmin=true",
                Path      = ZkPath.ShardsPath(ZkPath.CollectionName)
            };
            Server server2 = new Server()
            {
                ShardName = "shard1",
                Host      = "127.0.0.1",
                Port      = 6379,
                paramStr  = "allowAdmin=true",
                Path      = ZkPath.ShardsPath(ZkPath.CollectionName)
            };

            ServerInstances si = new ServerInstances();

            si.Add(new ServerInst(server1.Host, server1.Port, "allowAdmin=true"));
            si.Add(new ServerInst(server2.Host, server2.Port, "allowAdmin=true"));

            LeaderContext context1 = new LeaderContext(zookeeper, server1);

            context1.JoinElection();
            LeaderContext context2 = new LeaderContext(zookeeper, server2);

            context2.JoinElection();
        }
Beispiel #2
0
        public void RegistryZk(Guid id)
        {
            log.Info("registry on Zk,id=" + id);
            ServerInst inst = serverInstances.GetById(id);

            if (inst != null)
            {
                log.Info(inst);
                ShardBuilder builder = new ShardBuilder();
                Shard        shard   = builder.AddServer(inst.ServerInfo).Build();
                //多次对每个server初始化有没有问题?
                LeaderContext leaderContext = new LeaderContext(zookeeper, inst.ServerInfo);
                leaderContext.JoinElection();
            }
        }