本文整理汇总了C#中BerkeleyDB.DatabaseEnvironment类的典型用法代码示例。如果您正苦于以下问题:C# DatabaseEnvironment类的具体用法?C# DatabaseEnvironment怎么用?C# DatabaseEnvironment使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DatabaseEnvironment类属于BerkeleyDB命名空间,在下文中一共展示了DatabaseEnvironment类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Logging
/*
* 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")));
}
示例2: LockingEnvSetUp
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);
}
示例3: BdbStorage
public BdbStorage(string path, string name = null, DatabaseEnvironment env = null)
{
_dbPAth = path;
_env = env;
_name = name;
OpenBase();
}
示例4: SetUpEnvWithTxnAndLocking
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();
}
示例5: 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);
}
示例6: DBInit
/*
* 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;
}
示例7: 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);
}
示例8: Open
public BTreeDatabase Open(DatabaseEnvironment env, bool isMaster)
{
string dbName = "rep.db";
// Set up the database.
BTreeDatabaseConfig dbCfg = new BTreeDatabaseConfig();
dbCfg.Env = env;
if (isMaster)
dbCfg.Creation = CreatePolicy.IF_NEEDED;
dbCfg.AutoCommit = true;
dbCfg.FreeThreaded = true;
/*
* Open the database. Do not provide a txn handle. This
* Open is autocommitted because BTreeDatabaseConfig.AutoCommit
* is true.
*/
return BTreeDatabase.Open(dbName, dbCfg);
}
示例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();
}
示例10: 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();
}
示例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");
}
示例12: 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();
}
示例13: Open
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);
}
示例14: PutRecordWithTxn
public void PutRecordWithTxn(out DatabaseEnvironment env,
string home, string dbName, out Transaction txn)
{
BTreeDatabase db;
// Open a new environment and begin a transaction.
SetUpTransactionalEnv(home, out env);
TransactionConfig txnConfig = new TransactionConfig();
txnConfig.Name = "Transaction";
txn = env.BeginTransaction(txnConfig);
Assert.AreEqual("Transaction", txn.Name);
// Open a new database within the transaction.
OpenBtreeDBInEnv(dbName + ".db", env, out db, true, txn);
// Write to the database within the transaction.
WriteOneIntoBtreeDBWithTxn(db, txn);
// Close the database.
db.Close();
}
示例15: 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();
}