コード例 #1
0
	    public void DecodeFrom(IArrayAccessor accessor)
	    {
		    for (int i = 0; i < _tableMagicBytes.Length; i++)
		    {
			    var b = accessor[EncodedLength - _tableMagicBytes.Length + i];
				if( b != _tableMagicBytes[i])
					throw new InvalidOperationException("Not a sstable (bad magic number)");
		    }

			MetaIndexHandle = new BlockHandle();
			IndexHandle = new BlockHandle();
		    var size = MetaIndexHandle.DecodeFrom(accessor, 0);
		    IndexHandle.DecodeFrom(accessor, size);
	    }
コード例 #2
0
		private void InitDataIterator()
		{
			if (_indexIterator.IsValid == false)
			{
				SetDataIterator(null);
				return;
			}

			var handle = new BlockHandle();
			using (var stream = _indexIterator.CreateValueStream())
			{
				handle.DecodeFrom(stream);
			}

			if (handle.Equals(_currentDataHandle) &&  // nothing to change
				_dataIterator != null)  // but we have no iterator?
				return;

			IIterator blockIterator = null;
			try
			{
				blockIterator = getIterator(_readOptions, handle);
				SetDataIterator(blockIterator);
			}
			catch (Exception)
			{
				if (blockIterator != null)
					blockIterator.Dispose();
				throw;
			}
			_currentDataHandle = handle;
		}
コード例 #3
0
		public Table(StorageState storageState, FileData fileData)
		{
			_storageState = storageState;
			try
			{
				_fileData = fileData;

				if (_storageState.Options.MaxBlockCacheSizePerTableFile > 0)
				{
					_blockCache = new LruCache<BlockHandle, Block>(_storageState.Options.MaxBlockCacheSizePerTableFile);
				}

				if (fileData.Size < Footer.EncodedLength)
					throw new CorruptedDataException("File is too short to be an sstable");

				var footer = new Footer();
				using (var accessor = fileData.File.CreateAccessor(fileData.Size - Footer.EncodedLength, Footer.EncodedLength))
				{
					footer.DecodeFrom(accessor);
				}

				var readOptions = new ReadOptions
					{
						VerifyChecksums = _storageState.Options.ParanoidChecks
					};
				_indexBlock = new Block(_storageState.Options, readOptions, footer.IndexHandle, fileData);
				_indexBlock.IncrementUsage();
				if (_storageState.Options.FilterPolicy == null)
					return; // we don't need any metadata

				using (var metaBlock = new Block(_storageState.Options, readOptions, footer.MetaIndexHandle, fileData))
				using (var iterator = metaBlock.CreateIterator(CaseInsensitiveComparator.Default))
				{
					var filterName = ("filter." + _storageState.Options.FilterPolicy.Name);
					iterator.Seek(filterName);
					if (iterator.IsValid && CaseInsensitiveComparator.Default.Compare(filterName, iterator.Key) == 0)
					{
						var handle = new BlockHandle();
						using (var stream = iterator.CreateValueStream())
						{
							handle.DecodeFrom(stream);
						}
						var filterAccessor = _fileData.File.CreateAccessor(handle.Position, handle.Count);
						try
						{
							_filter = _storageState.Options.FilterPolicy.CreateFilter(filterAccessor);
						}
						catch (Exception)
						{
							if (_filter == null)
								filterAccessor.Dispose();
							else
								_filter.Dispose();
							throw;
						}

					}
				}
			}
			catch (Exception)
			{
				Dispose();
				throw;
			}
		}
コード例 #4
0
		internal Tuple<Slice, Stream> InternalGet(ReadOptions readOptions, InternalKey key)
		{
			using (var iterator = _indexBlock.CreateIterator(_storageState.InternalKeyComparator))
			{
				iterator.Seek(key.TheInternalKey);
				if (iterator.IsValid == false)
					return null;
				var handle = new BlockHandle();
				using (var stream = iterator.CreateValueStream())
				{
					handle.DecodeFrom(stream);
				}
				if (_filter != null && _filter.KeyMayMatch(handle.Position, key.UserKey) == false)
				{
					return null; // opptimized not found by filter, no need to read the actual block
				}
				using (var blockIterator = CreateBlockIterator(readOptions, handle))
				{
					blockIterator.Seek(key.TheInternalKey);
					if (blockIterator.IsValid == false)
						return null;
					return Tuple.Create(blockIterator.Key, blockIterator.CreateValueStream());
				}
			}
		}