Пример #1
0
        public void GetCursorWithExplicitTxn(string home,
		    string dbFile, bool ifConfig)
        {
            DatabaseEnvironmentConfig envConfig =
                new DatabaseEnvironmentConfig();
            envConfig.Create = true;
            envConfig.UseTxns = true;
            envConfig.UseMPool = true;
            DatabaseEnvironment env = DatabaseEnvironment.Open(
                home, envConfig);

            Transaction openTxn = env.BeginTransaction();
            RecnoDatabaseConfig dbConfig =
                new RecnoDatabaseConfig();
            dbConfig.Creation = CreatePolicy.IF_NEEDED;
            dbConfig.Env = env;
            RecnoDatabase db = RecnoDatabase.Open(dbFile,
                dbConfig, openTxn);
            openTxn.Commit();

            Transaction cursorTxn = env.BeginTransaction();
            RecnoCursor cursor;
            if (ifConfig == false)
                cursor = db.Cursor(cursorTxn);
            else
                cursor = db.Cursor(new CursorConfig(), cursorTxn);
            cursor.Close();
            cursorTxn.Commit();
            db.Close();
            env.Close();
        }
Пример #2
0
        // Get a cursor in CDS.
        public static void GetCursorInBtreeDBInCDS(
            string home, string name,
            CursorConfig cursorConfig,
            out DatabaseEnvironment env, out BTreeDatabase db,
            out BTreeCursor cursor)
        {
            string dbFileName = name + ".db";

            // Open an environment.
            DatabaseEnvironmentConfig envConfig =
                new DatabaseEnvironmentConfig();
            envConfig.Create = true;
            envConfig.UseCDB = true;
            envConfig.UseMPool = true;
            env = DatabaseEnvironment.Open(home, envConfig);

            /*
             * Open an btree database. The underlying database
             * should be opened with ReadUncommitted if the
             * cursor's isolation degree will be set to be 1.
             */
            BTreeDatabaseConfig dbConfig = new BTreeDatabaseConfig();
            dbConfig.Creation = CreatePolicy.IF_NEEDED;
            dbConfig.Env = env;

            if (cursorConfig.IsolationDegree == Isolation.DEGREE_ONE)
                dbConfig.ReadUncommitted = true;

            db = BTreeDatabase.Open(dbFileName, dbConfig);

            // Get a cursor in the transaction.
            cursor = db.Cursor(cursorConfig);
        }
Пример #3
0
        public static void SetUpEnvWithTxnAndLocking(string envHome,
		    out DatabaseEnvironment env, out Transaction txn,
		    uint maxLock, uint maxLocker, uint maxObject, uint partition)
        {
            // Configure env and locking subsystem.
            LockingConfig lkConfig = new LockingConfig();

            /*
             * If the maximum number of locks/lockers/objects
             * is given, then the LockingConfig is set. Unless,
             * it is not set to any value.
             */
            if (maxLock != 0)
                lkConfig.MaxLocks = maxLock;
            if (maxLocker != 0)
                lkConfig.MaxLockers = maxLocker;
            if (maxObject != 0)
                lkConfig.MaxObjects = maxObject;
            if (partition != 0)
                lkConfig.Partitions = partition;

            DatabaseEnvironmentConfig envConfig =
                new DatabaseEnvironmentConfig();
            envConfig.Create = true;
            envConfig.UseTxns = true;
            envConfig.UseMPool = true;
            envConfig.LockSystemCfg = lkConfig;
            envConfig.UseLocking = true;
            envConfig.NoLocking = false;
            env = DatabaseEnvironment.Open(envHome, envConfig);
            txn = env.BeginTransaction();
        }
Пример #4
0
        /*
         * Open environment, database and write data into database.
         * Generated log files are put under testHome.
         */
        public void Logging(string home, string dbName,
		    out DatabaseEnvironment env, out RecnoDatabase recnoDB)
        {
            string dbFileName = dbName + ".db";

            Configuration.ClearDir(home);

            // Open environment with logging subsystem.
            DatabaseEnvironmentConfig envConfig =
                new DatabaseEnvironmentConfig();
            envConfig.Create = true;
            envConfig.UseLogging = true;
            envConfig.LogSystemCfg = new LogConfig();
            envConfig.LogSystemCfg.FileMode = 755;
            envConfig.LogSystemCfg.ZeroOnCreate = true;
            envConfig.UseMPool = true;
            env = DatabaseEnvironment.Open(home, envConfig);

            /*
             * Open recno database, write 100000 records into
             * the database and close it.
             */
            RecnoDatabaseConfig recnoConfig =
                new RecnoDatabaseConfig();
            recnoConfig.Creation = CreatePolicy.IF_NEEDED;
            recnoConfig.Env = env;
            // The db needs mpool to open.
            recnoConfig.NoMMap = false;
            recnoDB = RecnoDatabase.Open(dbFileName,
                recnoConfig);
            for (int i = 0; i < 1000; i++)
                recnoDB.Append(new DatabaseEntry(
                    ASCIIEncoding.ASCII.GetBytes("key")));
        }
Пример #5
0
 public void EnvConfigCase1(DatabaseEnvironmentConfig cfg)
 {
     cfg.Create = true;
     cfg.UseTxns = true;
     cfg.UseMPool = true;
     cfg.UseLogging = true;
 }
Пример #6
0
        public static void LockingEnvSetUp(string testHome,
            string testName, out DatabaseEnvironment env,
            uint maxLock, uint maxLocker, uint maxObject,
            uint partition)
        {
            // Configure env and locking subsystem.
            LockingConfig lkConfig = new LockingConfig();
            /*
             * If the maximum number of locks/lockers/objects
             * is given, then the LockingConfig is set. Unless,
             * it is not set to any value.
             */
            if (maxLock != 0)
                lkConfig.MaxLocks = maxLock;
            if (maxLocker != 0)
                lkConfig.MaxLockers = maxLocker;
            if (maxObject != 0)
                lkConfig.MaxObjects = maxObject;
            if (partition != 0)
                lkConfig.Partitions = partition;

            DatabaseEnvironmentConfig envConfig =
                new DatabaseEnvironmentConfig();
            envConfig.Create = true;
            envConfig.LockSystemCfg = lkConfig;
            envConfig.UseLocking = true;
            envConfig.ErrorPrefix = testName;

            env = DatabaseEnvironment.Open(testHome, envConfig);
        }
