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


C# BTreeDatabase.Put方法代码示例

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


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

示例1: GetSecCursor

        public void GetSecCursor(BTreeDatabase db,
		    string secFileName, SecondaryKeyGenDelegate keyGen,
		    out SecondaryBTreeDatabase secDB,
		    out SecondaryCursor cursor, bool ifCfg,
		    DatabaseEntry data)
        {
            // Open secondary database.
            SecondaryBTreeDatabaseConfig secCfg =
                new SecondaryBTreeDatabaseConfig(db, keyGen);
            secCfg.Creation = CreatePolicy.IF_NEEDED;
            secCfg.Duplicates = DuplicatesPolicy.SORTED;
            secDB = SecondaryBTreeDatabase.Open(secFileName, secCfg);

            int[] intArray = new int[4];
            intArray[0] = 0;
            intArray[1] = 1;
            intArray[2] = 2049;
            intArray[3] = 65537;
            for (int i = 0; i < 4; i++)
            {
                DatabaseEntry record = new DatabaseEntry(
                    BitConverter.GetBytes(intArray[i]));
                db.Put(record, record);
            }

            // Get secondary cursor on the secondary database.
            if (ifCfg == false)
                cursor = secDB.SecondaryCursor();
            else
                cursor = secDB.SecondaryCursor(new CursorConfig());

            // Position the cursor.
            if (data != null)
                Assert.IsTrue(cursor.Move(data, true));
        }
开发者ID:xiaogao0371,项目名称:dockerfile,代码行数:35,代码来源:JoinCursorTest.cs

示例2: WriteRecordsInTxn

        public void WriteRecordsInTxn(BTreeDatabase db, 
		    DatabaseEnvironment env)
        {
            Transaction txn = env.BeginTransaction();
            /*
             * Write ten records into the database. The records
             * from 1st to 5th and 8th to 10th are unique in the
             * database. The data in the 6th and 7th records
             * are the same.
             */
            for (int i = 0; i < 10; i++)
            {
                if (i == 5 || i == 6)
                    db.Put(new DatabaseEntry(
                        BitConverter.GetBytes(i)),
                        new DatabaseEntry(
                        BitConverter.GetBytes((int)10)), txn);
                else
                    db.Put(new DatabaseEntry(
                        BitConverter.GetBytes(i)),
                        new DatabaseEntry(BitConverter.GetBytes(i)), txn);
            }

            txn.Commit();
        }
开发者ID:mcandre,项目名称:db,代码行数:25,代码来源:SecondaryCursorTest.cs

示例3: WriteRecords

 public void WriteRecords(BTreeDatabase db)
 {
     /*
      * Write ten records into the database. The records
      * from 1st to 5th and 8th to 10th are unique in the
      * database. The data in the 6th and 7th records
      * are the same.
      */
     for (int i = 0; i < 10; i++)
     {
         if (i == 5 || i == 6)
             db.Put(new DatabaseEntry(
                 BitConverter.GetBytes(i)),
                 new DatabaseEntry(
                 BitConverter.GetBytes((int)10)));
         else
             db.Put(new DatabaseEntry(
                 BitConverter.GetBytes(i)),
                 new DatabaseEntry(BitConverter.GetBytes(i)));
     }
 }
开发者ID:mcandre,项目名称:db,代码行数:21,代码来源:SecondaryCursorTest.cs

示例4: 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

示例5: 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

示例6: PopulateDb

 private void PopulateDb(ref BTreeDatabase db)
 {
     if (db == null) {
         BTreeDatabaseConfig cfg =
             new BTreeDatabaseConfig();
         cfg.Creation = CreatePolicy.IF_NEEDED;
         db = BTreeDatabase.Open(
             testHome + "/" + testName, cfg);
     }
     for (int i = 0; i < 100; i++)
         db.Put(
             new DatabaseEntry(BitConverter.GetBytes(i)),
             new DatabaseEntry(BitConverter.GetBytes(i)));
 }
