示例#1
0
        /// <summary>
        ///     The second layer of the search tree is a table file's block index of keys. The block index is part of the table
        ///     file's metadata which is located at the end of its physical data file. The index contains one entry for each
        ///     logical data block within the table file. The entry contains the last key in the block and the offset of the block
        ///     within the table file. leveldb performs a binary search of the block index to locate a candidate data block. It
        ///     reads the candidate data block from the table file.
        /// </summary>
        public static Footer Read(Stream stream)
        {
            stream.Seek(-FooterLength, SeekOrigin.End);
            Span <byte> footer = new byte[FooterLength];

            stream.Read(footer);

            var reader = new SpanReader(footer);

            var metaIndexHandle = BlockHandle.ReadBlockHandle(ref reader);
            var indexHandle     = BlockHandle.ReadBlockHandle(ref reader);

            reader.Seek(-sizeof(ulong), SeekOrigin.End);
            ReadOnlySpan <byte> magic = reader.Read(8);

            if (Magic.AsSpan().SequenceCompareTo(magic) != 0)
            {
                throw new Exception("Invalid footer. Magic end missing. This is not a proper table file");
            }

            return(new Footer(metaIndexHandle, indexHandle));
        }
示例#2
0
        /// <summary>
        ///     The second layer of the search tree is a table file's block index of keys. The block index is part of the table
        ///     file's metadata which is located at the end of its physical data file. The index contains one entry for each
        ///     logical data block within the table file. The entry contains the last key in the block and the offset of the block
        ///     within the table file. leveldb performs a binary search of the block index to locate a candidate data block. It
        ///     reads the candidate data block from the table file.
        /// </summary>
        public static Footer Read(MemoryMappedViewStream stream)
        {
            stream.Seek(-FooterLength, SeekOrigin.End);
            Span <byte> footer = new byte[FooterLength];

            stream.Read(footer);

            SpanReader reader = new SpanReader(footer);

            BlockHandle metaIndexHandle = BlockHandle.ReadBlockHandle(ref reader);
            BlockHandle indexHandle     = BlockHandle.ReadBlockHandle(ref reader);

            reader.Seek(-sizeof(ulong), SeekOrigin.End);
            var magic = reader.ReadUInt64();

            if (Magic != magic)
            {
                throw new Exception("Invalid footer. Magic end missing. This is not a proper table file");
            }

            return(new Footer(metaIndexHandle, indexHandle));
        }