本文整理汇总了C#中BerkeleyDB.BTreeDatabase类的典型用法代码示例。如果您正苦于以下问题:C# BTreeDatabase类的具体用法?C# BTreeDatabase怎么用?C# BTreeDatabase使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BTreeDatabase类属于BerkeleyDB命名空间,在下文中一共展示了BTreeDatabase类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: OpenBase
private void OpenBase()
{
var pathStr = Environment.GetEnvironmentVariable("PATH");
var pwd = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
pwd = Path.Combine(pwd, IntPtr.Size == 4 ? "x86" : "x64");
if (pathStr != null && !pathStr.Contains(pwd))
{
pwd += ";" + Environment.GetEnvironmentVariable("PATH");
Environment.SetEnvironmentVariable("PATH", pwd);
}
_btreeConfig = new BTreeDatabaseConfig
{
Duplicates = DuplicatesPolicy.NONE,
ErrorPrefix = "QH_" + Path.GetFileName(_dbPAth),
Creation = CreatePolicy.IF_NEEDED,
FreeThreaded = true
};
if (_env != null)
{
_btreeConfig.Env = _env;
}
_btreeDb = BTreeDatabase.Open(_dbPAth, _name, _btreeConfig);
}
开发者ID:SoftFx,项目名称:PerformancePoC,代码行数:28,代码来源:BdbStorage.cs
示例3: GetCursorInBtreeDBInCDS
// 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);
}
开发者ID:kanbang,项目名称:Colt,代码行数:34,代码来源:CursorTest.cs
示例4: GetCursorInBtreeDBUsingRecno
public void GetCursorInBtreeDBUsingRecno(string home,
string name, out BTreeDatabase db,
out BTreeCursor cursor)
{
string dbFileName = home + "/" + name + ".db";
BTreeDatabaseConfig dbConfig = new BTreeDatabaseConfig();
dbConfig.UseRecordNumbers = true;
dbConfig.Creation = CreatePolicy.IF_NEEDED;
db = BTreeDatabase.Open(dbFileName, dbConfig);
cursor = db.Cursor();
}
开发者ID:sukantoguha,项目名称:INET-Vagrant-Demos,代码行数:11,代码来源:BTreeCursorTest.cs
示例5: Init
public override void Init(int flowCount, long flowRecordCount)
{
BTreeDatabaseConfig config = new BTreeDatabaseConfig();
config.Creation = CreatePolicy.IF_NEEDED;
config.CacheSize = new CacheInfo(5, 0, 2);
config.PageSize = 8 * 1024;
config.BTreeCompare = new EntryComparisonDelegate(CompareFunctionKeyByteArray);
config.Duplicates = DuplicatesPolicy.NONE;
string fileName = Path.Combine(DataDirectory, string.Format("{0}.oracle", CollectionName));
database = BTreeDatabase.Open(fileName, config);
}
开发者ID:pavel-gridnev,项目名称:DatabaseBenchmark,代码行数:13,代码来源:OracleBerkeleyDBDatabase.cs
示例6: OpenBtreeDBInEnv
public void OpenBtreeDBInEnv(string dbName,
DatabaseEnvironment env, out BTreeDatabase db,
bool create, Transaction txn)
{
BTreeDatabaseConfig btreeDBConfig =
new BTreeDatabaseConfig();
btreeDBConfig.Env = env;
if (create == true)
btreeDBConfig.Creation = CreatePolicy.IF_NEEDED;
else
btreeDBConfig.Creation = CreatePolicy.NEVER;
if (txn == null)
db = BTreeDatabase.Open(dbName,
btreeDBConfig);
else
db = BTreeDatabase.Open(dbName,
btreeDBConfig, txn);
}
开发者ID:jamiekeefer,项目名称:gldcoin,代码行数:18,代码来源:TransactionTest.cs
示例7: OpenPrimaryAndSecondaryDB
public void OpenPrimaryAndSecondaryDB(string dbFileName,
out BTreeDatabase primaryDB,
out SecondaryBTreeDatabase secDB)
{
// Open primary database.
BTreeDatabaseConfig primaryDBConfig =
new BTreeDatabaseConfig();
primaryDBConfig.Creation = CreatePolicy.IF_NEEDED;
primaryDB =
BTreeDatabase.Open(dbFileName, primaryDBConfig);
// Open secondary database.
SecondaryBTreeDatabaseConfig secDBConfig =
new SecondaryBTreeDatabaseConfig(primaryDB,
new SecondaryKeyGenDelegate(SecondaryKeyGen));
secDB = SecondaryBTreeDatabase.Open(dbFileName,
secDBConfig);
}
开发者ID:sukantoguha,项目名称:INET-Vagrant-Demos,代码行数:18,代码来源:SecondaryDatabaseTest.cs
示例8: Confirm
public static void Confirm(XmlElement xmlElem,
BTreeDatabase btreeDB, bool compulsory)
{
DatabaseTest.Confirm(xmlElem, btreeDB, compulsory);
Configuration.ConfirmDuplicatesPolicy(xmlElem,
"Duplicates", btreeDB.Duplicates, compulsory);
Configuration.ConfirmUint(xmlElem, "MinKeysPerPage",
btreeDB.MinKeysPerPage, compulsory);
/*
* BTreeDatabase.RecordNumbers is the value of
* BTreeDatabaseConfig.UseRecordNumbers.
*/
Configuration.ConfirmBool(xmlElem, "UseRecordNumbers",
btreeDB.RecordNumbers, compulsory);
/*
* BTreeDatabase.ReverseSplit is the value of
* BTreeDatabaseConfig.NoReverseSplitting.
*/
Configuration.ConfirmBool(xmlElem, "NoReverseSplitting",
btreeDB.ReverseSplit, compulsory);
Assert.AreEqual(DatabaseType.BTREE, btreeDB.Type);
string type = btreeDB.ToString();
Assert.IsNotNull(type);
}
开发者ID:remotesyssupport,项目名称:omnibus,代码行数:24,代码来源:BTreeDatabaseTest.cs
示例9: OpenNewSequenceInEnv
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();
}
开发者ID:xiaogao0371,项目名称:dockerfile,代码行数:36,代码来源:SequenceTest.cs
示例10: OpenNewSequence
public void OpenNewSequence(string dbFileName,
out BTreeDatabase db, out Sequence seq)
{
// Open a database.
BTreeDatabaseConfig btreeDBConfig =
new BTreeDatabaseConfig();
btreeDBConfig.Creation = CreatePolicy.IF_NEEDED;
db = BTreeDatabase.Open(dbFileName, btreeDBConfig);
// Configure and initialize sequence.
SequenceConfig seqConfig = new SequenceConfig();
seqConfig.BackingDatabase = db;
seqConfig.CacheSize = 1000;
seqConfig.Creation = CreatePolicy.ALWAYS;
seqConfig.Decrement = false;
seqConfig.FreeThreaded = true;
seqConfig.Increment = true;
seqConfig.InitialValue = 100;
seqConfig.key = new DatabaseEntry(
ASCIIEncoding.ASCII.GetBytes("key"));
seqConfig.SetRange(Int64.MinValue, Int64.MaxValue);
seqConfig.Wrap = true;
seq = new Sequence(seqConfig);
}
开发者ID:xiaogao0371,项目名称:dockerfile,代码行数:24,代码来源:SequenceTest.cs
示例11: CursorReadUncommited
/*
* Configure a transactional cursor to have degree 1
* isolation. The cursor's read operations could return
* modified but not yet commited data.
*/
public void CursorReadUncommited(
DatabaseEnvironment env, BTreeDatabase db,
Cursor cursor, Transaction txn)
{
Console.WriteLine("CursorReadUncommited");
}
开发者ID:gildafnai82,项目名称:craq,代码行数:11,代码来源:CursorTest.cs
示例12: GetCursorInBtreeDBWithoutEnv
public static void GetCursorInBtreeDBWithoutEnv(
string home, string name, out BTreeDatabase db,
out BTreeCursor cursor)
{
string dbFileName = home + "/" + name + ".db";
BTreeDatabaseConfig dbConfig =
new BTreeDatabaseConfig();
dbConfig.Creation = CreatePolicy.IF_NEEDED;
dbConfig.Duplicates = DuplicatesPolicy.UNSORTED;
db = BTreeDatabase.Open(dbFileName, dbConfig);
cursor = db.Cursor();
}
开发者ID:gildafnai82,项目名称:craq,代码行数:13,代码来源:CursorTest.cs
示例13: 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
示例14: MyDbs
public MyDbs(string databaseHome)
{
vDbName = "vendordb.db";
iDbName = "inventorydb.db";
itemSDbName = "itemname.sdb";
if (databaseHome != null) {
vDbName = databaseHome + "\\" + vDbName;
iDbName = databaseHome + "\\" + iDbName;
itemSDbName = databaseHome + "\\" + itemSDbName;
}
btreeConfig = new BTreeDatabaseConfig();
btreeConfig.Creation = CreatePolicy.IF_NEEDED;
btreeConfig.CacheSize = new CacheInfo(0, 64 * 1024, 1);
btreeConfig.ErrorPrefix = "excs_getting_started";
btreeConfig.PageSize = 8 * 1024;
/* Optionally remove existing database files. */
try {
RemoveDbFile(vDbName);
RemoveDbFile(iDbName);
RemoveDbFile(itemSDbName);
} catch (Exception e) {
Console.WriteLine("Error deleting db.");
Console.WriteLine(e.Message);
throw e;
}
/* Create and open the Inventory and Vendor database files. */
try {
vbtreeDB = BTreeDatabase.Open(vDbName, btreeConfig);
} catch (Exception e) {
Console.WriteLine("Error opening {0}.", vDbName);
Console.WriteLine(e.Message);
throw e;
}
try {
ibtreeDB = BTreeDatabase.Open(iDbName, btreeConfig);
} catch (Exception e) {
Console.WriteLine("Error opening {0}.", iDbName);
Console.WriteLine(e.Message);
throw e;
}
/*
* Open a secondary btree database associated with the
* Inventory database.
*/
try {
itemSecbtreeConfig = new SecondaryBTreeDatabaseConfig(
ibtreeDB, new SecondaryKeyGenDelegate(
CreateSecondaryKey));
itemSecbtreeConfig.Creation = CreatePolicy.IF_NEEDED;
itemSecbtreeConfig.Duplicates = DuplicatesPolicy.UNSORTED;
itemSecbtreeDB = SecondaryBTreeDatabase.Open(
itemSDbName, itemSecbtreeConfig);
} catch (Exception e) {
Console.WriteLine("Error opening secondary {0}", itemSDbName);
Console.WriteLine(e.Message);
throw e;
}
}
开发者ID:simonzhangsm,项目名称:h-store,代码行数:65,代码来源:MyDbs.cs
示例15: 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
示例16: 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
示例17: 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
示例18: 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
示例19: OpenSecDBInTxn
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();
}
开发者ID:mcandre,项目名称:db,代码行数:40,代码来源:SecondaryCursorTest.cs
示例20: 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
注:本文中的BerkeleyDB.BTreeDatabase类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论