开发者ID:mcandre,项目名称:db,代码行数:14,代码来源:CursorTest.cs

示例7: WriteOneIntoBtreeDBWithTxn

        public void WriteOneIntoBtreeDBWithTxn(BTreeDatabase db,
		    Transaction txn)
        {
            DatabaseEntry key, data;

            key = new DatabaseEntry(
                ASCIIEncoding.ASCII.GetBytes("key"));
            data = new DatabaseEntry(
                ASCIIEncoding.ASCII.GetBytes("data"));
            db.Put(key, data, txn);
        }
开发者ID:jamiekeefer,项目名称:gldcoin,代码行数:11,代码来源:TransactionTest.cs

示例8: PutRecordCase1

 public void PutRecordCase1(BTreeDatabase db, Transaction txn)
 {
     byte[] bigArray = new byte[10240];
     for (int i = 0; i < 100; i++)
     {
         if (txn == null)
             db.Put(new DatabaseEntry(BitConverter.GetBytes(i)),
                 new DatabaseEntry(BitConverter.GetBytes(i)));
         else
             db.Put(new DatabaseEntry(BitConverter.GetBytes(i)),
                 new DatabaseEntry(BitConverter.GetBytes(i)), txn);
     }
     for (int i = 100; i < 500; i++)
     {
         if (txn == null)
             db.Put(new DatabaseEntry(bigArray),
                 new DatabaseEntry(bigArray));
         else
             db.Put(new DatabaseEntry(bigArray),
                 new DatabaseEntry(bigArray), txn);
     }
 }
开发者ID:remotesyssupport,项目名称:omnibus,代码行数:22,代码来源:BTreeDatabaseTest.cs

示例9: 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

示例10: 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

