Exemplo n.º 1
0
        public void ShouldStoreThreeRecordsOutOfOrder2(
            int pageSize)
        {
            var tree = new BplusTree(pageSize);

            var cusomter03 = CreateCustomer(102);

            tree.Insert(cusomter03);

            var cusomter02 = CreateCustomer(101);

            tree.Insert(cusomter02);

            var customer01 = CreateCustomer(100);

            tree.Insert(customer01);

            var customers = tree.GetAll();

            customers.Should().HaveCount(3);

            customers[0].CustomerId.Should().Be(100);
            customers[1].CustomerId.Should().Be(101);
            customers[2].CustomerId.Should().Be(102);
        }
Exemplo n.º 2
0
        public void BalancedInsert()
        {
            var tree = new BplusTree(PageCount);

            tree.GetStringVersion().Should().BeEmpty();

            var customerRecord1 = CreateCustomer(500);

            tree.Insert(customerRecord1);
            tree.GetStringVersion().Should().Be("P:500");

            var customerRecord2 = CreateCustomer(400);

            tree.Insert(customerRecord2);
            tree.GetStringVersion().Should().Be("P:400|P:500");

            var customerRecord3 = CreateCustomer(300);

            tree.Insert(customerRecord3);
            tree.GetStringVersion().Should().Be("P:300|P:400|P:500");

            var customerRecord4 = CreateCustomer(350);

            tree.Insert(customerRecord4);
            tree.GetStringVersion().Should().Be("P:300|P:350|I:400|P:400|P:500");
        }
Exemplo n.º 3
0
        public void Test910(
            int pageSize)
        {
            var tree = new BplusTree(pageSize);

            var customer01 = CreateCustomer(100);

            tree.Insert(customer01);

            var cusomter02 = CreateCustomer(110);

            tree.Insert(cusomter02);

            var cusomter03 = CreateCustomer(120);

            tree.Insert(cusomter03);

            var cusomter04 = CreateCustomer(105);

            tree.Insert(cusomter04);

            var cusomter05 = CreateCustomer(130);

            tree.Insert(cusomter05);

            var customers = tree.GetAll();

            customers.Should().HaveCount(5);

            customers[0].CustomerId.Should().Be(100);
            customers[1].CustomerId.Should().Be(105);
            customers[2].CustomerId.Should().Be(110);
            customers[3].CustomerId.Should().Be(120);
            customers[4].CustomerId.Should().Be(130);
        }
Exemplo n.º 4
0
        public void ShouldStoreTwoRecord(
            int pageSize)
        {
            var tree = new BplusTree(pageSize);

            var customer01 = CreateCustomer(100);

            tree.Insert(customer01);

            var cusomter02 = CreateCustomer(101);

            tree.Insert(cusomter02);

            var customers = tree.GetAll();

            customers.Should().HaveCount(2);

            customers[0].CustomerId.Should().Be(100);
            customers[0].Name.Should().Be(customer01.Name);

            customers[1].CustomerId.Should().Be(101);
            customers[1].Name.Should().Be(cusomter02.Name);

            var stringVersion = tree.GetStringVersion();

            stringVersion.Should().Be("P:100|P:101");
        }
Exemplo n.º 5
0
        private void Initialize(string workingDir, bool createNotFound)
        {
            if (String.IsNullOrEmpty(workingDir))
            {
                throw new InvalidOperationException();
            }

            _quickStorage = new MemoryTargetStorage();

            if (!Directory.Exists(workingDir))
            {
                Directory.CreateDirectory(workingDir);
            }
            if (_isSystem)
            {
                _treeFileName  = Path.Combine(workingDir, "LinkT2.6.10621.1.dat");
                _blockFileName = Path.Combine(workingDir, "LinkB2.6.10621.1.dat");
            }
            else
            {
                string tempFile = Path.GetFileNameWithoutExtension(
                    Path.GetTempFileName());

                _treeFileName  = Path.Combine(workingDir, tempFile + "Tree.dat");
                _blockFileName = Path.Combine(workingDir, tempFile + "Block.dat");
            }

            if (File.Exists(_treeFileName) && File.Exists(_blockFileName))
            {
                _isExisted = true;
                _plusTree  = hBplusTree.ReOpen(_treeFileName, _blockFileName);
                if (_plusTree.ContainsKey("$DataCount$"))
                {
                    _count = Convert.ToInt32(_plusTree["$DataCount$"]);
                }

                this.AddQuickTargets();
                //if (_count > 0)
                //{
                //}
            }
            else
            {
                _count = 0;
                if (createNotFound)
                {
                    _plusTree = hBplusTree.Initialize(_treeFileName,
                                                      _blockFileName, 64);
                }
            }

            if (_plusTree != null)
            {
                _targetCache = new DatabaseTargetCache(100);
            }
        }
