예제 #1
0
        /// <summary>
        /// 单个节点
        /// </summary>
        /// <param name="node"></param>
        public void AddNode(StoreNode node)
        {
            resetEvent.Reset();
            List <ulong> lst = new List <ulong>();

            for (int i = 0; i < numReps; i++)
            {
                //getKeyForNode方法为这组虚拟结点得到惟一名称
                /** 是一个16字节长度的数组,将16字节的数组每四个字节一组,分别对应一个虚拟结点,这就是为什么上面把虚拟结点四个划分一组的原因*/
                try
                {
                    byte[] digest = MurmurHashFactory.ComputeMurmur(node.ToString() + i);
                    ulong  key    = MurmurHashFactory.Hash(digest);
                    ketamaNodes.Add(key, node);
                }
                catch (RedBlackException ex)
                {
                    if (ex.Error == ReadBlackCode.KeyExists)
                    {
                        foreach (ulong key in lst)
                        {
                            try
                            {
                                ketamaNodes.Remove(key);
                            }
                            catch
                            {
                            }
                        }
                    }
                    i--;
                }
            }
            resetEvent.Set();
        }
예제 #2
0
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return(false);
            }
            if ((obj.GetType().Equals(this.GetType())) == false)
            {
                return(false);
            }
            StoreNode temp = null;

            temp = (StoreNode)obj;

            return(this.ToString().Equals(temp.ToString()));
        }