示例#1
0
        /// <summary>
        /// Creating a new KetamaServer object based on the server IP:port/weight information passed in.
        /// The new KetamaServer object will get saved to the list of KetamaServer objects called server
        /// </summary>
        /// <param name="serverIP">A server IP:port/weight value</param>
        public void AddServerToServers(string serverIP)
        {
            string       serverRedisName = "redis" + (serverNames.Count() + 1);         //Should resolve to some name like 'redis1' or 'redis2', etc.
            KetamaServer newServer       = new KetamaServer(serverIP, serverRedisName); //Since we're making a new server, we create a new server object. Pass in the serverIP (e.g. '10.10.10.10:1234') and the given redis name (e.g. 'redis1')

            servers.Add(newServer);                                                     //Add that new server to our list of servers

            serverNames.Add(serverRedisName, newServer.serverIP);                       //Setting the server name to redisX (where X is an integer) and having it be associated with the IP address
        }
示例#2
0
        /// <summary>
        /// Creating a new KetamaServer object based on the server IP:port/weight information passed in.
        /// The new KetamaServer object will get saved to the list of KetamaServer objects called server
        /// </summary>
        /// <param name="serverIP">A server IP:port/weight value</param>
        public void AddServerToServers(string serverIP)
        {
            string serverRedisName = "redis" + (serverNames.Count() + 1);             //Should resolve to some name like 'redis1' or 'redis2', etc.
            KetamaServer newServer = new KetamaServer(serverIP, serverRedisName);     //Since we're making a new server, we create a new server object. Pass in the serverIP (e.g. '10.10.10.10:1234') and the given redis name (e.g. 'redis1')

            servers.Add(newServer);                                                   //Add that new server to our list of servers

            serverNames.Add(serverRedisName, newServer.serverIP);                   //Setting the server name to redisX (where X is an integer) and having it be associated with the IP address
        }
示例#3
0
        /// <summary>
        /// Used to remove a KetamaServer object from the collection of KetamaServer objects.
        /// </summary>
        /// <param name="serverIP">A server IP:port/weight value</param>
        public void RemoveServerFromServers(string serverIP)
        {
            KetamaServer serverToRemove = GetKetamaServerByIP(serverIP);

            servers.Remove(serverToRemove);

            string serverName = GetServerNameFromIP(serverIP);

            serverNames.Remove(serverName);
        }
示例#4
0
 /// <summary>
 /// Returns a KetamaServer object depending on the server IP:port/weight string passed ins
 /// <param name="serverName">A server IP:port string (e.g. '10.10.10.10:6245') which should already
 /// be stored in the List of serverInfo objects called servers</param>
 /// <returns>A KetamaServer object from the servers list
 /// If there's no serverInfo object found for that servername, passes back an empty KetamaServer object</returns>
 public KetamaServer GetKetamaServerByIP(string serverIP)
 {
     foreach (KetamaServer server in servers)
     {
         if (server.serverIP == serverIP)
         {
             return server;
         }
     }
     //If we get here, it means that the server wasn't found.
     //We will return a new and empty KetamaServer object instead
     KetamaServer newServer = new KetamaServer();
     return newServer;
 }
示例#5
0
        /// <summary>
        /// Returns a KetamaServer object depending on the server IP:port/weight string passed ins
        /// <param name="serverName">A server IP:port string (e.g. '10.10.10.10:6245') which should already
        /// be stored in the List of serverInfo objects called servers</param>
        /// <returns>A KetamaServer object from the servers list
        /// If there's no serverInfo object found for that servername, passes back an empty KetamaServer object</returns>
        public KetamaServer GetKetamaServerByIP(string serverIP)
        {
            foreach (KetamaServer server in servers)
            {
                if (server.serverIP == serverIP)
                {
                    return(server);
                }
            }
            //If we get here, it means that the server wasn't found.
            //We will return a new and empty KetamaServer object instead
            KetamaServer newServer = new KetamaServer();

            return(newServer);
        }
