/*- * See the file LICENSE for redistribution information. * * Copyright (c) 2009 Oracle. All rights reserved. * */ using System; using System.Collections.Generic; using System.Text; using BerkeleyDB.Internal; namespace BerkeleyDB { /// /// A class representing configuration parameters for a /// . /// public class TransactionConfig { /// /// Specifies the log flushing behavior on transaction commit /// public enum LogFlush { /// /// Use Berkeley DB's default behavior of syncing the log on commit. /// DEFAULT, /// /// Berkeley DB will not write or synchronously flush the log on /// transaction commit or prepare. /// /// /// /// This means the transaction will exhibit the ACI (atomicity, /// consistency, and isolation) properties, but not D (durability); /// that is, database integrity will be maintained but it is /// possible that this transaction may be undone during recovery. /// /// NOSYNC, /// /// Berkeley DB will write, but will not synchronously flush, the /// log on transaction commit or prepare. /// /// /// /// This means that transactions exhibit the ACI (atomicity, /// consistency, and isolation) properties, but not D (durability); /// that is, database integrity will be maintained, but if the /// system fails, it is possible some number of the most recently /// committed transactions may be undone during recovery. The number /// of transactions at risk is governed by how often the system /// flushes dirty buffers to disk and how often the log is /// checkpointed. /// /// /// For consistent behavior across the environment, all /// objects opened in the /// environment must either set WRITE_NOSYNC, or the /// DB_TXN_WRITE_NOSYNC flag should be specified in the DB_CONFIG /// configuration file. /// /// WRITE_NOSYNC, /// /// Berkeley DB will synchronously flush the log on transaction /// commit or prepare. /// /// /// This means the transaction will exhibit all of the ACID /// (atomicity, consistency, isolation, and durability) properties. /// SYNC }; /// /// The degree of isolation for this transaction /// public Isolation IsolationDegree; /// /// If true and a lock is unavailable for any Berkeley DB operation /// performed in the context of a transaction, cause the operation to /// throw a /// (or if configured with /// ). /// /// /// /// This setting overrides the behavior specified by /// . /// /// public bool NoWait; /// /// If true, this transaction will execute with snapshot isolation. /// /// /// /// For databases with set, data /// values will be read as they are when the transaction begins, without /// taking read locks. Silently ignored for operations on databases with /// not set on the underlying /// database (read locks are acquired). /// /// /// A will be thrown from update /// operations if a snapshot transaction attempts to update data which /// was modified after the snapshot transaction read it. /// /// public bool Snapshot; /// /// Log sync behavior on transaction commit or prepare. /// /// /// /// This setting overrides the behavior specified by /// and /// . /// /// public LogFlush SyncAction; internal uint flags { get { uint ret = 0; switch (IsolationDegree) { case (Isolation.DEGREE_ONE): ret |= DbConstants.DB_READ_UNCOMMITTED; break; case (Isolation.DEGREE_TWO): ret |= DbConstants.DB_READ_COMMITTED; break; } ret |= NoWait ? DbConstants.DB_TXN_NOWAIT : 0; ret |= Snapshot ? DbConstants.DB_TXN_SNAPSHOT : 0; switch (SyncAction) { case (LogFlush.NOSYNC): ret |= DbConstants.DB_TXN_NOSYNC; break; case (LogFlush.SYNC): ret |= DbConstants.DB_TXN_SYNC; break; case (LogFlush.WRITE_NOSYNC): ret |= DbConstants.DB_TXN_WRITE_NOSYNC; break; } return ret; } } private uint _lckTimeout; internal bool lockTimeoutIsSet; /// /// The timeout value for locks for the transaction. /// /// /// /// Timeouts are checked whenever a thread of control blocks on a lock /// or when deadlock detection is performed. This timeout is for any /// single lock request. As timeouts are only checked when the lock /// request first blocks or when deadlock detection is performed, the /// accuracy of the timeout depends on how often deadlock detection is /// performed. /// /// /// Timeout values may be specified for the database environment as a /// whole. See for /// more information. /// /// public uint LockTimeout { get { return _lckTimeout; } set { lockTimeoutIsSet = true; _lckTimeout = value; } } private string _name; internal bool nameIsSet; /// /// The transaction's name. The name is returned by /// /// and displayed by /// . /// /// /// If the database environment has been configured for logging and the /// Berkeley DB library was built in Debug mode (or with DIAGNOSTIC /// defined), a debugging log record is written including the /// transaction ID and the name. /// public string Name { get { return _name; } set { nameIsSet = (value != null); _name = value; } } private uint _txnTimeout; internal bool txnTimeoutIsSet; /// /// The timeout value for locks for the transaction. /// /// /// /// Timeouts are checked whenever a thread of control blocks on a lock /// or when deadlock detection is performed. This timeout is for the /// life of the transaction. As timeouts are only checked when the lock /// request first blocks or when deadlock detection is performed, the /// accuracy of the timeout depends on how often deadlock detection is /// performed. /// /// /// Timeout values may be specified for the database environment as a /// whole. See for /// more information. /// /// public uint TxnTimeout { get { return _txnTimeout; } set { txnTimeoutIsSet = true; _txnTimeout = value; } } /// /// Instantiate a new TransactionConfig object /// public TransactionConfig() { IsolationDegree = Isolation.DEGREE_THREE; SyncAction = LogFlush.DEFAULT; } } }