Пример #1
0
        public void CopyToOriginal(LowLevelTransaction tx, bool defragRequired, bool wasModified)
        {
            if (CalcSizeUsed() < Original.PageMaxSpace)
            {
                // no need to compress
                Original.Lower  = (ushort)Constants.Tree.PageHeaderSize;
                Original.Upper  = (ushort)Original.PageSize;
                Original.Flags &= ~PageFlags.Compressed;

                for (var i = 0; i < NumberOfEntries; i++)
                {
                    var node = GetNode(i);
                    using (TreeNodeHeader.ToSlicePtr(tx.Allocator, node, out var slice))
                        Original.CopyNodeDataToEndOfPage(node, slice);
                }
            }
            else
            {
                using (LeafPageCompressor.TryGetCompressedTempPage(tx, this, out var compressed, defrag: defragRequired))
                {
                    if (compressed == null)
                    {
                        if (wasModified == false)
                        {
                            return;
                        }

                        ThrowCouldNotCompressDecompressedPage(PageNumber);
                    }

                    LeafPageCompressor.CopyToPage(compressed, Original);
                }
            }
        }
Пример #2
0
        public void CopyToOriginal(LowLevelTransaction tx, bool defragRequired)
        {
            if (CalcSizeUsed() < Original.PageMaxSpace)
            {
                // no need to compress
                Original.Lower  = (ushort)Constants.Tree.PageHeaderSize;
                Original.Upper  = (ushort)Original.PageSize;
                Original.Flags &= ~PageFlags.Compressed;

                for (var i = 0; i < NumberOfEntries; i++)
                {
                    var   node = GetNode(i);
                    Slice slice;
                    using (TreeNodeHeader.ToSlicePtr(tx.Allocator, node, out slice))
                        Original.CopyNodeDataToEndOfPage(node, slice);
                }
            }
            else
            {
                CompressionResult compressed;
                using (LeafPageCompressor.TryGetCompressedTempPage(tx, this, out compressed, defrag: defragRequired))
                {
                    if (compressed == null)
                    {
                        throw new InvalidOperationException("Could not compress a page which was already compressed. Should never happen");
                    }

                    LeafPageCompressor.CopyToPage(compressed, Original);
                }
            }
        }
Пример #3
0
        public void CopyToOriginal(LowLevelTransaction tx, bool defragRequired, bool wasModified, Tree tree)
        {
            if (CalcSizeUsed() < Original.PageMaxSpace)
            {
                // no need to compress
                Original.Lower  = (ushort)Constants.Tree.PageHeaderSize;
                Original.Upper  = (ushort)Original.PageSize;
                Original.Flags &= ~PageFlags.Compressed;

                for (var i = 0; i < NumberOfEntries; i++)
                {
                    var node = GetNode(i);
                    using (TreeNodeHeader.ToSlicePtr(tx.Allocator, node, out var slice))
                        Original.CopyNodeDataToEndOfPage(node, slice);
                }

                tree.DecompressionsCache.Invalidate(PageNumber, DecompressionUsage.Write);
            }
            else
            {
                using (LeafPageCompressor.TryGetCompressedTempPage(tx, this, out var compressed, defrag: defragRequired))
                {
                    if (compressed == null)
                    {
                        if (wasModified == false)
                        {
                            return;
                        }

                        if (NumberOfEntries > 0)
                        {
                            // we aren't able to compress the page back to 8KB page
                            // let's split it and try to copy it then

                            SplitPage(tx, tree);
                        }
                        else
                        {
                            ThrowCouldNotCompressEmptyDecompressedPage(PageNumber);
                        }

                        CopyToOriginal(tx, defragRequired: true, wasModified: true, tree);

                        return;
                    }

                    LeafPageCompressor.CopyToPage(compressed, Original);
                }
            }
        }