当前位置: 首页>>代码示例>>C#>>正文


C# BTreeDatabase.Close方法代码示例

本文整理汇总了C#中BerkeleyDB.BTreeDatabase.Close方法的典型用法代码示例。如果您正苦于以下问题:C# BTreeDatabase.Close方法的具体用法?C# BTreeDatabase.Close怎么用?C# BTreeDatabase.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BerkeleyDB.BTreeDatabase的用法示例。


在下文中一共展示了BTreeDatabase.Close方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: MoveWithRMW

        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();
        }
开发者ID:gildafnai82,项目名称:craq,代码行数:95,代码来源:CursorTest.cs

示例2: TestSnapshotIsolation

        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();
        }
开发者ID:gildafnai82,项目名称:craq,代码行数:81,代码来源:CursorTest.cs

示例3: TestDetectDeadlocks

        public void TestDetectDeadlocks()
        {
            testName = "TestDetectDeadlocks";
            SetUpTest(true);

            // Open an environment.
            DatabaseEnvironmentConfig cfg =
                new DatabaseEnvironmentConfig();
            cfg.Create = true;
            cfg.UseTxns = true;
            cfg.UseMPool = true;
            cfg.UseLogging = true;
            cfg.UseLocking = true;
            cfg.FreeThreaded = true;
            testDetectDeadlocksEnv = DatabaseEnvironment.Open(
                testHome, cfg);

            // Open btree database.
            BTreeDatabaseConfig dbConfig = new BTreeDatabaseConfig();
            dbConfig.AutoCommit = true;
            dbConfig.Creation = CreatePolicy.IF_NEEDED;
            dbConfig.Env = testDetectDeadlocksEnv;
            dbConfig.Duplicates = DuplicatesPolicy.NONE;
            dbConfig.FreeThreaded = true;
            testDetectDeadlocksDB = BTreeDatabase.Open(
                testName + ".db", dbConfig);

            // Put one record("key", "data") into database.
            testDetectDeadlocksDB.Put(
                new DatabaseEntry(ASCIIEncoding.ASCII.GetBytes("key")),
                new DatabaseEntry(ASCIIEncoding.ASCII.GetBytes("data")));

            // Begin two threads to read and write record.
            Thread thread1 = new Thread(new ThreadStart(ReadAndPutRecordThread));
            Thread thread2 = new Thread(new ThreadStart(ReadAndPutRecordThread));
            signal = new EventWaitHandle(false, EventResetMode.ManualReset);
            thread1.Start();
            thread2.Start();

            // Give enough time for threads to read record.
            Thread.Sleep(1000);

            /*
             * Let the two threads apply for write lock
             * synchronously.
             */
            signal.Set();

            // Confirm that there is deadlock in the environment.
            Thread.Sleep(1000);
            uint deadlockNum = testDetectDeadlocksEnv.DetectDeadlocks(
                DeadlockPolicy.DEFAULT);
            Assert.Less(0, deadlockNum);

            thread1.Join();
            thread2.Join();

            // Close all.
            testDetectDeadlocksDB.Close(false);
            testDetectDeadlocksEnv.Close();
        }
开发者ID:sukantoguha,项目名称:INET-Vagrant-Demos,代码行数:61,代码来源:DatabaseEnvironmentTest.cs

示例4: TestCheckpoint

        public void TestCheckpoint()
        {
            testName = "TestCheckpoint";
            SetUpTest(true);

            // Open an environment.
            DatabaseEnvironmentConfig cfg =
                new DatabaseEnvironmentConfig();
            cfg.Create = true;
            cfg.UseTxns = true;
            cfg.UseMPool = true;
            cfg.UseLogging = true;
            cfg.UseLocking = true;
            cfg.NoLocking = false;
            cfg.FreeThreaded = true;
            testCheckpointEnv = DatabaseEnvironment.Open(testHome, cfg);

            // Open btree database.
            BTreeDatabaseConfig dbConfig = new BTreeDatabaseConfig();
            dbConfig.AutoCommit = true;
            dbConfig.Creation = CreatePolicy.IF_NEEDED;
            dbConfig.Env = testCheckpointEnv;
            dbConfig.FreeThreaded = true;
            testCheckpointDB = BTreeDatabase.Open(testName + ".db", dbConfig);

            // Run a thread to put records into database.
            Thread thread1 = new Thread(new ThreadStart(PutRecordsThread));

            /*
             * Run a thread to do checkpoint periodically and
             * finally do a checkpoint to flush all in memory pool
             * to log files.
             */
            Thread thread2 = new Thread(new ThreadStart(CheckpointThread));

            thread1.Start();
            thread2.Start();
            thread1.Join();
            thread2.Join();

            // Close all.
            testCheckpointDB.Close();
            testCheckpointEnv.Close();
        }
