Implements a vbucket based node locator.
Inheritance: IMemcachedNodeLocator
コード例 #1
0
        public SyncOperation(VBucketNodeLocator locator, IList<KeyValuePair<string, ulong>> keys, SyncMode mode, int replicationCount)
        {
            if (keys == null) throw new ArgumentNullException("keys");
            if (keys.Count > 0xffff) throw new ArgumentException("Maximum 0xFFFF items are supported.");

            this.flags = GetFlags(mode, replicationCount);

            this.locator = locator;
            this.keys = keys;
        }
コード例 #2
0
        public SyncOperation(VBucketNodeLocator locator, KeyValuePair<string, ulong>[] keys, SyncMode mode, int replicationCount)
        {
            if (keys == null) throw new ArgumentNullException("keys");
            if (keys.Length > 0xffff) throw new ArgumentException("Only 0xffff items are supported");

            this.flags = GetFlags(mode, replicationCount);

            this.locator = locator;
            this.keys = keys;
        }
コード例 #3
0
        public void TestBuckets()
        {
            var vb = new VBucketNodeLocator("crc", buckets);

            var servers = new[] { "127.0.0.1", "127.0.0.2", "127.0.0.3" };
            var nodes = from s in servers
                        let ip = IPAddress.Parse(s)
                        select (IMemcachedNode)new MockNode(new IPEndPoint(ip, 11211));

            ((IMemcachedNodeLocator)vb).Initialize(nodes.ToList());

            foreach (var kvp in keyToVBucket)
            {
                var b = vb.GetVBucket(kvp.Key);
                var index = Array.IndexOf(buckets, b);

                Assert.IsTrue(index == kvp.Value, "Key '" + kvp.Key + "': expected " + kvp.Value + " but found " + index);
            }
        }
コード例 #4
0
 public TouchOperation(VBucketNodeLocator locator, string key, uint expires)
     : base(key)
 {
     this.locator = locator;
     this.expires = expires;
 }
コード例 #5
0
 public VBucketAwareOperationFactory(VBucketNodeLocator locator)
 {
     this.locator = locator;
 }
コード例 #6
0
 public VBStore(VBucketNodeLocator locator, StoreMode mode, string key, CacheItem value, uint expires)
     : base(mode, key, value, expires)
 {
     this.locator = locator;
 }
コード例 #7
0
 public VBMutator(VBucketNodeLocator locator, MutationMode mode, string key, ulong defaultValue, ulong delta, uint expires)
     : base(mode, key, defaultValue, delta, expires)
 {
     this.locator = locator;
 }
コード例 #8
0
 public VBMget(VBucketNodeLocator locator, IList<string> keys)
     : base(keys)
 {
     this.locator = locator;
 }
コード例 #9
0
 public VBGet(VBucketNodeLocator locator, string key)
     : base(key)
 {
     this.locator = locator;
     this.state = OperationState.Unspecified;
 }
コード例 #10
0
 public VBDelete(VBucketNodeLocator locator, string key)
     : base(key)
 {
     this.locator = locator;
 }
コード例 #11
0
 public VBConcat(VBucketNodeLocator locator, ConcatenationMode mode, string key, ArraySegment<byte> data)
     : base(mode, key, data)
 {
     this.locator = locator;
 }