Пример #7
0
        /*
         * Set up environment.
         */
        public static int SetUpEnv(string home, string data_dir)
        {
            DatabaseEnvironment env;
            DatabaseEnvironmentConfig envConfig;

            /* Configure an environment. */
            envConfig = new DatabaseEnvironmentConfig();
            envConfig.MPoolSystemCfg = new MPoolConfig();
            envConfig.MPoolSystemCfg.CacheSize = new CacheInfo(
                0, 64 * 1024, 1);
            envConfig.Create = true;
            envConfig.DataDirs.Add(data_dir);
            envConfig.CreationDir = data_dir;
            envConfig.ErrorPrefix = progName;
            envConfig.UseLogging = true;
            envConfig.UseLocking = true;
            envConfig.UseMPool = true;
            envConfig.UseTxns = true;

            /* Create and open the environment. */
            try {
                env = DatabaseEnvironment.Open(home, envConfig);
            } catch (Exception e) {
                Console.WriteLine("{0}", e.Message);
                return EXIT_FAILURE;
            }

            Console.ReadLine();
            env.Close();
            return EXIT_SUCCESS;
        }
Пример #8
0
        public void GetCursorWithImplicitTxn(string home, 
		    string dbFile, bool ifConfig)
        {
            DatabaseEnvironmentConfig envConfig =
                new DatabaseEnvironmentConfig();
            envConfig.Create = true;
            envConfig.UseCDB = true;
            envConfig.UseMPool = true;
            DatabaseEnvironment env = DatabaseEnvironment.Open(
                home, envConfig);

            RecnoDatabaseConfig dbConfig =
                new RecnoDatabaseConfig();
            dbConfig.Creation = CreatePolicy.IF_NEEDED;
            dbConfig.Env = env;
            RecnoDatabase db = RecnoDatabase.Open(dbFile,
                dbConfig);

            RecnoCursor cursor;
            if (ifConfig == false)
                cursor = db.Cursor();
            else
                cursor = db.Cursor(new CursorConfig());

            cursor.Close();
            db.Close();
            env.Close();
        }
Пример #9
0
 public static RepQuoteEnvironment Open(string home, DatabaseEnvironmentConfig cfg)
 {
     RepQuoteEnvironment dbEnv = new RepQuoteEnvironment();
     dbEnv.env = DatabaseEnvironment.Open(home, cfg);
     dbEnv._appFinished = false;
     dbEnv._inClientSync = false;
     dbEnv._isMaster = false;
     return dbEnv;
 }
        public DatabaseEnvironment SetUpEnv(String home, uint priority, uint port, bool isMaster)
        {
            try    {
                Configuration.ClearDir(home);
            } catch (Exception e)    {
                Console.WriteLine(e.Message);
                throw new TestException("Please clean the directory");
            }

            /* Configure and open environment with replication
             * application.
             */
            DatabaseEnvironmentConfig cfg =
                new DatabaseEnvironmentConfig();
            cfg.UseReplication = true;
            cfg.MPoolSystemCfg = new MPoolConfig();
            cfg.MPoolSystemCfg.CacheSize =
                new CacheInfo(0, 20485760, 1);
            cfg.UseLocking = true;
            cfg.UseTxns = true;
            cfg.UseMPool = true;
            cfg.Create = true;
            cfg.UseLogging = true;
            cfg.RunRecovery = true;
            cfg.TxnNoSync = true;
            cfg.FreeThreaded = true;

            cfg.RepSystemCfg = new ReplicationConfig();
            DbSiteConfig dbSiteConfig = new DbSiteConfig();
            dbSiteConfig.Host = ip;
            dbSiteConfig.Port = port;
            dbSiteConfig.LocalSite = true;
            cfg.RepSystemCfg.RepmgrSitesConfig.Add(dbSiteConfig);
            cfg.RepSystemCfg.Priority = priority;
            if (!isMaster) {
                DbSiteConfig dbSiteConfig1 = new DbSiteConfig();
                dbSiteConfig1.Host = ip;
                dbSiteConfig1.Port = masterPort;
                dbSiteConfig1.Helper = true;
                cfg.RepSystemCfg.RepmgrSitesConfig.Add(dbSiteConfig1);
            }
            cfg.RepSystemCfg.BulkTransfer = false;
            cfg.RepSystemCfg.AckTimeout = 5000;

            cfg.RepSystemCfg.RepMgrAckPolicy =
                AckPolicy.ALL_PEERS;

            DatabaseEnvironment env = DatabaseEnvironment.Open(
                home, cfg);

            return env;
        }
        public void GetSecondaryCursurWithTxn(string home,
		    string name, bool ifCfg)
        {
            string dbFileName = name + ".db";
            SecondaryCursor cursor;

            // Open env.
            DatabaseEnvironmentConfig envConfig =
                new DatabaseEnvironmentConfig();
            envConfig.Create = true;
            envConfig.UseTxns = true;
            envConfig.UseMPool = true;
            DatabaseEnvironment env = DatabaseEnvironment.Open(home,
                envConfig);

            // Open primary/secondary database.
            Transaction txn = env.BeginTransaction();
            BTreeDatabaseConfig dbConfig = new BTreeDatabaseConfig();
            dbConfig.Creation = CreatePolicy.IF_NEEDED;
            dbConfig.Env = env;
            BTreeDatabase db = BTreeDatabase.Open(dbFileName,
                dbConfig, txn);

            SecondaryBTreeDatabaseConfig secDBConfig = new
                SecondaryBTreeDatabaseConfig(db,
                new SecondaryKeyGenDelegate(SecondaryKeyGen));
            secDBConfig.Env = env;
            SecondaryBTreeDatabase secDB =
                SecondaryBTreeDatabase.Open(dbFileName,
                secDBConfig, txn);

            for (int i = 0; i < 10; i++)
                db.Put(new DatabaseEntry(BitConverter.GetBytes(i)),
                    new DatabaseEntry(BitConverter.GetBytes((int)i)), txn);

            // Create secondary cursor.
            if (ifCfg == false)
                secDB.SecondaryCursor(txn);
            else if (ifCfg == true)
            {
                CursorConfig cursorConfig = new CursorConfig();
                cursorConfig.WriteCursor = false;
                cursor = secDB.SecondaryCursor(cursorConfig, txn);
                cursor.Close();
            }

            secDB.Close();
            db.Close();
            txn.Commit();
            env.Close();
        }
