Ejemplo n.º 1
0
		public void T1()
		{
			var storageState = new StorageState("test", new StorageOptions());
			var random = new Random();
			var tables = new List<MemTable>();
			var expectedCount = 0;

			try
			{
				ulong seq = 0;
				for (var i = 0; i < 100; i++)
				{
					var table = new MemTable(storageState);
					for (var j = 0; j < 1000; j++)
					{
						var k = random.Next();
						var key = string.Format("{0:0000000000000000}", k);
						table.Add(seq++, ItemType.Value, key, null);
						expectedCount++;
					}

					tables.Add(table);
				}

				var iterators = tables.Select(table => table.NewIterator()).ToList();
				var comparator = new InternalKeyComparator(new CaseInsensitiveComparator());

				using (var iterator = new MergingIterator(comparator, iterators))
				{
					var actualCount = 0;
					iterator.SeekToFirst();
					Assert.True(iterator.IsValid);

					Slice prev = string.Empty;

					while (iterator.IsValid)
					{
						if (!prev.IsEmpty())
						{
							Assert.True(comparator.Compare(iterator.Key, prev) > 0);
						}

						prev = iterator.Key.Clone();
						iterator.Next();
						actualCount++;
					}

					Assert.Equal(expectedCount, actualCount);
				}
			}
			finally
			{
				foreach (var table in tables)
					table.Dispose();
			}

			
		}
Ejemplo n.º 2
0
		public Tuple<IIterator, ulong> NewInternalIterator(ReadOptions options)
		{
			var mem = MemTable;
			var imm = ImmutableMemTable;
			var currentVersion = VersionSet.Current;

			var snapshot = options.Snapshot != null ? options.Snapshot.Sequence : VersionSet.LastSequence;

			var iterators = new List<IIterator>
				                {
					                mem.NewIterator()
				                };

			if (imm != null)
				iterators.Add(imm.NewIterator());

			// Merge all level zero files together since they may overlap
			iterators.AddRange(currentVersion.Files[0].Select(file => TableCache.NewIterator(options, file.FileNumber, file.FileSize)));

			// For levels > 0, we can use a concatenating iterator that sequentially
			// walks through the non-overlapping files in the level, opening them
			// lazily.
			for (var level = 1; level < Config.NumberOfLevels; level++)
			{
				if (currentVersion.Files[level].Count > 0)
					iterators.Add(new TwoLevelIterator(new LevelFileNumIterator(InternalKeyComparator, currentVersion.Files[level]), VersionSet.GetFileIterator, options));
			}

			var internalIterator = new MergingIterator(InternalKeyComparator, iterators);

			return new Tuple<IIterator, ulong>(internalIterator, snapshot);
		}