Exemple #1
0
        public void TestCoalesceEmptyTree()
        {
            const string storeName = "Coalesce.EmptyTree.data";
            ulong        srcRootId, coalescedRootId;

            using (var store = TestUtils.CreateEmptyPageStore(storeName))
            {
                var tree = new BPlusTree(0, store);
                srcRootId = tree.Save(0, null);
                store.Commit(0, null);
            }

            using (var store = TestUtils.OpenPageStore(storeName, false))
            {
                var sourceTree = new BPlusTree(store, srcRootId);
                Assert.AreEqual(0, sourceTree.Scan(null).Count());
                var builder = new BPlusTreeBuilder(store, sourceTree.Configuration);
                coalescedRootId = builder.Build(1, sourceTree.Scan(null));
                var coalescedTree = new BPlusTree(store, coalescedRootId);
                Assert.AreEqual(0, coalescedTree.Scan(null).Count());
                store.Commit(1ul, null);
            }

            using (var store = TestUtils.OpenPageStore(storeName, true))
            {
                var coalescedTree = new BPlusTree(store, coalescedRootId);
                Assert.AreEqual(0, coalescedTree.Scan(null).Count());
            }
        }
Exemple #2
0
        public ulong Write(IPageStore pageStore, ulong transactionId, BrightstarProfiler profiler)
        {
            var targetConfiguration = new BPlusTreeConfiguration(pageStore, Configuration.KeySize,
                                                                 Configuration.ValueSize, Configuration.PageSize);
            var builder = new BPlusTreeBuilder(pageStore, targetConfiguration);

            return(builder.Build(transactionId, Scan(profiler), profiler));
        }
 public ulong Write(IPageStore pageStore, ulong transactionId, BrightstarProfiler profiler)
 {
     using (profiler.Step("RelatedResourceIndex.Write"))
     {
         var indexBuilder = new BPlusTreeBuilder(pageStore, Configuration);
         return(indexBuilder.Build(transactionId, WritePredicateIndexes(pageStore, transactionId, profiler),
                                   profiler));
     }
 }
 private IEnumerable <KeyValuePair <byte[], byte []> > WritePredicateIndexes(IPageStore pageStore, ulong transactionId, BrightstarProfiler profiler)
 {
     foreach (var entry in EnumeratePredicateIndexes(profiler))
     {
         var   predicateId         = entry.Key;
         var   builder             = new BPlusTreeBuilder(pageStore, entry.Value.Configuration);
         ulong newPredicateIndexId = builder.Build(transactionId, entry.Value.Scan(profiler), profiler);
         yield return(new KeyValuePair <byte[], byte[]>(BitConverter.GetBytes(predicateId), BitConverter.GetBytes(newPredicateIndexId)));
     }
 }
Exemple #5
0
        public void TestCoalesceRootLeafNode()
        {
            const string storeName = "Coalesce.RootLeafNode.data";
            ulong        srcRootId, targetRootId;
            var          txnId = 0ul;

            using (var store = TestUtils.CreateEmptyPageStore(storeName))
            {
                var sourceTree = new BPlusTree(0, store);
                var config     = sourceTree.Configuration;
                for (int i = 0; i < config.LeafLoadFactor; i++)
                {
                    sourceTree.Insert(txnId, (ulong)i, BitConverter.GetBytes((ulong)i));
                }
                sourceTree.DumpStructure();
                srcRootId = sourceTree.Save(txnId, null);
                store.Commit(txnId, null);
            }

            using (var store = TestUtils.OpenPageStore(storeName, false))
            {
                var sourceTree = new BPlusTree(store, srcRootId);
                var config     = sourceTree.Configuration;
                var builder    = new BPlusTreeBuilder(store, config);
                targetRootId = builder.Build(1, sourceTree.Scan(null));

                var targetTree = new BPlusTree(store, targetRootId);
                targetTree.DumpStructure();
                byte[] valueBuff = new byte[64];
                for (int i = 0; i < config.LeafLoadFactor; i++)
                {
                    Assert.IsTrue(targetTree.Search((ulong)i, valueBuff, null));
                    Assert.AreEqual((ulong)i, BitConverter.ToUInt64(valueBuff, 0));
                }
                store.Commit(1, null);
            }

            using (var store = TestUtils.OpenPageStore(storeName, true))
            {
                var targetTree = new BPlusTree(store, targetRootId);
                var config     = targetTree.Configuration;
                targetTree.DumpStructure();
                byte[] valueBuff = new byte[64];
                for (int i = 0; i < config.LeafLoadFactor; i++)
                {
                    Assert.IsTrue(targetTree.Search((ulong)i, valueBuff, null));
                    Assert.AreEqual((ulong)i, BitConverter.ToUInt64(valueBuff, 0));
                }
            }
        }
        private void BuildAndScan(IPageStore pageStore, string pageStoreName, PersistenceType persistenceType, int keyCount)
        {
            var config         = new BPlusTreeConfiguration(8, 64, pageStore.PageSize);
            var builder        = new BPlusTreeBuilder(pageStore, config);
            var treeRoot       = builder.Build(1, _testOrderedValues.Take(keyCount));
            var treeBeforeSave = new BPlusTree(pageStore, treeRoot);

            treeBeforeSave.Save(1, null);
            //ValidateScan(treeBeforeSave.Scan(null), keyCount, pageStoreName + " before save");
            pageStore.Commit(1, null);
            pageStore.Close();


            using (var ps = TestUtils.OpenPageStore(pageStoreName, true, persistenceType, 1))
            {
                var tree = new BPlusTree(ps, treeRoot);
                tree.DumpStructure();
                ValidateScan(tree.Scan(null), keyCount, pageStoreName + " after save");
                ValidateSearch(tree, keyCount, pageStoreName + "after save");
            }
        }