Пример #12
0
        /*
         * Create and open environment and database.
         */
        public static int DBInit(out DatabaseEnvironment env,
            string home, string progName, uint maxLock,
            uint doUnLink)
        {
            DatabaseEnvironmentConfig envConfig;
            LockingConfig lkConfig;

            /* Configure locking subsystem. */
            lkConfig = new LockingConfig();
            lkConfig.MaxLocks = maxLock;

            /* Configure environment. */
            envConfig = new DatabaseEnvironmentConfig();
            envConfig.Create = true;
            envConfig.ErrorPrefix = progName;
            envConfig.LockSystemCfg = lkConfig;
            envConfig.UseLocking = true;

            /*
             * Optionally remove the environment region and
             * open the environment.
             */
            try {
                if (doUnLink == 1)
                    DatabaseEnvironment.Remove(home, true);
                env = DatabaseEnvironment.Open(home, envConfig);
            } catch (Exception e) {
                Console.WriteLine("{0}:{1}\n{2}",
                    e.Source, e.Message, e.StackTrace);
                env = null;
                return EXIT_FAILURE;
            }

            /*
            try
            {
                env = DatabaseEnvironment.Open(home, envConfig);
            }
            catch(Exception e)
            {
                Console.WriteLine("{0}:{1}\n{2}",
                    e.Source, e.Message, e.StackTrace);
                env = null;
                return ExConstants.EXIT_FAILURE;
            }
            */

            return EXIT_SUCCESS;
        }
Пример #13
0
        public void TestGetAndFreeMutex()
        {
            testName = "TestGetAndFreeMutex";
            SetUpTest(true);

            DatabaseEnvironmentConfig envConfig =
                new DatabaseEnvironmentConfig();
            envConfig.Create = true;
            envConfig.UseMPool = true;
            DatabaseEnvironment env = DatabaseEnvironment.Open(
                testHome, envConfig);
            BerkeleyDB.Mutex mutex = env.GetMutex(true, true);
            mutex.Dispose();
            env.Close();
        }
Пример #14
0
        public void TestGetAndFreeMutex()
        {
            testName = "TestGetAndFreeMutex";
            testHome = testFixtureHome + "/" + testName;
            Configuration.ClearDir(testHome);

            DatabaseEnvironmentConfig envConfig =
                new DatabaseEnvironmentConfig();
            envConfig.Create = true;
            envConfig.UseMPool = true;
            DatabaseEnvironment env = DatabaseEnvironment.Open(
                testHome, envConfig);
            BerkeleyDB.Mutex mutex = env.GetMutex(true, true);
            mutex.Dispose();
            env.Close();
        }
Пример #15
0
        public void OpenNewSequenceInEnv(string home, string dbname,
		    out DatabaseEnvironment env, out BTreeDatabase db,
		    out Sequence seq)
        {
            DatabaseEnvironmentConfig envConfig =
                new DatabaseEnvironmentConfig();
            envConfig.Create = true;
            envConfig.UseTxns = true;
            envConfig.UseMPool = true;
            envConfig.UseLogging = true;
            env = DatabaseEnvironment.Open(home, envConfig);

            Transaction openTxn = env.BeginTransaction();
            BTreeDatabaseConfig dbConfig =
                new BTreeDatabaseConfig();
            dbConfig.Creation = CreatePolicy.IF_NEEDED;
            dbConfig.Env = env;
            db = BTreeDatabase.Open(dbname + ".db", dbConfig,
                openTxn);
            openTxn.Commit();

            Transaction seqTxn = env.BeginTransaction();
            SequenceConfig seqConfig = new SequenceConfig();
            seqConfig.BackingDatabase = db;
            seqConfig.Creation = CreatePolicy.ALWAYS;
            seqConfig.Decrement = false;
            seqConfig.FreeThreaded = true;
            seqConfig.Increment = true;
            seqConfig.InitialValue = 0;
            seqConfig.key = new DatabaseEntry(
                ASCIIEncoding.ASCII.GetBytes("key"));
            seqConfig.SetRange(Int64.MinValue, Int64.MaxValue);
            seqConfig.Wrap = true;
            seq = new Sequence(seqConfig);
            seqTxn.Commit();
        }
Пример #16
0
        public void MoveWithRMW(string home, string name)
        {
            paramEnv = null;
            paramDB = null;

            // Open the environment.
            DatabaseEnvironmentConfig envCfg =
                new DatabaseEnvironmentConfig();
            envCfg.Create = true;
            envCfg.FreeThreaded = true;
            envCfg.UseLocking = true;
            envCfg.UseLogging = true;
            envCfg.UseMPool = true;
            envCfg.UseTxns = true;
            paramEnv = DatabaseEnvironment.Open(home, envCfg);

            // Open database in transaction.
            Transaction openTxn = paramEnv.BeginTransaction();
            BTreeDatabaseConfig cfg = new BTreeDatabaseConfig();
            cfg.Creation = CreatePolicy.ALWAYS;
            cfg.Env = paramEnv;
            cfg.FreeThreaded = true;
            cfg.PageSize = 4096;
            cfg.Duplicates = DuplicatesPolicy.UNSORTED;
            paramDB = BTreeDatabase.Open(name + ".db", cfg, openTxn);
            openTxn.Commit();

            /*
             * Put 10 different, 2 duplicate and another different
             * records into database.
             */
            Transaction txn = paramEnv.BeginTransaction();
            for (int i = 0; i < 13; i++)
            {
                DatabaseEntry key, data;
                if (i == 10 || i == 11)
                {
                    key = new DatabaseEntry(
                        ASCIIEncoding.ASCII.GetBytes("key"));
                    data = new DatabaseEntry(
                        ASCIIEncoding.ASCII.GetBytes("data"));
                }
                else
                {
                    key = new DatabaseEntry(
                        BitConverter.GetBytes(i));
                    data = new DatabaseEntry(
                        BitConverter.GetBytes(i));
                }
                paramDB.Put(key, data, txn);
            }

            txn.Commit();

            // Get a event wait handle.
            signal = new EventWaitHandle(false, EventResetMode.ManualReset);

            /*
             * Start RdMfWt() in two threads. RdMfWt() reads
             * and writes data into database.
             */
            Thread t1 = new Thread(new ThreadStart(RdMfWt));
            Thread t2 = new Thread(new ThreadStart(RdMfWt));
            t1.Start();
            t2.Start();

            /*
             * Give both threads time to read before signalling
             * them to write.
             */
            Thread.Sleep(1000);

            // Invoke the write operation in both threads.
            signal.Set();

            // Return the number of deadlocks.
            while (t1.IsAlive || t2.IsAlive)
            {
                /*
                 * Give both threads time to write before
                 * counting the number of deadlocks.
                 */
                Thread.Sleep(1000);
                uint deadlocks = paramEnv.DetectDeadlocks(
                   DeadlockPolicy.DEFAULT);

                // Confirm that there won't be any deadlock.
                Assert.AreEqual(0, deadlocks);
            }

            t1.Join();
            t2.Join();
            paramDB.Close();
            paramEnv.Close();
        }
