public void TestLoggingSystemStats() { testName = "TestLoggingSystemStats"; SetUpTest(true); string logDir = "./"; Directory.CreateDirectory(testHome + "/" + logDir); DatabaseEnvironmentConfig cfg = new DatabaseEnvironmentConfig(); cfg.Create = true; cfg.UseTxns = true; cfg.AutoCommit = true; cfg.UseLocking = true; cfg.UseMPool = true; cfg.UseLogging = true; cfg.MPoolSystemCfg = new MPoolConfig(); cfg.MPoolSystemCfg.CacheSize = new CacheInfo(0, 1048576, 1); cfg.LogSystemCfg = new LogConfig(); cfg.LogSystemCfg.AutoRemove = false; cfg.LogSystemCfg.BufferSize = 10240; cfg.LogSystemCfg.Dir = logDir; cfg.LogSystemCfg.FileMode = 755; cfg.LogSystemCfg.ForceSync = true; cfg.LogSystemCfg.InMemory = false; cfg.LogSystemCfg.LogBlobContent = false; cfg.LogSystemCfg.MaxFileSize = 1048576; cfg.LogSystemCfg.NoBuffer = false; cfg.LogSystemCfg.RegionSize = 204800; cfg.LogSystemCfg.ZeroOnCreate = true; DatabaseEnvironment env = DatabaseEnvironment.Open(testHome, cfg); LogStats stats = env.LoggingSystemStats(); env.PrintLoggingSystemStats(); Assert.AreEqual(10240, stats.BufferSize); Assert.AreEqual(1, stats.CurrentFile); Assert.AreNotEqual(0, stats.CurrentOffset); Assert.AreEqual(0, stats.FileId); Assert.AreEqual(1048576, stats.FileSize); Assert.AreEqual(0, stats.InitFileId); Assert.AreNotEqual(0, stats.MagicNumber); Assert.AreEqual(0, stats.MaxFileId); Assert.AreNotEqual(0, stats.PermissionsMode); Assert.AreEqual(1, stats.Records); Assert.AreNotEqual(0, stats.RegionLockNoWait); Assert.LessOrEqual(204800, stats.RegionSize); Assert.AreNotEqual(0, stats.Version); Transaction openTxn = env.BeginTransaction(); BTreeDatabaseConfig dbConfig = new BTreeDatabaseConfig(); dbConfig.Creation = CreatePolicy.IF_NEEDED; dbConfig.Env = env; BTreeDatabase db = BTreeDatabase.Open(testName + ".db", dbConfig, openTxn); openTxn.Commit(); Transaction writeTxn = env.BeginTransaction(); byte[] byteArr = new byte[1024]; for (int i = 0; i < 1000; i++) { db.Put(new DatabaseEntry(BitConverter.GetBytes(i)), new DatabaseEntry(byteArr), writeTxn); } writeTxn.Commit(); stats = env.LoggingSystemStats(); Assert.AreNotEqual(0, stats.Bytes); Assert.AreNotEqual(0, stats.BytesSinceCheckpoint); Assert.AreNotEqual(0, stats.DiskFileNumber); Assert.AreNotEqual(0, stats.DiskOffset); Assert.AreNotEqual(0, stats.MaxCommitsPerFlush); Assert.AreNotEqual(0, stats.MBytes); Assert.AreNotEqual(0, stats.MBytesSinceCheckpoint); Assert.AreNotEqual(0, stats.MinCommitsPerFlush); Assert.AreNotEqual(0, stats.OverflowWrites); Assert.AreNotEqual(0, stats.Syncs); Assert.AreNotEqual(0, stats.Writes); Assert.AreEqual(0, stats.Reads); Assert.AreEqual(0, stats.RegionLockWait); stats = env.LoggingSystemStats(true); stats = env.LoggingSystemStats(); Assert.AreEqual(0, stats.Bytes); Assert.AreEqual(0, stats.BytesSinceCheckpoint); Assert.AreEqual(0, stats.MaxCommitsPerFlush); Assert.AreEqual(0, stats.MBytes); Assert.AreEqual(0, stats.MBytesSinceCheckpoint); Assert.AreEqual(0, stats.MinCommitsPerFlush); Assert.AreEqual(0, stats.OverflowWrites); Assert.AreEqual(0, stats.Syncs); Assert.AreEqual(0, stats.Writes); Assert.AreEqual(0, stats.Reads); env.PrintLoggingSystemStats(true, true); db.Close(); env.Close(); }
public void TestLogStatPrint() { testName = "TestLogStatPrint"; SetUpTest(true); string[] messageInfo = new string[] { "Log magic number", "Log version number", "Log record cache size", "Log file mode", "Current log file size", "Initial fileid allocation", "Current fileids in use", "Maximum fileids used", "Records entered into the log", "Log bytes written", "Log bytes written since last checkpoint", "Total log file I/O writes", "Total log file I/O writes due to overflow", "Total log file flushes", "Total log file I/O reads", "Current log file number", "Current log file offset", "On-disk log file number", "On-disk log file offset", "Maximum commits in a log flush", "Minimum commits in a log flush", "Region size", "The number of region locks that required waiting (0%)" }; string logDir = "./"; Directory.CreateDirectory(testHome + "/" + logDir); // Configure and open an environment. DatabaseEnvironmentConfig envConfig = new DatabaseEnvironmentConfig(); envConfig.Create = true; envConfig.UseTxns = true; envConfig.LogSystemCfg = new LogConfig(); envConfig.LogSystemCfg.AutoRemove = false; envConfig.LogSystemCfg.BufferSize = 10240; envConfig.LogSystemCfg.Dir = logDir; envConfig.LogSystemCfg.FileMode = 755; envConfig.LogSystemCfg.ForceSync = true; envConfig.LogSystemCfg.InMemory = false; envConfig.LogSystemCfg.LogBlobContent = false; envConfig.LogSystemCfg.MaxFileSize = 1048576; envConfig.LogSystemCfg.NoBuffer = false; envConfig.LogSystemCfg.NoSync = true; envConfig.LogSystemCfg.RegionSize = 204800; envConfig.LogSystemCfg.ZeroOnCreate = true; DatabaseEnvironment env = DatabaseEnvironment.Open(testHome, envConfig); // Confirm message file does not exist. string messageFile = testHome + "/" + "msgfile"; Assert.AreEqual(false, File.Exists(messageFile)); // Call set_msgfile() of env. env.Msgfile = messageFile; // Print env statistic to message file. env.PrintLoggingSystemStats(); // Confirm message file exists now. Assert.AreEqual(true, File.Exists(messageFile)); env.Msgfile = ""; int counter = 0; string line; line = null; // Read the message file line by line. System.IO.StreamReader file = new System.IO.StreamReader(@"" + messageFile); while ((line = file.ReadLine()) != null) { string[] tempStr = line.Split('\t'); // Confirm the content of the message file. Assert.AreEqual(tempStr[1], messageInfo[counter]); counter++; } Assert.AreNotEqual(counter, 0); file.Close(); env.Close(); }