本文整理汇总了C#中BerkeleyDB.TransactionConfig类的典型用法代码示例。如果您正苦于以下问题:C# TransactionConfig类的具体用法?C# TransactionConfig怎么用?C# TransactionConfig使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TransactionConfig类属于BerkeleyDB命名空间,在下文中一共展示了TransactionConfig类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestConfig
public void TestConfig()
{
testName = "TestConfig";
/*
* Configure the fields/properties and see if
* they are updated successfully.
*/
TransactionConfig txnConfig = new TransactionConfig();
XmlElement xmlElem = Configuration.TestSetUp(
testFixtureName, testName);
Config(xmlElem, ref txnConfig, true);
Confirm(xmlElem, txnConfig, true);
}
示例2: Confirm
public static void Confirm(XmlElement xmlElement,
TransactionConfig txnConfig, bool compulsory)
{
Configuration.ConfirmIsolation(xmlElement,
"IsolationDegree", txnConfig.IsolationDegree,
compulsory);
Configuration.ConfirmBool(xmlElement, "NoWait",
txnConfig.NoWait, compulsory);
Configuration.ConfirmBool(xmlElement, "Snapshot",
txnConfig.Snapshot, compulsory);
Configuration.ConfirmLogFlush(xmlElement, "SyncAction",
txnConfig.SyncAction, compulsory);
}
示例3: ReadTxn
public void ReadTxn()
{
// Get a new transaction for reading the db.
TransactionConfig txnConfig =
new TransactionConfig();
txnConfig.Snapshot = true;
readTxn = paramEnv.BeginTransaction(
txnConfig);
// Get a new cursor for putting record into db.
CursorConfig cursorConfig = new CursorConfig();
cursorConfig.WriteCursor = false;
BTreeCursor cursor = paramDB.Cursor(
cursorConfig, readTxn);
// Continually reading record from db.
try
{
Assert.IsTrue(cursor.MoveFirst());
int i = 0;
do
{
Assert.AreEqual(
BitConverter.ToInt32(
cursor.Current.Key.Data, 0),
BitConverter.ToInt32(
cursor.Current.Value.Data, 0));
} while (i <= 1000 && cursor.MoveNext());
}
catch (DeadlockException)
{
}
finally
{
cursor.Close();
}
}
示例4: UpdateTxn
public void UpdateTxn()
{
int int32Value;
DatabaseEntry data;
// Get a new transaction for updating the db.
TransactionConfig txnConfig =
new TransactionConfig();
txnConfig.IsolationDegree =
Isolation.DEGREE_THREE;
updateTxn =
paramEnv.BeginTransaction(txnConfig);
// Continually putting record to db.
BTreeCursor cursor =
paramDB.Cursor(updateTxn);
// Move the cursor to the first record.
Assert.IsTrue(cursor.MoveFirst());
int i = 0;
try
{
do
{
int32Value = BitConverter.ToInt32(
cursor.Current.Value.Data, 0);
data = new DatabaseEntry(
BitConverter.GetBytes(int32Value - 1));
cursor.Overwrite(data);
} while (i <= 1000 && cursor.MoveNext());
}
catch (DeadlockException)
{
}
finally
{
cursor.Close();
}
}
示例5: 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();
}
示例6: TestCloseWithoutSync
public void TestCloseWithoutSync()
{
testName = "TestCloseWithoutSync";
testHome = testFixtureHome + "/" + testName;
string btreeDBName = testName + ".db";
Configuration.ClearDir(testHome);
DatabaseEnvironmentConfig envConfig =
new DatabaseEnvironmentConfig();
envConfig.Create = true;
envConfig.ForceFlush = true;
envConfig.UseTxns = true;
envConfig.UseMPool = true;
envConfig.UseLogging = true;
envConfig.LogSystemCfg = new LogConfig();
envConfig.LogSystemCfg.ForceSync = false;
envConfig.LogSystemCfg.AutoRemove = true;
DatabaseEnvironment env = DatabaseEnvironment.Open(
testHome, envConfig);
TransactionConfig txnConfig = new TransactionConfig();
txnConfig.SyncAction =
TransactionConfig.LogFlush.WRITE_NOSYNC;
Transaction txn = env.BeginTransaction(txnConfig);
BTreeDatabaseConfig btreeConfig =
new BTreeDatabaseConfig();
btreeConfig.Creation = CreatePolicy.ALWAYS;
btreeConfig.Env = env;
BTreeDatabase btreeDB = BTreeDatabase.Open(
btreeDBName, btreeConfig, txn);
DatabaseEntry key = new DatabaseEntry(
ASCIIEncoding.ASCII.GetBytes("key"));
DatabaseEntry data = new DatabaseEntry(
ASCIIEncoding.ASCII.GetBytes("data"));
Assert.IsFalse(btreeDB.Exists(key, txn));
btreeDB.Put(key, data, txn);
btreeDB.Close(false);
txn.Commit();
env.Close();
BTreeDatabaseConfig dbConfig =
new BTreeDatabaseConfig();
dbConfig.Creation = CreatePolicy.NEVER;
using (BTreeDatabase db = BTreeDatabase.Open(
testHome + "/" + btreeDBName, dbConfig))
{
Assert.IsFalse(db.Exists(key));
}
}
示例7: DeadLockThreadWithTxnTimeout
public void DeadLockThreadWithTxnTimeout()
{
// Configure and begin a transaction.
TransactionConfig txnConfig = new TransactionConfig();
txnConfig.TxnTimeout = 5000;
txnConfig.Name = "DeadLockThreadWithTxnTimeout";
Transaction txn =
testBeginTransactionEnv.BeginTransaction(txnConfig, null);
try
{
testBeginTransactionDB.Put(
new DatabaseEntry(ASCIIEncoding.ASCII.GetBytes("key")),
new DatabaseEntry(ASCIIEncoding.ASCII.GetBytes("data")));
signal.WaitOne();
testBeginTransactionDB.Put(
new DatabaseEntry(ASCIIEncoding.ASCII.GetBytes("newkey")),
new DatabaseEntry(ASCIIEncoding.ASCII.GetBytes("newdata")),
txn);
txn.Commit();
}
catch (DeadlockException)
{
try
{
txn.Abort();
}
catch (DatabaseException)
{
throw new TestException();
}
}
catch (DatabaseException)
{
try
{
txn.Abort();
}
catch (DatabaseException)
{
throw new TestException();
}
}
}
示例8: TestTransactionSystemStats
public void TestTransactionSystemStats()
{
testName = "TestTransactionSystemStats";
SetUpTest(true);
TransactionStats stats;
BTreeDatabase db;
Transaction openTxn = null;
// Open an environment.
long dateTime;
DatabaseEnvironmentConfig envConfig =
new DatabaseEnvironmentConfig();
envConfig.Create = true;
envConfig.MaxTransactions = 50;
envConfig.UseLogging = true;
envConfig.UseLocking = true;
envConfig.UseMPool = true;
envConfig.UseTxns = true;
envConfig.TxnNoSync = false;
envConfig.TxnNoWait = true;
envConfig.TxnSnapshot = true;
envConfig.TxnTimestamp = DateTime.Now;
envConfig.TxnWriteNoSync = false;
DatabaseEnvironment env = DatabaseEnvironment.Open(
testHome, envConfig);
try
{
try
{
// Confirm initial transaction subsystem statistics.
stats = env.TransactionSystemStats();
env.PrintTransactionSystemStats(true, true);
Assert.AreEqual(0, stats.Aborted);
Assert.AreEqual(0, stats.Active);
Assert.AreEqual(0, stats.Begun);
Assert.AreEqual(0, stats.Committed);
Assert.AreEqual(0, stats.LastCheckpoint.LogFileNumber);
Assert.AreEqual(0, stats.LastCheckpoint.Offset);
Assert.AreEqual(50, stats.MaxTransactions);
Assert.AreNotEqual(0, stats.RegionSize);
Assert.AreEqual(0, stats.Transactions.Count);
}
catch (AssertionException e)
{
throw e;
}
try
{
//Begin a transaction called openTxn and open a database.
TransactionConfig openTxnCfg = new TransactionConfig();
openTxnCfg.Name = "openTxn";
openTxn = env.BeginTransaction(openTxnCfg);
openTxn.Priority = 50;
BTreeDatabaseConfig dbConfig = new BTreeDatabaseConfig();
dbConfig.Creation = CreatePolicy.IF_NEEDED;
dbConfig.Env = env;
db = BTreeDatabase.Open(testName + ".db", dbConfig, openTxn);
}
catch (DatabaseException e)
{
if (openTxn != null)
openTxn.Abort();
throw e;
}
try
{
// At least there is one transaction that is alive.
env.Checkpoint();
stats = env.TransactionSystemStats();
env.PrintTransactionSystemStats();
Assert.AreNotEqual(0, stats.Active);
Assert.AreNotEqual(0, stats.Transactions.Count);
Assert.AreNotEqual(0, stats.Transactions.Capacity);
Assert.AreNotEqual(0, stats.RegionLockNoWait);
dateTime = stats.LastCheckpointTime;
// Begin an embedded transaction called putTxn.
TransactionConfig putTxnCfg =
new TransactionConfig();
putTxnCfg.Name = "putTxn";
putTxnCfg.NoWait = false;
Transaction putTxn = env.BeginTransaction(
putTxnCfg, openTxn);
putTxn.Priority = 50;
try
{
// Put some records into database within putTxn.
for (int i = 0; i < 50; i++)
db.Put(new DatabaseEntry(BitConverter.GetBytes(i)),
new DatabaseEntry(BitConverter.GetBytes(i)), putTxn);
stats = env.TransactionSystemStats();
Assert.AreNotEqual(0, stats.MaxActive);
Assert.AreNotEqual(0, stats.MaxTransactions);
Assert.AreEqual(0, stats.MaxSnapshot);
Assert.AreEqual(0, stats.Snapshot);
//.........这里部分代码省略.........
示例9: TestLogFile
public void TestLogFile()
{
testName = "TestLogFile";
SetUpTest(true);
// Open environment and configure logging subsystem.
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 = "./";
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);
// Open database.
Transaction allTxn = env.BeginTransaction();
TransactionConfig txnConfig = new TransactionConfig();
txnConfig.Name = "OpenTransaction";
Transaction openTxn = env.BeginTransaction(txnConfig, allTxn);
BTreeDatabaseConfig dbConfig = new BTreeDatabaseConfig();
dbConfig.Creation = CreatePolicy.IF_NEEDED;
dbConfig.Env = env;
BTreeDatabase db = BTreeDatabase.Open(
testName + ".db", dbConfig, openTxn);
List<ActiveTransaction> activeTxns =
env.TransactionSystemStats().Transactions;
for (int i = 0; i < activeTxns.Count; i++)
if (activeTxns[i].Name == "OpenTransaction")
{
LSN lsn = new LSN(
activeTxns[i].Begun.LogFileNumber,
activeTxns[i].Begun.Offset);
env.LogFlush(lsn);
string fileName = env.LogFile(lsn);
}
openTxn.Commit();
// Write "##" to log before putting data into database.
env.WriteToLog("##");
// Write 1000 records into database.
TransactionConfig writeTxnConfig = new TransactionConfig();
writeTxnConfig.Name = "WriteTxn";
Transaction writeTxn = env.BeginTransaction(writeTxnConfig, allTxn);
byte[] byteArr = new byte[1024];
for (int i = 0; i < 1000; i++)
{
db.Put(new DatabaseEntry(BitConverter.GetBytes(i)),
new DatabaseEntry(byteArr), writeTxn);
env.LogFlush();
env.WriteToLog("#" + i.ToString(), writeTxn);
}
activeTxns = env.TransactionSystemStats().Transactions;
for (int i = 0; i < activeTxns.Count; i++)
if (activeTxns[i].Name == "WriteTxn")
{
LSN lsn = new LSN(
activeTxns[i].Begun.LogFileNumber,
activeTxns[i].Begun.Offset);
env.LogFlush(lsn);
string fileName = env.LogFile(lsn);
}
writeTxn.Commit();
db.Close();
// Write "##" after data has been put.
env.WriteToLog("##");
List<string> logFiles = env.LogFiles(true);
env.LogWrite(new DatabaseEntry(), true);
env.RemoveUnusedLogFiles();
allTxn.Commit();
env.Close();
}
示例10: BeginTransaction
/// <summary>
/// Create a new transaction in the environment.
/// </summary>
/// <remarks>
/// In the presence of distributed transactions and two-phase commit,
/// only the parental transaction, that is a transaction without a
/// parent specified, should be passed as an parameter to
/// <see cref="Transaction.Prepare"/>.
/// </remarks>
/// <param name="cfg">
/// The configuration properties for the transaction
/// </param>
/// <param name="parent">
/// If non-null, the new transaction is a nested transaction,
/// with <paramref name="parent"/> as the new transaction's parent.
/// Transactions may be nested to any level.
/// </param>
/// <returns>A new transaction object</returns>
public Transaction BeginTransaction(
TransactionConfig cfg, Transaction parent)
{
DB_TXN dbtxn = dbenv.txn_begin(
Transaction.getDB_TXN(parent), cfg.flags);
Transaction txn = new Transaction(dbtxn);
if (cfg.lockTimeoutIsSet)
txn.SetLockTimeout(cfg.LockTimeout);
if (cfg.nameIsSet)
txn.Name = cfg.Name;
if (cfg.txnTimeoutIsSet)
txn.SetTxnTimeout(cfg.TxnTimeout);
return txn;
}
示例11: TestNestedTXN
public void TestNestedTXN()
{
testName = "TestNestedTXN";
SetUpTest(true);
DatabaseEntry key, data;
DatabaseEnvironment master = SetUpEnv(testHome + "/master", 100, 8000, true);
BTreeDatabase db = Open(master, true);
TransactionConfig txnconfig = new TransactionConfig();
Transaction txn = master.BeginTransaction();
Transaction txn1 = master.BeginTransaction(txnconfig, txn);
key = new DatabaseEntry(
ASCIIEncoding.ASCII.GetBytes("Key"));
data = new DatabaseEntry(
ASCIIEncoding.ASCII.GetBytes("Data"));
db.Put(key, data, txn1);
txn1.Commit();
txn.Commit();
byte[] token;
Assert.Throws<ArgumentException>(delegate { token = txn1.CommitToken; });
master.Close();
}
示例12: ConfirmLogFlush
public static void ConfirmLogFlush(XmlElement xmlElem,
string name, TransactionConfig.LogFlush value,
bool compulsory)
{
XmlNode xmlNode;
string logFlush;
xmlNode = XMLReader.GetNode(xmlElem, name);
if (xmlNode == null && compulsory == true)
throw new ConfigNotFoundException(name);
else if (xmlNode != null)
{
logFlush = xmlNode.InnerText;
if (logFlush == "DEFAULT")
Assert.AreEqual(TransactionConfig.LogFlush.DEFAULT, value);
else if (logFlush == "NOSYNC")
Assert.AreEqual(TransactionConfig.LogFlush.NOSYNC, value);
else if (logFlush == "WRITE_NOSYNC")
Assert.AreEqual(TransactionConfig.LogFlush.WRITE_NOSYNC, value);
else if (logFlush == "SYNC")
Assert.AreEqual(TransactionConfig.LogFlush.SYNC, value);
else
throw new InvalidConfigException(name);
}
}
示例13: ConfigLogFlush
public static bool ConfigLogFlush(XmlElement xmlElem,
string name, ref TransactionConfig.LogFlush value,
bool compulsory)
{
XmlNode xmlNode;
string logFlush;
xmlNode = XMLReader.GetNode(xmlElem, name);
if (xmlNode == null && compulsory == false)
return false;
else if (xmlNode == null && compulsory == true)
throw new ConfigNotFoundException(name);
logFlush = xmlNode.InnerText;
if (logFlush == "DEFAULT")
value = TransactionConfig.LogFlush.DEFAULT;
else if (logFlush == "NOSYNC")
value = TransactionConfig.LogFlush.NOSYNC;
else if (logFlush == "WRITE_NOSYNC")
value = TransactionConfig.LogFlush.WRITE_NOSYNC;
else if (logFlush == "SYNC")
value = TransactionConfig.LogFlush.SYNC;
else
throw new InvalidConfigException(name);
return true;
}
示例14: TestTransactionStatPrint
public void TestTransactionStatPrint()
{
testName = "TestTransactionStatPrint";
SetUpTest(true);
string[] messageInfo = new string[]
{
"No checkpoint LSN",
"Checkpoint timestamp",
"Last transaction ID allocated",
"Maximum number of active transactions configured",
"Initial number of transactions configured",
"Active transactions",
"Maximum active transactions",
"Number of transactions begun",
"Number of transactions aborted",
"Number of transactions committed",
"Snapshot transactions",
"Maximum snapshot transactions",
"Number of transactions restored",
"Region size",
"The number of region locks that required waiting (0%)",
""
};
// Configure and open an environment.
DatabaseEnvironmentConfig envConfig =
new DatabaseEnvironmentConfig();
envConfig.Create = true;
envConfig.FreeThreaded = true;
envConfig.LockTimeout = 1000;
envConfig.MPoolSystemCfg = new MPoolConfig();
envConfig.MPoolSystemCfg.CacheSize = new CacheInfo(0, 104800, 1);
envConfig.UseLocking = true;
envConfig.UseMPool = true;
envConfig.UseTxns = true;
envConfig.MaxTransactions = 50;
DatabaseEnvironment env =
DatabaseEnvironment.Open(testHome, envConfig);
//Begin a transaction called openTxn and open a database.
Transaction openTxn = null;
TransactionConfig openTxnCfg = new TransactionConfig();
openTxnCfg.Name = "openTxn";
openTxn = env.BeginTransaction(openTxnCfg);
openTxn.Priority = 50;
BTreeDatabaseConfig dbConfig = new BTreeDatabaseConfig();
dbConfig.Creation = CreatePolicy.IF_NEEDED;
dbConfig.Env = env;
BTreeDatabase db;
db = BTreeDatabase.Open(testName + ".db", dbConfig, openTxn);
// Confirm message file does not exist.
string messageFile = testHome + "/" + "msgfile";
Assert.AreEqual(false, File.Exists(messageFile));
// Call set_msgfile() of env.
env.Msgfile = messageFile;
// Print env statistic to message file.
env.PrintTransactionSystemStats();
// Confirm message file exists now.
Assert.AreEqual(true, File.Exists(messageFile));
env.Msgfile = "";
int counter = 0;
string line;
line = null;
// Read the message file line by line.
System.IO.StreamReader file = new System.IO.StreamReader(@"" + messageFile);
while ((line = file.ReadLine()) != null)
{
string[] tempStr = line.Split('\t');
// Confirm the content of the message file.
if (tempStr[0] == "Active transactions:")
break;
Assert.AreEqual(messageInfo[counter], tempStr[1]);
counter++;
}
Assert.AreNotEqual(0, counter);
openTxn.Commit();
file.Close();
env.Close();
}