Пример #17
0
        public void TestSnapshotIsolation()
        {
            BTreeDatabaseConfig dbConfig;
            DatabaseEntry key, data;
            DatabaseEnvironmentConfig envConfig;
            Thread readThread, updateThread;
            Transaction txn;

            updateTxn = null;
            readTxn = null;
            paramDB = null;
            paramEnv = null;
            testName = "TestSnapshotIsolation";
            testHome = testFixtureHome + "/" + testName;

            Configuration.ClearDir(testHome);

            /*
             * Open environment with DB_MULTIVERSION
             * which is required by DB_TXN_SNAPSHOT.
             */
            envConfig = new DatabaseEnvironmentConfig();
            envConfig.Create = true;
            envConfig.UseMVCC = true;
            envConfig.UseTxns = true;
            envConfig.UseMPool = true;
            envConfig.UseLocking = true;
            envConfig.TxnTimeout = 1000;
            paramEnv = DatabaseEnvironment.Open(
                testHome, envConfig);
            paramEnv.DetectDeadlocks(DeadlockPolicy.YOUNGEST);

            /*
             * Open a transactional database and put 1000 records
             * into it within transaction.
             */
            txn = paramEnv.BeginTransaction();
            dbConfig = new BTreeDatabaseConfig();
            dbConfig.Creation = CreatePolicy.IF_NEEDED;
            dbConfig.UseMVCC = true;
            dbConfig.Env = paramEnv;
            paramDB = BTreeDatabase.Open(
                testName + ".db", dbConfig, txn);
            for (int i = 0; i < 256; i++)
            {
                key = new DatabaseEntry(
                    BitConverter.GetBytes(i));
                data = new DatabaseEntry(
                    BitConverter.GetBytes(i));
                paramDB.Put(key, data, txn);
            }
            txn.Commit();

            /*
             * Begin two threads, read and update thread.
             * The update thread runs a update transaction
             * using full read/write locking. The read thread
             * set DB_TXN_SNAPSHOT on read-only cursor.
             */
            readThread = new Thread(new ThreadStart(ReadTxn));
            updateThread = new Thread(new ThreadStart(UpdateTxn));
            updateThread.Start();
            Thread.Sleep(1000);
            readThread.Start();
            readThread.Join();
            updateThread.Join();

            // Commit transacion in both two threads.
            if (updateTxn != null)
                updateTxn.Commit();
            if (readTxn != null)
                readTxn.Commit();

            /*
             * Confirm that the overwrite operation works.
             */
            ConfirmOverwrite();

            paramDB.Close();
            paramEnv.Close();
        }
        public static void Config(XmlElement xmlElement,
		    ref DatabaseEnvironmentConfig envConfig, bool compulsory)
        {
            uint value = new uint();
            DateTime time = new DateTime();

            Configuration.ConfigBool(xmlElement, "AutoCommit",
                ref envConfig.AutoCommit, compulsory);
            Configuration.ConfigBool(xmlElement, "CDB_ALLDB",
                ref envConfig.CDB_ALLDB, compulsory);
            Configuration.ConfigBool(xmlElement, "Create",
                ref envConfig.Create, compulsory);
            Configuration.ConfigString(xmlElement, "CreationDir",
                ref envConfig.CreationDir, compulsory);
            Configuration.ConfigStringList(xmlElement, "DataDirs",
                ref envConfig.DataDirs, compulsory);
            Configuration.ConfigString(xmlElement, "ErrorPrefix",
                ref envConfig.ErrorPrefix, compulsory);
            Configuration.ConfigBool(xmlElement, "ForceFlush",
                ref envConfig.ForceFlush, compulsory);
            Configuration.ConfigBool(xmlElement, "FreeThreaded",
                ref envConfig.FreeThreaded, compulsory);
            Configuration.ConfigBool(xmlElement, "InitRegions",
                ref envConfig.InitRegions, compulsory);
            Configuration.ConfigString(xmlElement, "IntermediateDirMode",
                ref envConfig.IntermediateDirMode, compulsory);
            Configuration.ConfigBool(xmlElement, "Lockdown",
                ref envConfig.Lockdown, compulsory);
            if (Configuration.ConfigUint(xmlElement, "LockTimeout",
                ref value, compulsory))
                envConfig.LockTimeout = value;
            if (Configuration.ConfigUint(xmlElement, "MaxTransactions",
                ref value, compulsory))
                envConfig.MaxTransactions = value;
            Configuration.ConfigBool(xmlElement, "NoBuffer",
                ref envConfig.NoBuffer, compulsory);
            Configuration.ConfigBool(xmlElement, "NoLocking",
                ref envConfig.NoLocking, compulsory);
            Configuration.ConfigBool(xmlElement, "NoMMap",
                ref envConfig.NoMMap, compulsory);
            Configuration.ConfigBool(xmlElement, "NoLocking",
                ref envConfig.NoLocking, compulsory);
            Configuration.ConfigBool(xmlElement, "NoPanic",
                ref envConfig.NoPanic, compulsory);
            Configuration.ConfigBool(xmlElement, "Overwrite",
                ref envConfig.Overwrite, compulsory);
            Configuration.ConfigBool(xmlElement, "Private",
                ref envConfig.Private, compulsory);
            Configuration.ConfigBool(xmlElement, "Register",
                ref envConfig.Register, compulsory);
            Configuration.ConfigBool(xmlElement, "RunFatalRecovery",
                ref envConfig.RunFatalRecovery, compulsory);
            Configuration.ConfigBool(xmlElement, "RunRecovery",
                ref envConfig.RunRecovery, compulsory);
            Configuration.ConfigBool(xmlElement, "SystemMemory",
                ref envConfig.SystemMemory, compulsory);
            Configuration.ConfigString(xmlElement, "TempDir",
                ref envConfig.TempDir, compulsory);
            Configuration.ConfigBool(xmlElement, "TimeNotGranted",
                ref envConfig.TimeNotGranted, compulsory);
            Configuration.ConfigBool(xmlElement, "TxnNoSync",
                ref envConfig.TxnNoSync, compulsory);
            Configuration.ConfigBool(xmlElement, "TxnNoWait",
                ref envConfig.TxnNoWait, compulsory);
            Configuration.ConfigBool(xmlElement, "TxnSnapshot",
                ref envConfig.TxnSnapshot, compulsory);
            if (Configuration.ConfigDateTime(xmlElement, "TxnTimestamp",
                ref time, compulsory))
                envConfig.TxnTimestamp = time;
            Configuration.ConfigBool(xmlElement, "TxnWriteNoSync",
                ref envConfig.TxnWriteNoSync, compulsory);
            Configuration.ConfigBool(xmlElement, "UseLocking",
                ref envConfig.UseLocking, compulsory);
            Configuration.ConfigBool(xmlElement, "UseLogging",
                ref envConfig.UseLogging, compulsory);
            Configuration.ConfigBool(xmlElement, "UseMPool",
                ref envConfig.UseMPool, compulsory);
            Configuration.ConfigBool(xmlElement, "UseMVCC",
                ref envConfig.UseMVCC, compulsory);
            Configuration.ConfigBool(xmlElement, "UseReplication",
                ref envConfig.UseReplication, compulsory);
            Configuration.ConfigBool(xmlElement, "UseTxns",
                ref envConfig.UseTxns, compulsory);
            envConfig.Verbosity = new VerboseMessages();
            Configuration.ConfigVerboseMessages(xmlElement,
                "Verbosity", ref envConfig.Verbosity, compulsory);
            Configuration.ConfigBool(xmlElement, "YieldCPU",
                ref envConfig.YieldCPU, compulsory);
        }
        public void TestSetEncryption()
        {
            testName = "TestSetEncryption";
            SetUpTest(true);

            DatabaseEnvironmentConfig envConfig =
                new DatabaseEnvironmentConfig();
            envConfig.Create = true;
            envConfig.SetEncryption("key", EncryptionAlgorithm.AES);
            Assert.AreEqual("key", envConfig.EncryptionPassword);
            Assert.AreEqual(EncryptionAlgorithm.AES, envConfig.EncryptAlgorithm);
            DatabaseEnvironment env = DatabaseEnvironment.Open(
                testHome, envConfig);
            Assert.AreEqual(EncryptionAlgorithm.AES, env.EncryptAlgorithm);
            env.Close();
        }
 public void TestConfigReplication()
 {
     testName = "TestConfigReplication";
     SetUpTest(false);
     XmlElement xmlElem = Configuration.TestSetUp(
         testFixtureName, testName);
     DatabaseEnvironmentConfig cfg =
         new DatabaseEnvironmentConfig();
     cfg.RepSystemCfg = new ReplicationConfig();
     ReplicationConfigTest.Config(xmlElem,
         ref cfg.RepSystemCfg, true);
     ReplicationConfigTest.Confirm(xmlElem,
         cfg.RepSystemCfg, true);
 }
        public void OpenSecRecnoDBWithinTxn(string className,
		    string funName, string home, string dbFileName,
		    string dbSecFileName, bool ifDbName)
        {
            XmlElement xmlElem = Configuration.TestSetUp(
                className, funName);

            // Open an environment.
            DatabaseEnvironmentConfig envConfig =
                new DatabaseEnvironmentConfig();
            envConfig.Create = true;
            envConfig.UseTxns = true;
            envConfig.UseMPool = true;
            envConfig.UseLogging = true;
            DatabaseEnvironment env = DatabaseEnvironment.Open(
                home, envConfig);

            // Open a primary recno database.
            Transaction openDBTxn = env.BeginTransaction();
            RecnoDatabaseConfig dbConfig =
                new RecnoDatabaseConfig();
            dbConfig.Creation = CreatePolicy.IF_NEEDED;

            dbConfig.Env = env;
            RecnoDatabase db = RecnoDatabase.Open(
                dbFileName, dbConfig, openDBTxn);
            openDBTxn.Commit();

            // Open a secondary recno database.
            Transaction openSecTxn = env.BeginTransaction();
            SecondaryRecnoDatabaseConfig secDBConfig =
                new SecondaryRecnoDatabaseConfig(db,
                new SecondaryKeyGenDelegate(SecondaryKeyGen));
            SecondaryRecnoDatabaseConfigTest.Config(xmlElem,
                ref secDBConfig, false);
            secDBConfig.Env = env;
            SecondaryRecnoDatabase secDB;
            if (ifDbName == false)
                secDB = SecondaryRecnoDatabase.Open(
                    dbSecFileName, secDBConfig, openSecTxn);
            else
                secDB = SecondaryRecnoDatabase.Open(
                    dbSecFileName, "secondary", secDBConfig,
                    openSecTxn);
            openSecTxn.Commit();

            // Confirm its flags configured in secDBConfig.
            Confirm(xmlElem, secDB, true);
            secDB.Close();

            // Open the existing secondary database.
            Transaction secTxn = env.BeginTransaction();
            SecondaryDatabaseConfig secConfig =
                new SecondaryDatabaseConfig(db,
                new SecondaryKeyGenDelegate(SecondaryKeyGen));
            secConfig.Env = env;

            SecondaryDatabase secExDB;
            if (ifDbName == false)
                secExDB = SecondaryRecnoDatabase.Open(
                    dbSecFileName, secConfig, secTxn);
            else
                secExDB = SecondaryRecnoDatabase.Open(
                    dbSecFileName, "secondary", secConfig,
                    secTxn);
            secExDB.Close();
            secTxn.Commit();

            db.Close();
            env.Close();
        }
        public void OpenSecDBWithinTxn(string home,
		    string dbFileName, string dbSecFileName, bool ifDbName)
        {
            // Open an environment.
            DatabaseEnvironmentConfig envConfig =
                new DatabaseEnvironmentConfig();
            envConfig.Create = true;
            envConfig.UseTxns = true;
            envConfig.UseMPool = true;
            envConfig.UseLogging = true;
            envConfig.UseLocking = true;
            DatabaseEnvironment env = DatabaseEnvironment.Open(
                home, envConfig);

            // Open a primary btree database.
            Transaction openDBTxn = env.BeginTransaction();
            BTreeDatabaseConfig dbConfig =
                new BTreeDatabaseConfig();
            dbConfig.Creation = CreatePolicy.IF_NEEDED;
            dbConfig.Env = env;
            BTreeDatabase db = BTreeDatabase.Open(
                dbFileName, dbConfig, openDBTxn);

            // Open a secondary btree database.
            SecondaryBTreeDatabaseConfig secDBConfig =
                new SecondaryBTreeDatabaseConfig(db,
                new SecondaryKeyGenDelegate(SecondaryKeyGen));
            secDBConfig.Env = env;
            secDBConfig.Creation = CreatePolicy.IF_NEEDED;

            SecondaryBTreeDatabase secDB;
            if (ifDbName == false)
                secDB = SecondaryBTreeDatabase.Open(
                    dbSecFileName, secDBConfig, openDBTxn);
            else
                secDB = SecondaryBTreeDatabase.Open(
                    dbSecFileName, "secondary", secDBConfig,
                    openDBTxn);
            openDBTxn.Commit();
            secDB.Close();

            // Open the existing secondary database.
            Transaction secTxn = env.BeginTransaction();
            SecondaryDatabaseConfig secConfig =
                new SecondaryDatabaseConfig(db,
                new SecondaryKeyGenDelegate(SecondaryKeyGen));
            secConfig.Env = env;

            SecondaryDatabase secExDB;
            if (ifDbName == false)
                secExDB = SecondaryBTreeDatabase.Open(
                    dbSecFileName, secConfig, secTxn);
            else
                secExDB = SecondaryBTreeDatabase.Open(
                    dbSecFileName, "secondary", secConfig,
                    secTxn);
            secExDB.Close();
            secTxn.Commit();

            db.Close();
            env.Close();
        }
 public void TestConfig()
 {
     testName = "TestConfig";
     SetUpTest(false);
     XmlElement xmlElem = Configuration.TestSetUp(
         testFixtureName, testName);
     DatabaseEnvironmentConfig envConfig =
         new DatabaseEnvironmentConfig();
     Config(xmlElem, ref envConfig, true);
     Confirm(xmlElem, envConfig, true);
 }
