Beispiel #1
0
 public void ConfirmStatsPart2Case1(HeapStats stats)
 {
     Assert.AreNotEqual(0, stats.nPages);
     Assert.AreEqual(0, stats.MetadataFlags);
     Assert.AreEqual(100, stats.nRecords);
     Assert.AreNotEqual(0, stats.nRegions);
 }
Beispiel #2
0
 public void ConfirmStatsPart1Case1(HeapStats stats)
 {
     Assert.AreNotEqual(0, stats.MagicNumber);
     Assert.AreEqual(4096, stats.PageSize);
     Assert.AreNotEqual(0, stats.RegionSize);
     Assert.AreEqual(2, stats.Version);
 }
Beispiel #3
0
        public void TestStats()
        {
            testName = "TestStats";
            SetUpTest(true);
            string dbFileName = testHome + "/" +
                                testName + ".db";

            HeapDatabaseConfig dbConfig =
                new HeapDatabaseConfig();

            ConfigCase1(dbConfig);
            HeapDatabase db = HeapDatabase.Open(dbFileName, dbConfig);

            HeapStats stats = db.Stats();

            ConfirmStatsPart1Case1(stats);
            db.PrintFastStats(true);

            // Put 500 records into the database.
            PutRecordCase1(db, null);

            stats = db.Stats();
            ConfirmStatsPart2Case1(stats);
            db.PrintFastStats();

            db.Close();
        }
        public void ProcessEvent(EventWrittenEventArgs e)
        {
            if (e.EventId == EventIdAllocTick)
            {
                AllocationTick?.Invoke(Events.AllocationTickEvent.ParseFrom(e));
                return;
            }

            if (e.EventId == EventIdHeapStats)
            {
                HeapStats?.Invoke(Events.HeapStatsEvent.ParseFrom(e));
                return;
            }

            // flags representing the "Garbage Collection" + "Preparation for garbage collection" pause reasons
            const uint suspendGcReasons = 0x1 | 0x6;

            if (e.EventId == EventIdSuspendEEStart && ((uint)e.Payload[0] & suspendGcReasons) == 0)
            {
                // Execution engine is pausing for a reason other than GC, discard event.
                return;
            }

            if (_gcPauseEventTimer.TryGetDuration(e, out var pauseDuration) == DurationResult.FinalWithDuration)
            {
                PauseComplete?.Invoke(Events.PauseCompleteEvent.GetFrom(pauseDuration));
                return;
            }

            if (e.EventId == EventIdGcStart)
            {
                CollectionStart?.Invoke(Events.CollectionStartEvent.ParseFrom(e));
            }

            if (_gcEventTimer.TryGetDuration(e, out var gcDuration, out var gcData) == DurationResult.FinalWithDuration)
            {
                CollectionComplete?.Invoke(Events.CollectionCompleteEvent.GetFrom(gcData.Generation, gcData.Type, gcDuration));
            }
        }
Beispiel #5
0
        public void TestHeapRegionsize()
        {
            /*
             * Check that with a very small region size, the number of regions
             * grows quickly.
             */
            testName = "TestHeapRegionsize";
            SetUpTest(true);

            Random r = new Random();

            byte[] buf = new byte[1024];
            r.NextBytes(buf);

            HeapDatabaseConfig cfg = new HeapDatabaseConfig();

            cfg.Creation   = CreatePolicy.ALWAYS;
            cfg.PageSize   = 512;
            cfg.RegionSize = 4;

            HeapDatabase db = HeapDatabase.Open(
                testHome + "/" + testName + ".db", cfg);
            DatabaseEntry dbt = new DatabaseEntry(buf);

            for (int i = 0; i < 10; i++)
            {
                db.Append(dbt);
            }

            Assert.AreEqual(db.RegionSize, 4);

            HeapStats stats = db.Stats();

            db.Close();

            Assert.AreEqual(stats.RegionSize, 4);
            Assert.Greater(stats.nRegions, 1);
        }