示例#6
0
        /// <summary>
        /// Where the servers get their names hashed to be placed along the continuum.
        /// How the hashing works: For the first hash, we calculate the hash with the server name (e.g. 'redis1') and the default offset value,
        /// then for subsequent hashes we take the previous hash, use that hash value as the initial offset, and redo the hash.
        /// In other words, for all but the first hash, when calculating a new hash value, the one that came before it is used as the salt.
        /// </summary>
        /// <param name="serverName">A server name to base hashes on</param>
        /// <returns>A List(uint) of hashes for a given KetamaServer object</returns>
        private List <uint> CalculateHashValuesForServer(string serverName)
        {
            KetamaServer server       = ketamaServers.GetServer(serverName);
            List <uint>  listOfHashes = new List <uint>();
            uint         serverHostKeyHash;

            for (int individualReplica = 0; individualReplica < server.factor; individualReplica++)
            {
                if (individualReplica == 0)
                {
                    serverHostKeyHash = hashingAlgorithm.GetHashFromString(server.serverName);
                }
                else
                {
                    serverHostKeyHash = hashingAlgorithm.GetHashFromString(server.serverName, listOfHashes.Last()); //using the last entry in the hash list as the offset for the next hash to come
                }
                listOfHashes.Add(serverHostKeyHash);
            }
            return(listOfHashes);
        }
示例#7
0
        /// <summary>
        /// Where the servers get their names hashed to be placed along the continuum.
        /// How the hashing works: For the first hash, we calculate the hash with the server name (e.g. 'redis1') and the default offset value,
        /// then for subsequent hashes we take the previous hash, use that hash value as the initial offset, and redo the hash.
        /// In other words, for all but the first hash, when calculating a new hash value, the one that came before it is used as the salt.
        /// </summary>
        /// <param name="serverName">A KetamaServer object to get hashed for</param>
        /// <returns>A List(uint) of hashes for a given KetamaServer object</returns>
        private List <uint> CalculateHashValuesForServer(string serverName)
        {
            KetamaServer server       = ketamaServers.GetKetamaServerByName(serverName);
            List <uint>  listOfHashes = new List <uint>();
            uint         serverHostKeyHash;

            for (int individualReplica = 0; individualReplica < server.factor; individualReplica++)
            {
                if (individualReplica == 0)
                {
                    serverHostKeyHash = hashingAlgorithm.GetHashFromString(server.serverIP);
                }
                else
                {
                    serverHostKeyHash = hashingAlgorithm.GetHashFromString(server.serverIP, listOfHashes.Last()); //using the last entry in the hash list as the offset for the next hash to come
                }
                listOfHashes.Add(serverHostKeyHash);                                                              //Decide the best way to do this - whether they should be stored as uint's or uint's
            }

            return(listOfHashes);
        }
示例#8
0
        /// <summary>
        /// Used to remove a KetamaServer object from the collection of KetamaServer objects.
        /// </summary>
        /// <param name="server">A server name we want to remove</param>
        public void RemoveServerFromServers(string server)
        {
            KetamaServer serverToRemove = GetServer(server);

            servers.Remove(serverToRemove);
        }
示例#9
0
        /// <summary>
        /// Creating a new KetamaServer object based on the server IP:port/weight information passed in.
        /// The new KetamaServer object will get saved to the list of KetamaServer objects called server
        /// </summary>
        /// <param name="serverName">The name of the server we're adding</param>
        /// <param name="serverWeight">The weight of the server we're adding</param>
        public void AddServerToServers(string serverName, int serverWeight = 0)
        {
            KetamaServer newServer = new KetamaServer(serverName, serverWeight); //Since we're making a new server, we create a new server object.

            servers.Add(newServer);                                              //Add that new server to our list of servers
        }
示例#10
0
        /// <summary>
        /// Creating a new KetamaServer object based on the server IP:port/weight information passed in.
        /// The new KetamaServer object will get saved to the list of KetamaServer objects called server
        /// </summary>
        /// <param name="serverName">The name of the server we're adding</param>
        /// <param name="serverWeight">The weight of the server we're adding</param>
        public void AddServerToServers(string serverName, int serverWeight = 0)
        {
            KetamaServer newServer = new KetamaServer(serverName, serverWeight); //Since we're making a new server, we create a new server object.

            servers.Add(newServer); //Add that new server to our list of servers
        }