Пример #24
0
        private void Open()
        {
            Console.WriteLine("Opening environment and database");

            // Set up the environment.
            DatabaseEnvironmentConfig envCfg = new DatabaseEnvironmentConfig();
            envCfg.Create = true;
            envCfg.UseMPool = true;
            envCfg.UseLocking = true;
            envCfg.UseLogging = true;
            envCfg.UseTxns = true;

            // Allow multiple threads visit to the environment handle.
            envCfg.FreeThreaded = true;

            if (inMem)
                envCfg.Private = true;
            else
                envCfg.RunRecovery = true;

            /*
             * Indicate that we want db to internally perform
             * deadlock detection, aborting the transaction that
             * has performed the least amount of WriteData activity
             * in the event of a deadlock.
             */
            envCfg.LockSystemCfg = new LockingConfig();
            envCfg.LockSystemCfg.DeadlockResolution =
                DeadlockPolicy.MIN_WRITE;

            if (inMem) {
                // Specify in-memory logging.
                envCfg.LogSystemCfg = new LogConfig();
                envCfg.LogSystemCfg.InMemory = true;

                /*
                 * Specify the size of the in-memory log buffer
                 * Must be large enough to handle the log data
                 * created by the largest transaction.
                 */
                envCfg.LogSystemCfg.BufferSize = 10 * 1024 * 1024;

                /*
                 * Specify the size of the in-memory cache,
                 * large enough to avoid paging to disk.
                 */
                envCfg.MPoolSystemCfg = new MPoolConfig();
                envCfg.MPoolSystemCfg.CacheSize =
                    new CacheInfo(0, 10 * 1024 * 1024, 1);
            }

            // Set up the database.
            BTreeDatabaseConfig dbCfg = new BTreeDatabaseConfig();
            dbCfg.AutoCommit = true;
            dbCfg.Creation = CreatePolicy.IF_NEEDED;
            dbCfg.Duplicates = DuplicatesPolicy.SORTED;
            dbCfg.FreeThreaded = true;
            dbCfg.ReadUncommitted = true;

            /*
                         * Open the environment. Any errors will be caught
                         * by the caller.
                         */
            env = DatabaseEnvironment.Open(home, envCfg);

            /*
             * Open the database. Do not provide a txn handle. This
             * Open is autocommitted because BTreeDatabaseConfig.AutoCommit
             * is true.
             */
            dbCfg.Env = env;
            db = BTreeDatabase.Open(dbName, dbCfg);
        }