Exemplo n.º 6
0
        private void Initialize(string workingDir, bool createNotFound)
        {
            _count          = 0;
            _cachedMsdnUrls = new Dictionary <string, string>();

            if (String.IsNullOrEmpty(workingDir))
            {
                throw new InvalidOperationException();
            }

            if (!Directory.Exists(workingDir))
            {
                Directory.CreateDirectory(workingDir);
            }
            //string localPart = _locale.ToUpper();

            if (_isSystem)
            {
                _treeFileName  = Path.Combine(workingDir, "MsdnT2.6.10621.1.dat");
                _blockFileName = Path.Combine(workingDir, "MsdnB2.6.10621.1.dat");
                //_treeFileName = Path.Combine(workingDir, "MsdnT" + localPart + "2.6.10621.1.dat");
                //_blockFileName = Path.Combine(workingDir, "MsdnB" + localPart + "2.6.10621.1.dat");
            }
            else
            {
                string tempFile = Path.GetFileNameWithoutExtension(
                    Path.GetTempFileName());

                _treeFileName  = Path.Combine(workingDir, tempFile + "Tree.dat");
                _blockFileName = Path.Combine(workingDir, tempFile + "Block.dat");
                //_treeFileName = Path.Combine(workingDir, tempFile + localPart + "Tree.dat");
                //_blockFileName = Path.Combine(workingDir, tempFile + localPart + "Block.dat");
            }

            if (File.Exists(_treeFileName) && File.Exists(_blockFileName))
            {
                _isExisted = true;
                _plusTree  = hBplusTree.ReOpen(_treeFileName, _blockFileName);
                if (_plusTree.ContainsKey("$DataCount$"))
                {
                    _count = Convert.ToInt32(_plusTree["$DataCount$"]);
                }
            }
            else
            {
                if (createNotFound)
                {
                    _plusTree = hBplusTree.Initialize(_treeFileName,
                                                      _blockFileName, 64);
                }
            }
        }
Exemplo n.º 7
0
        public void ShouldNotErrorWithZeroRecords(
            int pageSize)
        {
            var tree = new BplusTree(pageSize);

            var customers = tree.GetAll();

            customers.Should().HaveCount(0);

            var stringVersion = tree.GetStringVersion();

            stringVersion.Should().BeEmpty();
        }
Exemplo n.º 8
0
        public void RightSplit()
        {
            var tree = new BplusTree(PageCount);

            tree.GetStringVersion().Should().BeEmpty();

            tree.Insert(CreateCustomer(100));
            tree.GetStringVersion().Should().Be("P:100");

            tree.Insert(CreateCustomer(110));
            tree.GetStringVersion().Should().Be("P:100|P:110");

            tree.Insert(CreateCustomer(120));
            tree.GetStringVersion().Should().Be("P:100|I:110|P:110|P:120");

            tree.Insert(CreateCustomer(130));
            tree.GetStringVersion().Should().Be("P:100|I:110|P:110|I:120|P:120|P:130");
        }
Exemplo n.º 9
0
        public void BalancedInsert()
        {
            var tree = new BplusTree(PageCount);

            tree.GetStringVersion().Should().BeEmpty();

            tree.Insert(CreateCustomer(500));
            tree.GetStringVersion().Should().Be("P:500");

            tree.Insert(CreateCustomer(400));
            tree.GetStringVersion().Should().Be("P:400|P:500");

            tree.Insert(CreateCustomer(300));
            tree.GetStringVersion().Should().Be("P:300|I:400|P:400|P:500");

            tree.Insert(CreateCustomer(350));
            tree.GetStringVersion().Should().Be("P:300|P:350|I:400|P:400|P:500");
        }
Exemplo n.º 10
0
 private static void InitKeyValueStore()
 {
     try
     {
         if (File.Exists("services.dat") && File.Exists("services.tree"))
         {
             _tree = BplusTree.ReOpen("services.tree", "services.dat");
         }
         else
         {
             _tree = BplusTree.Initialize("services.tree", "services.dat", 36);
         }
     }
     catch (Exception)
     {
         Log.Error("Error initialising service tree");
         //_tree = BplusTree.Initialize("services.tree", "services.dat", 36);
     }
 }
