Ejemplo n.º 1
0
        public Server GetServerForKey(String key)
        {
            Server serverHoldingKey;

            if (this.hashRing.Count == 0)
            {
                return(null);
            }

            uint hashKey = FnvHash.To32BitFnvHash(key);

            if (this.hashRing.ContainsKey(hashKey))
            {
                serverHoldingKey = this.hashRing[hashKey];
            }
            else
            {
                uint[] sortedKeys = this.hashRing.Keys.ToArray();

                uint firstServerKey = sortedKeys.FirstOrDefault(x => x >= hashKey);

                serverHoldingKey = this.hashRing[firstServerKey];
            }
            return(serverHoldingKey);
        }
Ejemplo n.º 2
0
 private void RemoveServerFromRing(Server server)
 {
     for (int i = 0; i < numberOfReplicas; i++)
     {
         string serverIdentity = String.Concat(server.IpAddress, ":", i);
         uint   hashKey        = FnvHash.To32BitFnvHash(serverIdentity);
         this.hashRing.Remove(hashKey);
     }
 }