示例#1
0
        public void TestCreateNewMaster()
        {
            var pm = new FilePersistenceManager();
            var dirName = "TestCreateNewMaster1";
            pm.CreateDirectory(dirName);
            var storeConfig = new StoreConfiguration {PersistenceType = PersistenceType.AppendOnly};
            var storeSetId = Guid.NewGuid();
            var mf = MasterFile.Create(pm, dirName, storeConfig, storeSetId);
            var storeId = mf.StoreId;
            mf = MasterFile.Open(pm, dirName);
            Assert.AreEqual(storeId, mf.StoreId);
            Assert.AreEqual(storeSetId, mf.StoreSetId);
            Assert.AreEqual(StoreType.Standard, mf.StoreType);
            Assert.AreEqual(PersistenceType.AppendOnly, mf.PersistenceType);

            dirName = "TestCreateNewMaster2";
            pm.CreateDirectory(dirName);
            storeConfig.PersistenceType = PersistenceType.Rewrite;
            storeSetId = Guid.NewGuid();
            mf = MasterFile.Create(pm, dirName, storeConfig, storeSetId);
            storeId = mf.StoreId;
            mf = MasterFile.Open(pm, dirName);
            Assert.AreEqual(storeId, mf.StoreId);
            Assert.AreEqual(storeSetId, mf.StoreSetId);
            Assert.AreEqual(StoreType.Standard, mf.StoreType);
            Assert.AreEqual(PersistenceType.Rewrite, mf.PersistenceType);

            // Enumerating commit points of a new master file should not throw an error
            Assert.AreEqual(0, mf.GetCommitPoints().Count());
        }
示例#2
0
        public void TestBatchInsert()
        {
            const int target = 40000000;
            const int batchSize = 50000;
            const int batchCount = target/batchSize;
            // Tests insert of 40 million unique keys in batches of 50,000
            // Reports time for each batch to console.

#if SILVERLIGHT
            var persistenceManager = new IsolatedStoragePersistanceManager();
#else
            var persistenceManager = new FilePersistenceManager();
#endif
            // Create a test batch
            if (!File.Exists("C:\\brightstar\\testdata.dat"))
            {
                MakeTestData();
            }
            var testList = ReadTestData("c:\\brightstar\\testdata.dat");

            // Create empty store
            if (File.Exists("40m_batch.data")) File.Delete("40m_batch.data");
            var pageStore = new AppendOnlyFilePageStore(persistenceManager, "40m_batch.data", 4096, false, false);
            var tree = new BPlusTree(pageStore);
            ulong lastRoot = tree.RootId;
            tree.Save(0, null);
            pageStore.Commit(0ul, null);

            byte[] testBuffer = Encoding.UTF8.GetBytes("Test Buffer");
            var batchTimer = Stopwatch.StartNew();
            int insertedCount = 0;
            var txnId = 1ul;
            for (int i = 0; i < batchCount; i++)
            {
                tree = new BPlusTree(pageStore, lastRoot);
                foreach (var item in testList)
                {
                    var insertKey = (ulong) ((item*batchCount) + i);
                    try
                    {
                        tree.Insert(txnId, insertKey, testBuffer);
                        insertedCount++;
                    }
                    catch (Exception e)
                    {
                        Assert.Fail("Failed to add key {0}. Cause: {1}", insertKey, e);
                    }
                }
                long beforeSave = batchTimer.ElapsedMilliseconds;
                tree.Save(txnId, null);
                lastRoot = tree.RootId;
                pageStore.Commit(txnId, null);
                Console.WriteLine("{0},{1},{2}", insertedCount, beforeSave, batchTimer.ElapsedMilliseconds);
                txnId++;
            }
        }
