/// <summary>Create an allocator operating under a specific location</summary>
		/// <param name="subspace"></param>
		public FdbHighContentionAllocator(FdbSubspace subspace)
		{
			if (subspace == null) throw new ArgumentException("subspace");

			this.Subspace = subspace;
			this.Counters = subspace.Partition(COUNTERS);
			this.Recent = subspace.Partition(RECENT);
		}
Exemplo n.º 2
0
        /// <summary>Create an allocator operating under a specific location</summary>
        /// <param name="subspace"></param>
        public FdbHighContentionAllocator(FdbSubspace subspace)
        {
            if (subspace == null)
            {
                throw new ArgumentException("subspace");
            }

            this.Subspace = subspace;
            this.Counters = subspace.Partition(COUNTERS);
            this.Recent   = subspace.Partition(RECENT);
        }
        public FdbWorkerPool(FdbSubspace subspace)
        {
            if (subspace == null)
            {
                throw new ArgumentNullException("subspace");
            }

            this.Subspace = subspace;

            this.TaskStore          = subspace.Partition(Slice.FromChar('T'));
            this.IdleRing           = subspace.Partition(Slice.FromChar('I'));
            this.BusyRing           = subspace.Partition(Slice.FromChar('B'));
            this.UnassignedTaskRing = subspace.Partition(Slice.FromChar('U'));

            this.Counters = new FdbCounterMap <int>(subspace.Partition(Slice.FromChar('C')));
        }
        public void Test_Subspace_Partitioning_With_Tuple_Suffix()
        {
            // start from a parent subspace
            var parent = new FdbSubspace(Slice.Create(new byte[] { 254 }));

            Assert.That(parent.Key.ToString(), Is.EqualTo("<FE>"));

            // create a child subspace using a tuple
            var child = parent.Partition(FdbTuple.Create("hca"));

            Assert.That(child, Is.Not.Null);
            Assert.That(child.Key.ToString(), Is.EqualTo("<FE><02>hca<00>"));

            // create a tuple from this child subspace
            var tuple = child.Append(123);

            Assert.That(tuple, Is.Not.Null);
            Assert.That(tuple.ToSlice().ToString(), Is.EqualTo("<FE><02>hca<00><15>{"));

            // derive another tuple from this one
            var t1 = tuple.Append(false);

            Assert.That(t1.ToSlice().ToString(), Is.EqualTo("<FE><02>hca<00><15>{<14>"));

            // check that we could also create the same tuple starting from the parent subspace
            var t2 = parent.Append("hca", 123, false);

            Assert.That(t2.ToSlice(), Is.EqualTo(t1.ToSlice()));

            // cornercase
            Assert.That(child[FdbTuple.Empty].Key, Is.EqualTo(child.Key));
        }
Exemplo n.º 5
0
        /// <summary>Create a new queue using either High Contention mode or Simple mode</summary>
        /// <param name="subspace">Subspace where the queue will be stored</param>
        /// <param name="highContention">If true, uses High Contention Mode (lots of popping clients). If true, uses the Simple Mode (a few popping clients).</param>
        public FdbQueue([NotNull] FdbSubspace subspace, bool highContention, [NotNull] IValueEncoder <T> encoder)
        {
            if (subspace == null)
            {
                throw new ArgumentNullException("subspace");
            }
            if (encoder == null)
            {
                throw new ArgumentNullException("encoder");
            }

            this.Subspace       = subspace;
            this.HighContention = highContention;
            this.Encoder        = encoder;

            this.ConflictedPop  = subspace.Partition(Slice.FromAscii("pop"));
            this.ConflictedItem = subspace.Partition(Slice.FromAscii("conflict"));
            this.QueueItem      = subspace.Partition(Slice.FromAscii("item"));
        }
		public FdbWorkerPool(FdbSubspace subspace)
		{
			if (subspace == null) throw new ArgumentNullException("subspace");

			this.Subspace = subspace;

			this.TaskStore = subspace.Partition(Slice.FromChar('T'));
			this.IdleRing = subspace.Partition(Slice.FromChar('I'));
			this.BusyRing = subspace.Partition(Slice.FromChar('B'));
			this.UnassignedTaskRing = subspace.Partition(Slice.FromChar('U'));

			this.Counters = new FdbCounterMap<int>(subspace.Partition(Slice.FromChar('C')));
		}
		/// <summary>Returns the list of names and nodes of all children of the specified node</summary>
		private IFdbAsyncEnumerable<KeyValuePair<string, FdbSubspace>> SubdirNamesAndNodes(IFdbReadOnlyTransaction tr, FdbSubspace node)
		{
			Contract.Requires(tr != null && node != null);

			var sd = node.Partition(SUBDIRS);
			return tr
				.GetRange(sd.ToRange())
				.Select(kvp => new KeyValuePair<string, FdbSubspace>(
					sd.UnpackSingle<string>(kvp.Key),
					NodeWithPrefix(kvp.Value)
				));
		}
		/// <summary>
		/// Creates a new instance that will manages directories in FoudnationDB.
		/// </summary>
		/// <param name="nodeSubspace">Subspace where all the node metadata will be stored ('\xFE' by default)</param>
		/// <param name="contentSubspace">Subspace where all automatically allocated directories will be stored (empty by default)</param>
		/// <param name="location">Location of the root of all the directories managed by this Directory Layer. Ususally empty for the root partition of the database.</param>
		internal FdbDirectoryLayer(FdbSubspace nodeSubspace, FdbSubspace contentSubspace, IFdbTuple location)
		{
			Contract.Requires(nodeSubspace != null && contentSubspace != null);

			// If specified, new automatically allocated prefixes will all fall within content_subspace
			this.ContentSubspace = contentSubspace;
			this.NodeSubspace = nodeSubspace;

			// The root node is the one whose contents are the node subspace
			this.RootNode = nodeSubspace.Partition(nodeSubspace.Key);
			this.Allocator = new FdbHighContentionAllocator(this.RootNode.Partition(HcaKey));
			if (location == null || location.Count == 0)
			{
				this.Location = FdbTuple.Empty;
				this.Path = new string[0];
			}
			else
			{
				this.Location = location;
				this.Path = location.ToArray<string>();
			}
		}
		public void Test_Subspace_Partitioning_With_Tuple_Suffix()
		{
			// start from a parent subspace
			var parent = new FdbSubspace(Slice.Create(new byte[] { 254 }));
			Assert.That(parent.Key.ToString(), Is.EqualTo("<FE>"));

			// create a child subspace using a tuple
			var child = parent.Partition(FdbTuple.Create("hca"));
			Assert.That(child, Is.Not.Null);
			Assert.That(child.Key.ToString(), Is.EqualTo("<FE><02>hca<00>"));

			// create a tuple from this child subspace
			var tuple = child.Append(123);
			Assert.That(tuple, Is.Not.Null);
			Assert.That(tuple.ToSlice().ToString(), Is.EqualTo("<FE><02>hca<00><15>{"));

			// derive another tuple from this one
			var t1 = tuple.Append(false);
			Assert.That(t1.ToSlice().ToString(), Is.EqualTo("<FE><02>hca<00><15>{<14>"));

			// check that we could also create the same tuple starting from the parent subspace
			var t2 = parent.Append("hca", 123, false);
			Assert.That(t2.ToSlice(), Is.EqualTo(t1.ToSlice()));

			// cornercase
			Assert.That(child[FdbTuple.Empty].Key, Is.EqualTo(child.Key));

		}