Пример #25
0
        public int init(RepConfig config)
        {
            int ret = 0;

            DatabaseEnvironmentConfig envConfig = new DatabaseEnvironmentConfig();
            envConfig.ErrorPrefix = RepConfig.progname;
            envConfig.RepSystemCfg = new ReplicationConfig();

            envConfig.RepSystemCfg.RepmgrSitesConfig.Add(config.localSite);
            for (int i = 0; i < config.remoteSites.Count; i++)
                envConfig.RepSystemCfg.RepmgrSitesConfig.Add(config.remoteSites[i]);

            envConfig.RepSystemCfg.BulkTransfer = config.bulk;

            /*
             * Configure heartbeat timeouts so that repmgr monitors the
             * health of the TCP connection.  Master sites broadcast a heartbeat
             * at the frequency specified by the DB_REP_HEARTBEAT_SEND timeout.
             * Client sites wait for message activity the length of the
             * DB_REP_HEARTBEAT_MONITOR timeout before concluding that the
             * connection to the master is lost.  The DB_REP_HEARTBEAT_MONITOR
             * timeout should be longer than the DB_REP_HEARTBEAT_SEND timeout.
             */
            envConfig.RepSystemCfg.HeartbeatMonitor = 10000000;
            envConfig.RepSystemCfg.HeartbeatSend = 5000000;

            /*
             * Set replication group election priority for this environment.
             * An election first selects the site with the most recent log
             * records as the new master.  If multiple sites have the most
             * recent log records, the site with the highest priority value
             * is selected as master.
             */
            envConfig.RepSystemCfg.Priority = config.priority;
            envConfig.MPoolSystemCfg = new MPoolConfig();
            envConfig.MPoolSystemCfg.CacheSize = RepConfig.CACHESIZE;
            envConfig.TxnNoSync = true;

            envConfig.EventNotify = new EventNotifyDelegate(RepQuoteEventHandler);

            /*
             * Set the policy that determines how master and client sites
             * handle acknowledgement of replication messages needed for
             * permanent records.  The default policy of "quorum" requires only
             * a quorum of electable peers sufficient to ensure a permanent
             * record remains durable if an election is held.  The "all" option
             * requires all clients to acknowledge a permanent replication
             * message instead.
             */
            envConfig.RepSystemCfg.RepMgrAckPolicy = config.ackPolicy;

            /*
             * Set the threshold for the minimum and maximum time the client
             * waits before requesting retransmission of a missing message.
             * Base these values on the performance and load characteristics
             * of the master and client host platforms as well as the round
             * trip message time.
             */
            envConfig.RepSystemCfg.RetransmissionRequest(20000, 500000);

            /*
             * Configure deadlock detection to ensure that any deadlocks
             * are broken by having one of the conflicting lock requests
             * rejected. DB_LOCK_DEFAULT uses the lock policy specified
             * at environment creation time or DB_LOCK_RANDOM if none was
             * specified.
             */
            envConfig.LockSystemCfg = new LockingConfig();
            envConfig.LockSystemCfg.DeadlockResolution = DeadlockPolicy.DEFAULT;

            envConfig.Create = true;
            envConfig.RunRecovery = true;
            envConfig.FreeThreaded = true;
            envConfig.UseReplication = true;
            envConfig.UseLocking = true;
            envConfig.UseLogging = true;
            envConfig.UseMPool = true;
            envConfig.UseTxns = true;
            envConfig.Verbosity = new VerboseMessages();
            envConfig.Verbosity.Replication = config.verbose;

            try
            {
                dbenv = RepQuoteEnvironment.Open(config.home, envConfig);
            } catch(DatabaseException e)
            {
                Console.WriteLine("Fail to open environment: " + e.Message);
                return 1;
            }

            /* The following base replication features may also be useful to your
             * application. See Berkeley DB documentation for more details.
             *   - Master leases: Provide stricter consistency for data reads
             *     on a master site.
             *   - Timeouts: Customize the amount of time Berkeley DB waits
             *     for such things as an election to be concluded or a master
             *     lease to be granted.
             *   - Delayed client synchronization: Manage the master site's
             *     resources by spreading out resource-intensive client
             *     synchronizations.
             *   - Blocked client operations: Return immediately with an error
             *     instead of waiting indefinitely if a client operation is
             *     blocked by an ongoing client synchronization.
             *
             * The following repmgr features may also be useful to your
             * application.  See Berkeley DB documentation for more details.
             *  - Two-site strict majority rule - In a two-site replication
             *    group, require both sites to be available to elect a new
             *    master.
             *  - Timeouts - Customize the amount of time repmgr waits
             *    for such things as waiting for acknowledgements or attempting
             *    to reconnect to other sites.
             *  - Site list - return a list of sites currently known to repmgr.
             */

            /* Start checkpoint and log archive support threads. */
            checkpointThread = new Thread(new ThreadStart(CheckPoint));
            checkpointThread.Start();
            logArchiveThread = new Thread(new ThreadStart(LogArchive));
            logArchiveThread.Start();

            /* Start replication manager. */
            if (config.startPolicy == StartPolicy.CLIENT)
                dbenv.env.RepMgrStartClient(3);
            else if (config.startPolicy == StartPolicy.ELECTION)
                dbenv.env.RepMgrStartClient(3, true);
            else if (config.startPolicy == StartPolicy.MASTER)
                dbenv.env.RepMgrStartMaster(3);

            return ret;
        }
        static void Main(string[] args) {
            BTreeDatabase btreeDB;
            BTreeDatabaseConfig btreeDBConfig;
            DatabaseEnvironment env;
            DatabaseEnvironmentConfig envConfig;
            Sequence seq;
            SequenceConfig seqConfig;
            string buff;
            string dbFileName;
            string home;
            string progName;

            /*
             * excs_sequence is meant to be run from build_windows\AnyCPU, in
             * either the Debug or Release directory. The required core
             * libraries, however, are in either build_windows\Win32 or
             * build_windows\x64, depending upon the platform.  That location
             * needs to be added to the PATH environment variable for the
             * P/Invoke calls to work.
             */
            try {
                String pwd = Environment.CurrentDirectory;
                pwd = Path.Combine(pwd, "..");
                pwd = Path.Combine(pwd, "..");
                if (IntPtr.Size == 4)
                    pwd = Path.Combine(pwd, "Win32");
                else
                    pwd = Path.Combine(pwd, "x64");
#if DEBUG
                pwd = Path.Combine(pwd, "Debug");
#else
                pwd = Path.Combine(pwd, "Release");
#endif
                pwd += ";" + Environment.GetEnvironmentVariable("PATH");
                Environment.SetEnvironmentVariable("PATH", pwd);
            } catch (Exception e) {
                Console.WriteLine(
                    "Unable to set the PATH environment variable.");
                Console.WriteLine(e.Message);
                return;
            }
            
            progName = "excs_sequence";
            try {
                home = args[0];
                dbFileName = args[1];
            } catch {
                Usage();
                return;
            };

            /* Optiionally remove the existing database file. */
            if (File.Exists(dbFileName)) {
                while (true) {
                    Console.Write
                        ("File already exists, delete or not (y/n)?");
                    buff = Console.ReadLine();
                    if (buff == "y" || buff == "n")
                        break;
                }

                if (buff == "y") {
                    File.Delete(dbFileName);
                    Console.WriteLine("The existing {0} is deleted",
                        dbFileName);
                }
            }

            /* Configure and open environment. */
            envConfig = new DatabaseEnvironmentConfig();
            envConfig.Create = true;
            envConfig.UseLogging = true;
            envConfig.UseMPool = true;
            envConfig.UseTxns = true;
            try {
                env = DatabaseEnvironment.Open(home, envConfig);
            } catch (Exception e) {
                Console.WriteLine("{0}:{1}\n{2}",
                    e.Source, e.Message, e.StackTrace);
                return;
            }

            /* Configure and open sequence's database. */
            btreeDBConfig = new BTreeDatabaseConfig();
            btreeDBConfig.AutoCommit = true;
            btreeDBConfig.Creation = CreatePolicy.IF_NEEDED;
            btreeDBConfig.ErrorPrefix = progName;
            btreeDBConfig.Env = env;
            try {
                btreeDB = BTreeDatabase.Open(dbFileName,
                    btreeDBConfig);
            } catch (Exception e) {
                Console.WriteLine("{0}:{1}\n{2}",
                    e.Source, e.Message, e.StackTrace);
                return;
            }

            /* Configure and initialize sequence. */
            seqConfig = new SequenceConfig();
            seqConfig.BackingDatabase = btreeDB;
            seqConfig.Creation = CreatePolicy.IF_NEEDED;
            seqConfig.Increment = true;
            seqConfig.InitialValue = Int64.MaxValue;
            seqConfig.key = new DatabaseEntry();
            seqConfig.SetRange(Int64.MinValue, Int64.MaxValue);
            seqConfig.Wrap = true;
            DbtFromString(seqConfig.key, "excs_sequence");
            seq = new Sequence(seqConfig);

            /* Get from sequence. */
            for (int i = 0; i < 10; i++) {
                Console.WriteLine("{0}", seq.Get(2));
                Console.ReadLine();
            }

            Console.WriteLine("Sequence Name: {0}",
                seq.BackingDatabase.FileName);
            Console.WriteLine("Sequence Key: {0}",
                StrFromDBT(seq.Key));
            Console.WriteLine("{0}->{1}", seq.Min, seq.Max);
            Console.WriteLine(seq.Wrap ? "wrap" : "not wrap");
            Console.WriteLine(seq.Increment ? "increase" :
                "decrease");

            /* Close sequence, database and environment. */
            seq.Close();
            btreeDB.Close();
            env.Close();
        }
