public DataServerStruct(Address addr, int weight, SystemInfo info) { this.addr = addr; this.weight = weight; this.info = info; this.regions = new HashSet<Region>(); }
public void AddMasterAddr(Address addr) { masterAddrs.Add(addr); }
public void addRegion(Region region, Address addr) { map.Add(region, addr); regions.Add(region); sorted = false; }
public KVClient(ClientOption option) { this.option = option; this.connections = new Dictionary<Address, Socket>(); activeMaster = null; }
protected Socket getMasterConnection() { Socket socket = null; if (activeMaster != null) { try { socket = getConnection(activeMaster); } catch (Exception e) { Console.Error.WriteLine("Fail to connect to master " + activeMaster); } } if (socket == null) { ICollection<Address> masters = option.MasterAddrs; foreach (Address master in masters) { try { socket = getConnection(master); if (socket != null) { activeMaster = master; return socket; } } catch (Exception e) { Console.Error.WriteLine("Fail to connect to master " + activeMaster + " try next"); } } } if (socket != null) { return socket; } else { throw new KVException( "No active master found in cluster, please check the configuration."); } }
protected Socket getConnection(Address addr) { Socket socket = null; connections.TryGetValue(addr, out socket); if (socket == null || !socket.Connected) { socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); socket.Connect(new IPEndPoint(IPAddress.Parse(addr.Ip), addr.Port)); connections.Add(addr, socket); } return socket; }