示例11: TestLockStats

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

            // Configure locking subsystem.
            LockingConfig lkConfig = new LockingConfig();
            lkConfig.MaxLockers = 60;
            lkConfig.MaxLocks = 50;
            lkConfig.MaxObjects = 70;
            lkConfig.Partitions = 20;
            lkConfig.DeadlockResolution = DeadlockPolicy.DEFAULT;

            // Configure and open environment.
            DatabaseEnvironmentConfig envConfig =
                new DatabaseEnvironmentConfig();
            envConfig.Create = true;
            envConfig.FreeThreaded = true;
            envConfig.LockSystemCfg = lkConfig;
            envConfig.LockTimeout = 1000;
            envConfig.MPoolSystemCfg = new MPoolConfig();
            envConfig.MPoolSystemCfg.CacheSize = new CacheInfo(0, 104800, 1);
            envConfig.NoLocking = false;
            envConfig.TxnTimeout = 2000;
            envConfig.UseLocking = true;
            envConfig.UseMPool = true;
            envConfig.UseTxns = true;
            DatabaseEnvironment env =
                DatabaseEnvironment.Open(testHome, envConfig);

            // Get and confirm locking subsystem statistics.
            LockStats stats = env.LockingSystemStats();
            env.PrintLockingSystemStats(true, true);
            Assert.AreEqual(0, stats.AllocatedLockers);
            Assert.AreNotEqual(0, stats.AllocatedLocks);
            Assert.AreNotEqual(0, stats.AllocatedObjects);
            Assert.AreEqual(0, stats.InitLockers);
            Assert.AreNotEqual(0, stats.InitLocks);
            Assert.AreNotEqual(0, stats.InitObjects);
            Assert.AreEqual(0, stats.LastAllocatedLockerID);
            Assert.AreEqual(0, stats.LockConflictsNoWait);
            Assert.AreEqual(0, stats.LockConflictsWait);
            Assert.AreEqual(0, stats.LockDeadlocks);
            Assert.AreEqual(0, stats.LockDowngrades);
            Assert.AreEqual(0, stats.LockerNoWait);
            Assert.AreEqual(0, stats.Lockers);
            Assert.AreEqual(0, stats.LockerWait);
            Assert.AreEqual(9, stats.LockModes);
            Assert.AreEqual(0, stats.LockPuts);
            Assert.AreEqual(0, stats.LockRequests);
            Assert.AreEqual(0, stats.Locks);
            Assert.AreEqual(0, stats.LockSteals);
            Assert.AreEqual(1000, stats.LockTimeoutLength);
            Assert.AreEqual(0, stats.LockTimeouts);
            Assert.AreEqual(0, stats.LockUpgrades);
            Assert.AreEqual(0, stats.MaxBucketLength);
            Assert.AreEqual(0, stats.MaxLockers);
            Assert.AreEqual(60, stats.MaxLockersInTable);
            Assert.AreEqual(0, stats.MaxLocks);
            Assert.AreEqual(0, stats.MaxLocksInBucket);
            Assert.AreEqual(50, stats.MaxLocksInTable);
            Assert.AreEqual(0, stats.MaxLockSteals);
            Assert.AreEqual(0, stats.MaxObjects);
            Assert.AreEqual(0, stats.MaxObjectsInBucket);
            Assert.AreEqual(70, stats.MaxObjectsInTable);
            Assert.AreEqual(0, stats.MaxObjectSteals);
            Assert.AreEqual(0, stats.MaxPartitionLockNoWait);
            Assert.AreEqual(0, stats.MaxPartitionLockWait);
            Assert.AreNotEqual(0, stats.MaxUnusedID);
            Assert.AreEqual(20, stats.nPartitions);
            Assert.AreEqual(0, stats.ObjectNoWait);
            Assert.AreEqual(0, stats.Objects);
            Assert.AreEqual(0, stats.ObjectSteals);
            Assert.AreEqual(0, stats.ObjectWait);
            Assert.LessOrEqual(0, stats.PartitionLockNoWait);
            Assert.AreEqual(0, stats.PartitionLockWait);
            Assert.Less(0, stats.RegionNoWait);
            Assert.AreNotEqual(0, stats.RegionSize);
            Assert.AreEqual(0, stats.RegionWait);
            Assert.AreNotEqual(0, stats.TableSize);
            Assert.AreEqual(2000, stats.TxnTimeoutLength);
            Assert.AreEqual(0, stats.TxnTimeouts);

            env.PrintLockingSystemStats();

            Transaction txn = env.BeginTransaction();
            BTreeDatabaseConfig dbConfig = new BTreeDatabaseConfig();
            dbConfig.Creation = CreatePolicy.IF_NEEDED;
            dbConfig.Env = env;
                dbConfig.FreeThreaded = true;
            BTreeDatabase db = BTreeDatabase.Open(
                testName + ".db", dbConfig, txn);
            txn.Commit();

            testLockStatsEnv = env;
            testLockStatsDb = db;

            // Use some locks, to ensure  the stats work when populated.
            txn = testLockStatsEnv.BeginTransaction();
            for (int i = 0; i < 500; i++)
//.........这里部分代码省略.........
开发者ID:balagopalraj,项目名称:clearlinux,代码行数:101,代码来源:LockTest.cs

示例12: PopulateDb

        private void PopulateDb(DatabaseEnvironment env,
		    out BTreeDatabase db)
        {
            DatabaseEntry key, data;
            Transaction txn = null;
            string dbName;

            if (env != null) {
                txn = env.BeginTransaction();
                dbName = testName + ".db";
            } else
                dbName = testHome + "/" + testName + ".db";

            OpenBtreeDB(env, txn, dbName, out db);

            for (int i = 0; i < 100; i++) {
                key = new DatabaseEntry(
                    BitConverter.GetBytes(i));
                data = new DatabaseEntry(
                    ASCIIEncoding.ASCII.GetBytes("hello"));
                db.Put(key, data, txn);
            }

            if (txn != null)
                txn.Commit();
        }
开发者ID:hyc,项目名称:BerkeleyDB,代码行数:26,代码来源:BTreeDatabaseTest.cs


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