Пример #27
0
        public void OpenSecDBInTxn(string home, string dbFileName, 
		    string dbSecFileName, out DatabaseEnvironment env,
		    out BTreeDatabase db, out SecondaryBTreeDatabase secDB)
        {
            // Open environment.
            DatabaseEnvironmentConfig envCfg =
                new DatabaseEnvironmentConfig();
            envCfg.Create = true;
            envCfg.UseLocking = true;
            envCfg.UseLogging = true;
            envCfg.UseMPool = true;
            envCfg.UseTxns = true;
            env = DatabaseEnvironment.Open(
                home, envCfg);

            // Open primary and secondary database in a transaction.
            Transaction openTxn = env.BeginTransaction();
            BTreeDatabaseConfig dbConfig =
                new BTreeDatabaseConfig();
            dbConfig.Creation = CreatePolicy.IF_NEEDED;
            dbConfig.Env = env;
            dbConfig.PageSize = 4096;
            dbConfig.Duplicates = DuplicatesPolicy.NONE;
            dbConfig.ReadUncommitted = true;
            db = BTreeDatabase.Open(dbFileName, dbConfig,
                openTxn);
            openTxn.Commit();

            openTxn = env.BeginTransaction();
            SecondaryBTreeDatabaseConfig secConfig =
                new SecondaryBTreeDatabaseConfig(db,
                new SecondaryKeyGenDelegate(SecondaryKeyGen));
            secConfig.Creation = CreatePolicy.IF_NEEDED;
            secConfig.Duplicates = DuplicatesPolicy.SORTED;
            secConfig.Env = env;
            secConfig.ReadUncommitted = true;
            secDB = SecondaryBTreeDatabase.Open(dbSecFileName,
                secConfig, openTxn);
            openTxn.Commit();
        }
 public void TestConfigLock()
 {
     testName = "TestConfigLock";
     SetUpTest(false);
     XmlElement xmlElem = Configuration.TestSetUp(
         testFixtureName, testName);
     DatabaseEnvironmentConfig cfg =
         new DatabaseEnvironmentConfig();
     cfg.LockSystemCfg = new LockingConfig();
     LockingConfigTest.Config(xmlElem,
         ref cfg.LockSystemCfg, true);
     LockingConfigTest.Confirm(xmlElem,
         cfg.LockSystemCfg, true);
 }
 public void TestConfigMutex()
 {
     testName = "TestConfigMutex";
     SetUpTest(false);
     XmlElement xmlElem = Configuration.TestSetUp(
         testFixtureName, testName);
     DatabaseEnvironmentConfig cfg =
         new DatabaseEnvironmentConfig();
     cfg.MutexSystemCfg = new MutexConfig();
     MutexConfigTest.Config(xmlElem, ref cfg.MutexSystemCfg, true);
     MutexConfigTest.Confirm(xmlElem, cfg.MutexSystemCfg, true);
 }
Пример #30
0
        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.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();
        }