Beispiel #6
0
        /*
         * Test the blob database with or without environment.
         * 1. Config and open the environment;
         * 2. Verify the environment blob configs;
         * 3. Config and open the database;
         * 4. Verify the database blob configs;
         * 5. Insert and verify some blob data by database methods;
         * 6. Verify the stats;
         * 7. Close all handles.
         * If "blobdbt" is true, set the data DatabaseEntry.Blob as
         * true, otherwise make the data DatabaseEntry reach the blob
         * threshold in size.
         */
        void TestBlobHeapDatabase(uint env_threshold, string env_blobdir,
                                  uint db_threshold, string db_blobdir, bool blobdbt)
        {
            if (env_threshold == 0 && db_threshold == 0)
            {
                return;
            }

            string heapDBName =
                testHome + "/" + testName + ".db";

            Configuration.ClearDir(testHome);
            HeapDatabaseConfig cfg = new HeapDatabaseConfig();

            cfg.Creation = CreatePolicy.ALWAYS;
            string blrootdir = "__db_bl";

            // Open the environment and verify the blob configs.
            if (env_threshold > 0)
            {
                DatabaseEnvironmentConfig envConfig =
                    new DatabaseEnvironmentConfig();
                envConfig.AutoCommit    = true;
                envConfig.Create        = true;
                envConfig.UseMPool      = true;
                envConfig.UseLogging    = true;
                envConfig.UseTxns       = true;
                envConfig.UseLocking    = true;
                envConfig.BlobThreshold = env_threshold;
                if (env_blobdir != null)
                {
                    envConfig.BlobDir = env_blobdir;
                    blrootdir         = env_blobdir;
                }
                DatabaseEnvironment env = DatabaseEnvironment.Open(
                    testHome, envConfig);
                if (env_blobdir == null)
                {
                    Assert.IsNull(env.BlobDir);
                }
                else
                {
                    Assert.AreEqual(0,
                                    env.BlobDir.CompareTo(env_blobdir));
                }
                Assert.AreEqual(env_threshold, env.BlobThreshold);
                cfg.Env    = env;
                heapDBName = testName + ".db";
            }

            // Open the database and verify the blob configs.
            if (db_threshold > 0)
            {
                cfg.BlobThreshold = db_threshold;
            }
            if (db_blobdir != null)
            {
                cfg.BlobDir = db_blobdir;

                /*
                 * The blob directory setting in the database
                 * is effective only when it is opened without
                 * an environment.
                 */
                if (cfg.Env == null)
                {
                    blrootdir = db_blobdir;
                }
            }

            HeapDatabase db = HeapDatabase.Open(heapDBName, cfg);

            Assert.AreEqual(
                db_threshold > 0 ? db_threshold : env_threshold,
                db.BlobThreshold);
            if (db_blobdir == null && cfg.Env == null)
            {
                Assert.IsNull(db.BlobDir);
            }
            else
            {
                Assert.AreEqual(0, db.BlobDir.CompareTo(blrootdir));
            }

            // Insert and verify some blob data by database methods.
            string[]      records = { "a", "b", "c", "d", "e", "f", "g", "h",
                                      "i",      "j", "k", "l", "m", "n", "o", "p","q","r", "s",
                                      "t",      "u", "v", "w", "x", "y", "z" };
            DatabaseEntry kdbt = new DatabaseEntry();
            DatabaseEntry ddbt = new DatabaseEntry();

            byte[] ddata;
            string str;
            KeyValuePair <DatabaseEntry, DatabaseEntry> pair;

            ddbt.Blob = blobdbt;
            Assert.AreEqual(blobdbt, ddbt.Blob);
            for (int i = 0; i < records.Length; i++)
            {
                str = records[i];
                if (!blobdbt)
                {
                    for (int j = 0; j < db_threshold; j++)
                    {
                        str = str + records[i];
                    }
                }
                ddata     = Encoding.ASCII.GetBytes(str);
                ddbt.Data = ddata;
                kdbt      = new DatabaseEntry((db.Append(ddbt)).toArray());
                try
                {
                    pair = db.Get(kdbt);
                }
                catch (DatabaseException)
                {
                    db.Close();
                    if (cfg.Env != null)
                    {
                        cfg.Env.Close();
                    }
                    throw new TestException();
                }
                Assert.AreEqual(ddata, pair.Value.Data);
            }

            /*
             * Verify the blob files are created in the expected location.
             * This part of test is disabled since BTreeDatabase.BlobSubDir
             * is not exposed to users.
             */
            //if (cfg.Env != null)
            //	blrootdir = testHome + "/" + blrootdir;
            //string blobdir = blrootdir + "/" + db.BlobSubDir;
            //Assert.AreEqual(records.Length,
            //    Directory.GetFiles(blobdir, "__db.bl*").Length);
            //Assert.AreEqual(1,
            //    Directory.GetFiles(blobdir, "__db_blob_meta.db").Length);

            // Verify the stats.
            HeapStats st = db.Stats();

            Assert.AreEqual(records.Length, st.nBlobRecords);

            // Close all handles.
            db.Close();
            if (cfg.Env != null)
            {
                cfg.Env.Close();
            }

            /*
             * Remove the default blob directory
             * when it is not under the test home.
             */
            if (db_blobdir == null && cfg.Env == null)
            {
                Directory.Delete("__db_bl", true);
            }
        }