Exemplo n.º 11
0
        private void OpenSaveFile(string filename, string path)
        {
            if (IsOpen())
            {
                Debug.LogError(
                    $"You are trying to open an already opened save file ('{filename}')");
                return;
            }

            var treeFileName  = Path.Combine(path, filename + ".save");
            var blockFileName = Path.Combine(path, filename + ".block");

            try
            {
                _tree = BplusTree.Initialize(treeFileName, blockFileName, 40);
            }
            catch (IOException)
            {
                try
                {
                    _tree = BplusTree.ReOpen(treeFileName, blockFileName);
                }
                catch (DirectoryNotFoundException e)
                {
                    Debug.LogError(
                        "Error while opening the save file, check that the specified directory exists\n" +
                        e);
                    return;
                }
                catch (IOException e)
                {
                    Debug.LogError(
                        $"Error while opening the save file, check that save file '{filename}' is not already open\n" +
                        e);
                    return;
                }
            }

            _open     = true;
            _filename = filename;
            _path     = path;
        }
Exemplo n.º 12
0
            protected override void Dispose(bool disposing)
            {
                if (_plusTree != null)
                {
                    try
                    {
                        // Save the system reflection database, if newly created...
                        if (_isSystem)
                        {
                            if (!_isExisted)
                            {
                                // Add some metadata...
                                _plusTree["$DataCount$"]   = _count.ToString();
                                _plusTree["$DataVersion$"] = "2.6.10621.1";

                                _plusTree.Commit();
                            }
                        }

                        _plusTree.Shutdown();
                        _plusTree = null;

                        // For the non-system reflection database, delete after use...
                        if (!_isSystem)
                        {
                            if (!String.IsNullOrEmpty(_treeFileName) &&
                                File.Exists(_treeFileName))
                            {
                                File.Delete(_treeFileName);
                            }
                            if (!String.IsNullOrEmpty(_blockFileName) &&
                                File.Exists(_blockFileName))
                            {
                                File.Delete(_blockFileName);
                            }
                        }
                    }
                    catch
                    {
                    }
                }
            }
Exemplo n.º 13
0
        public void ShouldStoreSingleRecord(
            int pageSize)
        {
            var tree = new BplusTree(pageSize);

            var customerRecord = CreateCustomer(100);

            tree.Insert(customerRecord);

            var customers = tree.GetAll();

            customers.Should().HaveCount(1);

            customers[0].CustomerId.Should().Be(100);
            customers[0].Name.Should().Be(customerRecord.Name);

            var stringVersion = tree.GetStringVersion();

            stringVersion.Should().Be("P:100");
        }
Exemplo n.º 14
0
        public void HighLevelIndexSplit()
        {
            var tree = new BplusTree(PageCount);

            tree.GetStringVersion().Should().BeEmpty();

            tree.Insert(CreateCustomer(100));
            tree.GetStringVersion().Should().Be("P:100");

            tree.Insert(CreateCustomer(200));
            tree.GetStringVersion().Should().Be("P:100|P:200");

            tree.Insert(CreateCustomer(300));
            tree.GetStringVersion().Should().Be("P:100|I:200|P:200|P:300");

            tree.Insert(CreateCustomer(110));
            tree.GetStringVersion().Should().Be("P:100|P:110|I:200|P:200|P:300");

            tree.Insert(CreateCustomer(400));
            tree.GetStringVersion().Should().Be("P:100|P:110|I:200|P:200|I:300|P:300|P:400");

            tree.Insert(CreateCustomer(225));
            tree.GetStringVersion().Should().Be("P:100|P:110|I:200|P:200|P:225|I:300|P:300|P:400");

            tree.Insert(CreateCustomer(230));
            tree.GetStringVersion().Should().Be("P:100|P:110|I:200|P:200|I:225|P:225|P:230|I:300|P:300|P:400");

            tree.Insert(CreateCustomer(500));
            tree.GetStringVersion().Should().Be("P:100|P:110|I:200|P:200|I:225|P:225|P:230|I:300|P:300|I:400|P:400|P:500");

            tree.Insert(CreateCustomer(600));
            tree.GetStringVersion().Should().Be("P:100|P:110|I:200|P:200|I:225|P:225|P:230|I:300|P:300|I:400|P:400|I:500|P:500|P:600");

            tree.Insert(CreateCustomer(700));
            tree.GetStringVersion().Should().Be("P:100|P:110|I:200|P:200|I:225|P:225|P:230|I:300|P:300|I:400|P:400|I:500|P:500|I:600|P:600|P:700");

            tree.Insert(CreateCustomer(800));
            tree.GetStringVersion().Should().Be("P:100|P:110|I:200|P:200|I:225|P:225|P:230|I:300|P:300|I:400|P:400|I:500|P:500|I:600|P:600|I:700|P:700|P:800");
        }