开发者ID:sukantoguha,项目名称:INET-Vagrant-Demos,代码行数:44,代码来源:DatabaseEnvironmentTest.cs

示例5: TestBeginTransaction

        public void TestBeginTransaction()
        {
            testName = "TestBeginTransaction";
            SetUpTest(true);

            // Open an environment.
            DatabaseEnvironmentConfig cfg =
                new DatabaseEnvironmentConfig();
            cfg.Create = true;
            cfg.UseTxns = true;
            cfg.UseMPool = true;
            cfg.UseLogging = true;
            cfg.UseLocking = true;
            cfg.NoLocking = false;
            cfg.FreeThreaded = true;
            testBeginTransactionEnv = DatabaseEnvironment.Open(testHome, cfg);
            testBeginTransactionEnv.DeadlockResolution = DeadlockPolicy.OLDEST;

            // Open btree database.
            BTreeDatabaseConfig dbConfig = new BTreeDatabaseConfig();
            dbConfig.AutoCommit = true;
            dbConfig.Creation = CreatePolicy.IF_NEEDED;
            dbConfig.Env = testBeginTransactionEnv;
            dbConfig.Duplicates = DuplicatesPolicy.NONE;
            dbConfig.FreeThreaded = true;
            testBeginTransactionDB = BTreeDatabase.Open(
                testName + ".db", dbConfig);

            testBeginTransactionDB.Put(
                new DatabaseEntry(ASCIIEncoding.ASCII.GetBytes("key")),
                new DatabaseEntry(ASCIIEncoding.ASCII.GetBytes("data")));

            // Begin two threads to run dead lock detection.
            Thread thread1 = new Thread(new ThreadStart(
                DeadLockThreadWithLockTimeOut));
            Thread thread2 = new Thread(new ThreadStart(
                DeadLockThreadWithTxnTimeout));
            signal = new EventWaitHandle(false, EventResetMode.ManualReset);
            thread1.Start();
            thread2.Start();
            Thread.Sleep(1000);
            signal.Set();
            thread1.Join();
            thread2.Join();

            // Close all.
            testBeginTransactionDB.Close();
            testBeginTransactionEnv.Close();
        }
开发者ID:sukantoguha,项目名称:INET-Vagrant-Demos,代码行数:49,代码来源:DatabaseEnvironmentTest.cs

示例6: TestLockAndUnlockMutex

        public void TestLockAndUnlockMutex()
        {
            testName = "TestLockAndUnlockMutex";
            SetUpTest(true);

            /*
             * Open an environment without locking and
             * deadlock detection.
             */
            DatabaseEnvironmentConfig envConfig =
                new DatabaseEnvironmentConfig();
            envConfig.FreeThreaded = true;
            envConfig.UseLogging = true;
            envConfig.Create = true;
            envConfig.UseMPool = true;
            DatabaseEnvironment env = DatabaseEnvironment.Open(
                testHome, envConfig);

            // Open a database.
            BTreeDatabaseConfig dbConfig =
                new BTreeDatabaseConfig();
            dbConfig.Creation = CreatePolicy.IF_NEEDED;
            dbConfig.Env = env;
            TestDB = BTreeDatabase.Open(
                testName + ".db", dbConfig);

            // Get a mutex which will be used in two threads.
            TestMutex = env.GetMutex(true, false);

            // Begin two threads to write records into database.
            Thread mutexThread1 = new Thread(
                new ThreadStart(MutexThread1));
            Thread mutexThread2 = new Thread(
                new ThreadStart(MutexThread2));
            mutexThread1.Start();
            mutexThread2.Start();
            mutexThread1.Join();
            mutexThread2.Join();

            // Free the mutex.
            TestMutex.Dispose();

            // Close all.
            TestDB.Close();
            env.Close();
        }
开发者ID:sukantoguha,项目名称:INET-Vagrant-Demos,代码行数:46,代码来源:MutexTest.cs


注:本文中的BerkeleyDB.BTreeDatabase.Close方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。