public void Init() { 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 = "shard2", Host = "127.0.0.1", Port = 6379, paramStr = "allowAdmin=true", Path = ZkPath.ShardsPath(ZkPath.CollectionName) }; ShardBuilder builder1 = new ShardBuilder(); Shard shard1 = builder1.Name("shard1").AddServer(server1).State(LiveState.ACTIVE).Build(); ShardBuilder builder2 = new ShardBuilder(); Shard shard2 = builder2.Name("shard2").AddServer(server2).State(LiveState.ACTIVE).Build(); ShardBuilder builder3 = new ShardBuilder(); Shard shard3 = builder3.Name("shard3").State(LiveState.ACTIVE).Build(); Dictionary <String, Shard> shards = new Dictionary <String, Shard>(); shards.Add("shard1", shard1); shards.Add("shard2", shard2); shards.Add("shard3", shard3); ccl = new CacheCollection("testCol", shards, Router.DEFAULT); }
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(); } }