コード例 #12
0
		private InternalState InitVBucket(ClusterConfig config, ISaslAuthenticationProvider auth)
		{
			// we have a vbucket config, which has its own server list
			// it's supposed to be the same as the cluster config's list,
			// but the order is significicant (because of the bucket indexes),
			// so we we'll use this for initializing the locator
			var vbsm = config.vBucketServerMap;

			if (log.IsInfoEnabled) log.Info("Has vbucket. Server count: " + (vbsm.serverList == null ? 0 : vbsm.serverList.Length));

			var epa = (from server in vbsm.serverList
					   select ConfigurationHelper.ResolveToEndPoint(server)).ToArray();

			var epaLength = epa.Length;

			for (var i = 0; i < vbsm.vBucketMap.Length; i++)
			{
				var vb = vbsm.vBucketMap[i];
				if (vb == null || vb.Length == 0)
					throw new InvalidOperationException("Server sent an empty vbucket definition at index " + i);
				if (vb[0] >= epaLength || vb[0] < 0)
					throw new InvalidOperationException(String.Format("VBucket line {0} has a master index {1} out of range of the server list ({2})", i, vb[0], epaLength));
			}

			var buckets = vbsm.vBucketMap.Select(a => new VBucket(a[0], a.Skip(1).ToArray())).ToArray();
			var bucketNodeMap = buckets.ToLookup(vb =>
			{
				try
				{
					return epa[vb.Master];
				}
				catch (Exception e)
				{
					log.Error(e);

					throw;
				}
			}
			);
			var vbnl = new VBucketNodeLocator(vbsm.hashAlgorithm, buckets);

			return new InternalState
			{
				CurrentNodes = epa.Select(ip => (IMemcachedNode)new BinaryNode(ip, this.configuration.SocketPool, auth)).ToArray(),
				Locator = vbnl,
				OpFactory = new VBucketAwareOperationFactory(vbnl)
			};
		}
コード例 #13
0
        private InternalState InitVBucket(ClusterConfig config, ISaslAuthenticationProvider auth)
        {
            // we have a vbucket config, which has its own server list
            // it's supposed to be the same as the cluster config's list,
            // but the order is significicant (because of the bucket indexes),
            // so we we'll use this for initializing the locator
            var vbsm = config.vBucketServerMap;

            if (log.IsInfoEnabled) log.Info("Has vbucket. Server count: " + (vbsm.serverList == null ? 0 : vbsm.serverList.Length));

            // parse the ip addresses of the servers in the vbucket map
            // make sure we have a propert vbucket map
            ValidateVBucketMap(vbsm, vbsm.serverList.Length);

            // create vbuckets from the int[][] arrays
            var buckets = vbsm.vBucketMap.Select(a => new VBucket(a[0], a.Skip(1).ToArray())).ToArray();

            var locator = new VBucketNodeLocator(vbsm.hashAlgorithm, buckets);

            // create a (host=>node) lookup from the node info objects,
            // so we can pass the extra config data to the factory method
            // (the vbucket map only contains 'host:port' strings)
            // this expects that all nodes listed in the vbucket map are listed in the config.nodes member as well
            var realNodes = config.nodes.ToDictionary(node => node.HostName + ":" + node.Port);
            var nodes = new List<IMemcachedNode>();

            foreach (var hostSpec in vbsm.serverList)
            {
                ClusterNode node;

                if (!realNodes.TryGetValue(hostSpec, out node))
                    throw new InvalidOperationException(String.Format("VBucket map contains a node {0} whihc was not found in the cluster info's node list.", hostSpec));

                var ip = GetFirstAddress(node.HostName);
                var endpoint = new IPEndPoint(ip, node.Port);

                nodes.Add(this.CreateNode(endpoint, auth, node.ConfigurationData));
            }

            return new InternalState
            {
                CurrentNodes = nodes.ToArray(),
                Locator = locator,
                OpFactory = new VBucketAwareOperationFactory(locator),
                IsVbucket = true
            };
        }
コード例 #14
0
 public GetWithLockOperation(VBucketNodeLocator locator, string key, uint lockExpiration)
     : base(key)
 {
     this.locator = locator;
     this.lockExpiration = lockExpiration;
 }
コード例 #15
0
 public GetAndTouchOperation(VBucketNodeLocator locator, string key, uint newExpiration)
     : base(key)
 {
     this.locator = locator;
     this.newExpiration = newExpiration;
 }
コード例 #16
0
 public UnlockOperation(VBucketNodeLocator locator, string key, ulong cas)
     : base(key)
 {
     this.locator = locator;
     this.Cas = cas;
 }