public void TestLogVerifyConfig() { testName = "TestLogVerifyConfig"; SetUpTest(true); // Open enviornment. DatabaseEnvironmentConfig cfg = new DatabaseEnvironmentConfig(); cfg.Create = true; cfg.UseLocking = true; cfg.UseLogging = true; cfg.UseMPool = true; cfg.UseTxns = true; DatabaseEnvironment env = DatabaseEnvironment.Open( testHome, cfg); // Open database. Transaction txn = env.BeginTransaction(); BTreeDatabaseConfig dbCfg = new BTreeDatabaseConfig(); dbCfg.Env = env; dbCfg.Creation = CreatePolicy.IF_NEEDED; dbCfg.Duplicates = DuplicatesPolicy.UNSORTED; BTreeDatabase db = BTreeDatabase.Open( testName, dbCfg, txn); txn.Commit(); // Do a lot of transactional operations to create logs. DatabaseEntry key, data; for (int i = 0; i < 5; i++) { txn = env.BeginTransaction(); switch (i) { case 0: /* * Put 1000 records and commit the * transaction. */ for (int j = 0; j < 1000;j++) { key = new DatabaseEntry( BitConverter.GetBytes(j)); data = new DatabaseEntry( BitConverter.GetBytes(j)); db.Put(key, data, txn); } txn.Commit(); break; case 1: /* * Put 10 overflow records and commit * the transaction. */ for (int j = 0; j < 10;j++) { key = new DatabaseEntry( BitConverter.GetBytes(j)); data = new DatabaseEntry( new byte[1024 * 4]); db.Put(key, data, txn); } txn.Commit(); break; case 2: /* * Put 1000 records and abort the * transaction. */ for (int j = 0; j < 1000;j++) { key = new DatabaseEntry( BitConverter.GetBytes(j)); data = new DatabaseEntry( BitConverter.GetBytes(j + 1)); db.Put(key, data, txn); } txn.Abort(); break; case 3: /* * Put 10 overflow records and abort the * transaction. */ for (int j = 10; j < 20;j++) { key = new DatabaseEntry( BitConverter.GetBytes(j)); data = new DatabaseEntry( new byte[1024 * 4]); db.Put(key, data, txn); } txn.Abort(); break; case 4: // Get 100 records. for (int j = 100; j < 200; j++) { key = new DatabaseEntry( BitConverter.GetBytes(j)); data = new DatabaseEntry( BitConverter.GetBytes(j)); db.GetBoth(key, data, txn); } txn.Commit(); break; } } // Verfiy entire log. string tempHome = testHome + "_tmp"; Configuration.ClearDir(tempHome); LogVerifyConfig logVerifyCfg = new LogVerifyConfig(); logVerifyCfg.CacheSize = 1024 * 10; logVerifyCfg.ContinueAfterFail = true; logVerifyCfg.EnvHome = tempHome; logVerifyCfg.Verbose = true; Assert.AreEqual(0, env.LogVerify(logVerifyCfg)); db.Close(); env.Close(); // Verify specific database. logVerifyCfg.DbFile = testName + ".db"; logVerifyCfg.DbName = testName; Assert.AreEqual(0, env.LogVerify(logVerifyCfg)); // Verify partial log. DateTime time = DateTime.Now; DateTime startTime = new DateTime(time.Year, time.Month, time.Day, time.Hour, time.Minute - 2, time.Second); DateTime endTime = new DateTime(time.Year, time.Month, time.Day, time.Hour, time.Minute - 1, time.Second); logVerifyCfg.StartTime = startTime; logVerifyCfg.EndTime = endTime; Assert.AreEqual(0, env.LogVerify(logVerifyCfg)); // Verfiy unexisting log. logVerifyCfg.StartLsn = new LSN(1, 3); logVerifyCfg.EndLsn = new LSN(2, 100); Assert.AreEqual(0, env.LogVerify(logVerifyCfg)); Assert.AreEqual(logVerifyCfg.CacheSize, 1024 * 10); Assert.AreEqual(logVerifyCfg.ContinueAfterFail, true); Assert.AreEqual(logVerifyCfg.DbFile, testName + ".db"); Assert.AreEqual(logVerifyCfg.DbName, testName); Assert.AreEqual(logVerifyCfg.EndLsn.LogFileNumber, 2); Assert.AreEqual(logVerifyCfg.EndLsn.Offset, 100); Assert.AreEqual(logVerifyCfg.EndTime, endTime); Assert.AreEqual(logVerifyCfg.EnvHome, testHome + "_tmp"); Assert.AreEqual(logVerifyCfg.StartLsn.LogFileNumber, 1); Assert.AreEqual(logVerifyCfg.StartLsn.Offset, 3); Assert.AreEqual(logVerifyCfg.StartTime, startTime); Assert.AreEqual(logVerifyCfg.Verbose, true); }
/// <summary> /// Verify log records of this environment. /// </summary> /// <param name="config"> /// Log verification configuration object. /// </param> public int LogVerify(LogVerifyConfig config) { String dbfile, dbname, home; int etime, stime; uint cachesize; uint efile, eoffset, sfile, soffset; int caf, ret, verbose; caf = ret = verbose = 0; etime = stime = 0; home = config.EnvHome; dbfile = config.DbFile; dbname = config.DbName; try { etime = (int)config.EndTime.ToFileTimeUtc(); stime = (int)config.StartTime.ToFileTimeUtc(); } catch (Exception){} efile = config.EndLsn.LogFileNumber; eoffset = config.EndLsn.Offset; sfile = config.StartLsn.LogFileNumber; soffset = config.StartLsn.Offset; cachesize = config.CacheSize; if (config.Verbose) verbose = 1; if (config.ContinueAfterFail) caf = 1; try { ret = dbenv.log_verify(home, cachesize, dbfile, dbname, stime, etime, sfile, soffset, efile, eoffset, caf, verbose); } catch (Exception){} return (ret); }