Exemplo n.º 15
0
        public void LeftMostSplit()
        {
            var tree = new BplusTree(PageCount);

            tree.GetStringVersion().Should().BeEmpty();

            tree.Insert(CreateCustomer(100));
            tree.GetStringVersion().Should().Be("P:100");

            tree.Insert(CreateCustomer(200));
            tree.GetStringVersion().Should().Be("P:100|P:200");

            tree.Insert(CreateCustomer(300));
            tree.GetStringVersion().Should().Be("P:100|P:200|P:300");

            tree.Insert(CreateCustomer(400));
            tree.GetStringVersion().Should().Be("P:100|P:200|I:300|P:300|P:400");

            tree.Insert(CreateCustomer(250));
            tree.GetStringVersion().Should().Be("P:100|P:200|P:250|I:300|P:300|P:400");

            tree.Insert(CreateCustomer(275));
            tree.GetStringVersion().Should().Be("P:100|P:200|I:250|P:250|P:275|I:300|P:300|P:400");

            tree.Insert(CreateCustomer(225));
            tree.GetStringVersion().Should().Be("P:100|P:200|P:225|I:250|P:250|P:275|I:300|P:300|P:400");

            tree.Insert(CreateCustomer(150));
            tree.GetStringVersion().Should().Be("P:100|P:150|I:200|P:200|P:225|I:250|P:250|P:275|I:300|P:300|P:400");

            tree.Insert(CreateCustomer(175));
            tree.GetStringVersion().Should().Be("P:100|P:150|P:175|I:200|P:200|P:225|I:250|P:250|P:275|I:300|P:300|P:400");

            tree.Insert(CreateCustomer(125));
            tree.GetStringVersion().Should().Be("P:100|P:125|I:150|P:150|P:175|I:200|P:200|P:225|I:250|P:250|P:275|I:300|P:300|P:400");
        }
Exemplo n.º 16
0
        public void MiddleSplit()
        {
            var tree = new BplusTree(PageCount);

            tree.GetStringVersion().Should().BeEmpty();

            tree.Insert(CreateCustomer(100));
            tree.GetStringVersion().Should().Be("P:100");

            tree.Insert(CreateCustomer(110));
            tree.GetStringVersion().Should().Be("P:100|P:110");

            tree.Insert(CreateCustomer(120));
            tree.GetStringVersion().Should().Be("P:100|P:110|P:120");

            tree.Insert(CreateCustomer(130));
            tree.GetStringVersion().Should().Be("P:100|P:110|I:120|P:120|P:130");

            tree.Insert(CreateCustomer(111));
            tree.GetStringVersion().Should().Be("P:100|P:110|P:111|I:120|P:120|P:130");

            tree.Insert(CreateCustomer(112));
            tree.GetStringVersion().Should().Be("P:100|P:110|I:111|P:111|P:112|I:120|P:120|P:130");

            tree.Insert(CreateCustomer(113));
            tree.GetStringVersion().Should().Be("P:100|P:110|I:111|P:111|P:112|P:113|I:120|P:120|P:130");

            tree.Insert(CreateCustomer(114));
            tree.GetStringVersion().Should().Be("P:100|P:110|I:111|P:111|P:112|I:113|P:113|P:114|I:120|P:120|P:130");

            tree.Insert(CreateCustomer(115));
            tree.GetStringVersion().Should().Be("P:100|P:110|I:111|P:111|P:112|I:113|P:113|P:114|P:115|I:120|P:120|P:130");

            tree.Insert(CreateCustomer(116));
            tree.GetStringVersion().Should().Be("P:100|P:110|I:111|P:111|P:112|I:113|P:113|P:114|I:115|P:115|P:116|I:120|P:120|P:130");
        }
Exemplo n.º 17
0
 public WebServer(BplusTree serviceTree)
 {
     _tree = serviceTree;
 }