Exemplo n.º 1
0
        /// <summary>
        /// Create new index node and persist into page segment
        /// </summary>
        public IndexNode(IndexPage page, byte index, BufferSlice segment, byte slot, byte level, BsonValue key, PageAddress dataBlock)
        {
            _page = page;
            _segment = segment;

            this.Position = new PageAddress(page.PageID, index);
            this.Slot = slot;
            this.Level = level;
            this.Key = key;
            this.DataBlock = dataBlock;
            this.NextNode = PageAddress.Empty;

            this.Next = new PageAddress[level];
            this.Prev = new PageAddress[level];

            for (var i = 0; i < level; i++)
            {
                this.SetPrev((byte)i, PageAddress.Empty);
                this.SetNext((byte)i, PageAddress.Empty);
            }

            // persist in buffer read only data
            segment[P_SLOT] = slot;
            segment[P_LEVEL] = level;
            segment.Write(dataBlock, P_DATA_BLOCK);
            segment.WriteIndexKey(key, P_KEY);

            // prevNode/nextNode must be defined as Empty
            segment.Write(this.NextNode, P_NEXT_NODE);

            page.IsDirty = true;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Update NextNode pointer (update in buffer too). Also, set page as dirty
        /// </summary>
        public void SetNextNode(PageAddress value)
        {
            this.NextNode = value;

            _segment.Write(value, P_NEXT_NODE);

            _page.IsDirty = true;
        }
Exemplo n.º 3
0
        public void Insert(IEnumerable <KeyValuePair <BsonValue, PageAddress> > items, int order, BufferSlice buffer)
        {
            var query = order == Query.Ascending ?
                        items.OrderBy(x => x.Key, _collation) : items.OrderByDescending(x => x.Key, _collation);

            var offset = 0;

            foreach (var item in query)
            {
                buffer.WriteIndexKey(item.Key, offset);

                var keyLength = IndexNode.GetKeyLength(item.Key, false);

                if (keyLength > MAX_INDEX_KEY_LENGTH)
                {
                    throw LiteException.InvalidIndexKey($"Sort key must be less than {MAX_INDEX_KEY_LENGTH} bytes.");
                }

                offset += keyLength;

                buffer.Write(item.Value, offset);

                offset += PageAddress.SIZE;

                _remaining++;
            }

            _count = _remaining;
        }
Exemplo n.º 4
0
        public void SetNextBlock(PageAddress nextBlock)
        {
            this.NextBlock = nextBlock;

            // update segment buffer with NextBlock (uint + byte)
            _segment.Write(nextBlock, P_NEXT_BLOCK);

            _page.IsDirty = true;
        }
Exemplo n.º 5
0
        /// <summary>
        /// Create new DataBlock and fill into buffer
        /// </summary>
        public DataBlock(DataPage page, byte index, BufferSlice segment, bool extend, PageAddress nextBlock)
        {
            _page    = page;
            _segment = segment;

            this.Position = new PageAddress(page.PageID, index);

            this.NextBlock = nextBlock;
            this.Extend    = extend;

            // byte 00: Data Index
            segment.Write(extend, P_EXTEND);

            // byte 01-05 (can be updated in "UpdateNextBlock")
            segment.Write(nextBlock, P_NEXT_BLOCK);

            // byte 06-EOL: Buffer
            this.Buffer = segment.Slice(P_BUFFER, segment.Count - P_BUFFER);

            page.IsDirty = true;
        }
Exemplo n.º 6
0
        public void Insert(IEnumerable <KeyValuePair <BsonValue, PageAddress> > items, int order, BufferSlice buffer)
        {
            var query = order == Query.Ascending ?
                        items.OrderBy(x => x.Key) : items.OrderByDescending(x => x.Key);

            var offset = 0;

            foreach (var item in query)
            {
                buffer.WriteIndexKey(item.Key, offset);

                offset += GetKeyLength(item.Key);

                buffer.Write(item.Value, offset);

                offset += PageAddress.SIZE;

                _remaining++;
            }

            _count = _remaining;
        }