Пример #1
0
		public void CanReadValuesBackWithoutFilter()
		{
			var state = new StorageState("none", new StorageOptions
			{
				ParanoidChecks = true,
				FilterPolicy = null
			});
			string name;
			using (var file = CreateFile())
			{
				name = file.Name;
				using (var tblBuilder = new TableBuilder(state, file, new TemporaryFiles(state.FileSystem, 1)))
				{
					for (int i = 0; i < 10; i++)
					{
						string k = "tests/" + i.ToString("0000");
						tblBuilder.Add(new InternalKey(k, 1, ItemType.Value).TheInternalKey, new MemoryStream(Encoding.UTF8.GetBytes(k)));
					}

					tblBuilder.Finish();
					file.Flush(true);
				}
			}

			using (var mmf = MemoryMappedFile.CreateFromFile(name, FileMode.Open))
			{
				var length = new FileInfo(name).Length;
				using (var table = new Table(state, new FileData(new MemoryMappedFileAccessor(name, mmf), length)))
				using (var iterator = table.CreateIterator(new ReadOptions()))
				{
					for (int i = 0; i < 10; i++)
					{
						string k = "tests/" + i.ToString("0000");
						iterator.Seek(new InternalKey(k, 100, ItemType.Value).TheInternalKey);
						Assert.True(iterator.IsValid);
						using (var stream = iterator.CreateValueStream())
						using (var reader = new StreamReader(stream))
						{
							Assert.Equal(k, reader.ReadToEnd());
						}
					}
				}
			}
		}
Пример #2
0
		private Table FindTable(ulong fileNumber, long fileSize)
		{
			slim.EnterReadLock();
			try
			{
				Table table;
				if (cache.TryGet(fileNumber, out table))
				{
					return table;
				}
			}
			finally
			{
				slim.ExitReadLock();
			}

			slim.EnterWriteLock();
			try
			{
				Table table;
				if (cache.TryGet(fileNumber, out table))
				{
					return table;
				}

				var filePath = state.FileSystem.GetFullFileName(fileNumber, Constants.Files.Extensions.TableFile);

				IAccessor file = state.FileSystem.OpenMemoryMap(filePath);
				var fileData = new FileData(file, fileSize);
				table = new Table(state, fileData);

				cache.Set(fileNumber, table);

				return table;
			}
			finally
			{
				slim.ExitWriteLock();
			}

		}
Пример #3
0
		private IEnumerable<RavenJObject> YieldSstContents(Table table, Reference<Slice> reference)
		{
			using (var iterator = table.CreateIterator(new ReadOptions()))
			{
				iterator.Seek(reference.Value);
				while (iterator.IsValid)
				{
					reference.Value = iterator.Key;
					using (var stream = iterator.CreateValueStream())
					{
						yield return RavenJObject.Load(new BsonReader(stream));
					}
					iterator.Next();
				}
			}
		}