This is a ketama-like consistent hashing based node locator. Used when no other T:IMemcachedNodeLocator is specified for the pool.
Inheritance: IMemcachedNodeLocator
Beispiel #1
0
        void BuildIndex(List <IMemcachedNode> nodes)
        {
            var keys      = new uint[nodes.Count * DefaultNodeLocator.ServerAddressMutations];
            var nodeIndex = 0;

            foreach (var node in nodes)
            {
                var tempKeys = DefaultNodeLocator.GenerateKeys(node, DefaultNodeLocator.ServerAddressMutations);
                for (var index = 0; index < tempKeys.Length; index++)
                {
                    this._servers[tempKeys[index]] = node;
                }
                tempKeys.CopyTo(keys, nodeIndex);
                nodeIndex += DefaultNodeLocator.ServerAddressMutations;
            }

            Array.Sort <uint>(keys);
            Interlocked.Exchange(ref this._keys, keys);
        }
        private void BuildIndex(List <IMemcachedNode> nodes)
        {
            var keys = new uint[nodes.Count * DefaultNodeLocator.ServerAddressMutations];

            int nodeIdx = 0;

            foreach (IMemcachedNode node in nodes)
            {
                var tmpKeys = DefaultNodeLocator.GenerateKeys(node, DefaultNodeLocator.ServerAddressMutations);

                for (var i = 0; i < tmpKeys.Length; i++)
                {
                    this.servers[tmpKeys[i]] = node;
                }

                tmpKeys.CopyTo(keys, nodeIdx);
                nodeIdx += DefaultNodeLocator.ServerAddressMutations;
            }

            Array.Sort <uint>(keys);
            Interlocked.Exchange(ref this.keys, keys);
        }
Beispiel #3
0
        void IMemcachedNodeLocator.Initialize(IList <MemcachedNode> nodes)
        {
            if (this.isInitialized)
            {
                throw new InvalidOperationException("Instance is already initialized.");
            }

            // locking on this is rude but easy
            lock (this)
            {
                if (this.isInitialized)
                {
                    throw new InvalidOperationException("Instance is already initialized.");
                }

                this.keys = new uint[nodes.Count * DefaultNodeLocator.ServerAddressMutations];

                int nodeIdx = 0;

                foreach (MemcachedNode node in nodes)
                {
                    List <uint> tmpKeys = DefaultNodeLocator.GenerateKeys(node, DefaultNodeLocator.ServerAddressMutations);

                    tmpKeys.ForEach(delegate(uint k)
                    {
                        this.servers[k] = node;
                    });

                    tmpKeys.CopyTo(this.keys, nodeIdx);
                    nodeIdx += DefaultNodeLocator.ServerAddressMutations;
                }

                Array.Sort <uint>(this.keys);

                this.isInitialized = true;
            }
        }