示例#3
0
        public void TestAppendCommitPoint()
        {
            var pm = new FilePersistenceManager();
            const string dirName = "TestAppendCommitPoint";
            EnsureEmptyDirectory(pm, dirName);

            var storeConfig = new StoreConfiguration {PersistenceType = PersistenceType.AppendOnly};
            var storeSetId = Guid.NewGuid();
            var mf = MasterFile.Create(pm, dirName, storeConfig, storeSetId);
            DateTime commit1Time = DateTime.UtcNow;
            Guid commit1JobId = Guid.NewGuid();
            mf = MasterFile.Open(pm, dirName);
            mf.AppendCommitPoint(new CommitPoint(1ul, 1ul, commit1Time, commit1JobId));
            DateTime commit2Time = DateTime.UtcNow;
            Guid commit2JobId = Guid.NewGuid();
            mf = MasterFile.Open(pm, dirName);
            mf.AppendCommitPoint(new CommitPoint(2ul, 2ul, commit2Time, commit2JobId));

            mf = MasterFile.Open(pm, dirName);
            var allCommits = mf.GetCommitPoints().ToList();
            Assert.AreEqual(2, allCommits.Count);
            Assert.AreEqual(2ul, allCommits[0].CommitNumber);
            Assert.AreEqual(2ul, allCommits[0].LocationOffset);
            Assert.AreEqual(commit2JobId, allCommits[0].JobId);
            Assert.AreEqual(commit2Time.Ticks, allCommits[0].CommitTime.Ticks);

            Assert.AreEqual(1ul, allCommits[1].CommitNumber);
            Assert.AreEqual(1ul, allCommits[1].LocationOffset);
            Assert.AreEqual(commit1JobId, allCommits[1].JobId);
            Assert.AreEqual(commit1Time.Ticks, allCommits[1].CommitTime.Ticks);

            var lastCommit = mf.GetLatestCommitPoint();
            Assert.AreEqual(2ul, lastCommit.CommitNumber);
            Assert.AreEqual(2ul, lastCommit.LocationOffset);
            Assert.AreEqual(commit2JobId, lastCommit.JobId);
            Assert.AreEqual(commit2Time.Ticks, lastCommit.CommitTime.Ticks);

        }
示例#4
0
        public void TestCorruptCommitPoint()
        {
            var pm = new FilePersistenceManager();
            var dirName = "TestCorruptCommitPoint";
            pm.CreateDirectory(dirName);
            var storeConfig = new StoreConfiguration { PersistenceType = PersistenceType.AppendOnly };
            var storeSetId = Guid.NewGuid();
            var mf = MasterFile.Create(pm, dirName, storeConfig, storeSetId);
            DateTime commit1Time = DateTime.UtcNow;
            Guid commit1JobId = Guid.NewGuid();
            mf = MasterFile.Open(pm, dirName);
            mf.AppendCommitPoint(new CommitPoint(1ul, 1ul, commit1Time, commit1JobId));
            DateTime commit2Time = DateTime.UtcNow;
            Guid commit2JobId = Guid.NewGuid();
            mf = MasterFile.Open(pm, dirName);
            mf.AppendCommitPoint(new CommitPoint(2ul, 2ul, commit2Time, commit2JobId));

            mf = MasterFile.Open(pm, dirName);
            var allCommits = mf.GetCommitPoints().ToList();
            Assert.AreEqual(2, allCommits.Count);

            using (var fs = pm.GetOutputStream(Path.Combine(dirName, MasterFile.MasterFileName), FileMode.Open))
            {
                fs.Seek(-250, SeekOrigin.End);
                fs.WriteByte(255);
            }
            // Error in one half of commit point should not cause a problem
            mf = MasterFile.Open(pm, dirName);
            var lastCommit = mf.GetLatestCommitPoint();
            allCommits = mf.GetCommitPoints().ToList();
            Assert.AreEqual(2, allCommits.Count);
            Assert.AreEqual(2ul, lastCommit.CommitNumber);
            Assert.AreEqual(2ul, lastCommit.LocationOffset);
            Assert.AreEqual(commit2JobId, lastCommit.JobId);
            Assert.AreEqual(commit2Time.Ticks, lastCommit.CommitTime.Ticks);

            using(var fs = pm.GetOutputStream(Path.Combine(dirName, MasterFile.MasterFileName), FileMode.Open))
            {
                fs.Seek(-120, SeekOrigin.End);
                fs.WriteByte(255);
            }
            // Error in both halves of commit point should force a rewind to previous commit point
            mf = MasterFile.Open(pm, dirName);
            lastCommit = mf.GetLatestCommitPoint();
            allCommits = mf.GetCommitPoints().ToList();
            Assert.AreEqual(1, allCommits.Count);

            Assert.AreEqual(1ul, lastCommit.CommitNumber);
            Assert.AreEqual(1ul, lastCommit.LocationOffset);
            Assert.AreEqual(commit1JobId, lastCommit.JobId);
            Assert.AreEqual(commit1Time.Ticks, lastCommit.CommitTime.Ticks);

        }