Exemple #7
0
        public ulong Write(IPageStore pageStore, ulong transactionId, BrightstarProfiler profiler)
        {
            var builder = new BPlusTreeBuilder(pageStore, Configuration);

            return(builder.Build(transactionId, Scan(profiler), profiler));
        }
 public ulong Write(IPageStore pageStore, ulong  transactionId, BrightstarProfiler profiler)
 {
     var targetConfiguration = new BPlusTreeConfiguration(pageStore, Configuration.KeySize,
                                                          Configuration.ValueSize, Configuration.PageSize);
     var builder = new BPlusTreeBuilder(pageStore, targetConfiguration);
     return builder.Build(transactionId, Scan(profiler), profiler);
 }
 public ulong Write(IPageStore pageStore, ulong  transactionId, BrightstarProfiler profiler)
 {
     var builder = new BPlusTreeBuilder(pageStore, Configuration);
     return builder.Build(transactionId, Scan(profiler), profiler);
 }
 private IEnumerable<KeyValuePair<byte[], byte []>> WritePredicateIndexes(IPageStore pageStore, ulong transactionId, BrightstarProfiler profiler)
 {
     foreach (var entry in EnumeratePredicateIndexes(profiler))
     {
         var predicateId = entry.Key;
         var targetConfiguration = new BPlusTreeConfiguration(pageStore, entry.Value.Configuration.KeySize,
                                                              entry.Value.Configuration.ValueSize,
                                                              entry.Value.Configuration.PageSize);
         var builder = new BPlusTreeBuilder(pageStore, targetConfiguration);
         ulong newPredicateIndexId = builder.Build(transactionId, entry.Value.Scan(profiler), profiler);
         yield return new KeyValuePair<byte[], byte[]>(BitConverter.GetBytes(predicateId), BitConverter.GetBytes(newPredicateIndexId));
     }
 }
 public ulong Write(IPageStore pageStore, ulong transactionId, BrightstarProfiler profiler)
 {
     using (profiler.Step("RelatedResourceIndex.Write"))
     {
         var targetConfiguration = new BPlusTreeConfiguration(pageStore, Configuration.KeySize,
                                                              Configuration.ValueSize, Configuration.PageSize);
         var indexBuilder = new BPlusTreeBuilder(pageStore, targetConfiguration);
         return indexBuilder.Build(transactionId, WritePredicateIndexes(pageStore, transactionId, profiler),
                                   profiler);
     }
 }
Exemple #12
0
        public void TestCoalesceLeafLoadPlusOne()
        {
            const string storeName = "Coalesce.LeafLoadPlusOne.data";
            ulong        srcRootId, targetRootId;
            var          txnId = 0ul;

            using (var store = TestUtils.CreateEmptyPageStore(storeName))
            {
                var sourceTree = new BPlusTree(0, store);
                var config     = sourceTree.Configuration;
                for (int i = 0; i < config.LeafLoadFactor + 1; i++)
                {
                    sourceTree.Insert(txnId, (ulong)i, BitConverter.GetBytes((ulong)i));
                }
                sourceTree.DumpStructure();
                srcRootId = sourceTree.Save(txnId, null);
                store.Commit(txnId, null);
            }

            using (var store = TestUtils.OpenPageStore(storeName, false))
            {
                var sourceTree = new BPlusTree(store, srcRootId);
                var config     = sourceTree.Configuration;
                var builder    = new BPlusTreeBuilder(store, config);
                targetRootId = builder.Build(1, sourceTree.Scan(null));
                var targetTree = new BPlusTree(store, targetRootId);
                targetTree.DumpStructure();
                byte[] valueBuff = new byte[64];
                for (int i = 0; i < config.LeafLoadFactor + 1; i++)
                {
                    Assert.IsTrue(targetTree.Search((ulong)i, valueBuff, null));
                    Assert.AreEqual((ulong)i, BitConverter.ToUInt64(valueBuff, 0));
                }
                store.Commit(1, null);
            }

            using (var store = TestUtils.OpenPageStore(storeName, true))
            {
                var targetTree = new BPlusTree(store, targetRootId);
                var config     = targetTree.Configuration;

                targetTree.DumpStructure();
                byte[] valueBuff = new byte[64];
                for (int i = 0; i < config.LeafLoadFactor + 1; i++)
                {
                    Assert.IsTrue(targetTree.Search((ulong)i, valueBuff, null));
                    Assert.AreEqual((ulong)i, BitConverter.ToUInt64(valueBuff, 0));
                }

                var root = targetTree.GetNode(targetTree.RootId, null) as IInternalNode;
                Assert.IsNotNull(root);
                Assert.AreEqual(1, root.KeyCount);
                var leftChild  = targetTree.GetNode(root.GetChildPointer(0), null) as ILeafNode;
                var rightChild = targetTree.GetNode(root.GetChildPointer(1), null) as ILeafNode;
                Assert.IsNotNull(leftChild);
                Assert.IsNotNull(rightChild);

                Assert.AreEqual(config.LeafLoadFactor + 1, leftChild.KeyCount + rightChild.KeyCount);
                // Key count in each node should be >= split index
                Assert.IsTrue(leftChild.KeyCount > config.LeafSplitIndex, "Left child has too few keys");
                Assert.IsTrue(rightChild.KeyCount > config.LeafSplitIndex, "Right child has too few keys");
                // And neither
            }
        }