/*-
* See the file LICENSE for redistribution information.
*
* Copyright (c) 2009, 2015 Oracle and/or its affiliates. All rights reserved.
*
*/
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
using BerkeleyDB.Internal;
namespace BerkeleyDB {
///
/// A class representing a Berkeley DB database environment - a collection
/// including support for some or all of caching, locking, logging and
/// transaction subsystems, as well as databases and log files.
///
public class DatabaseEnvironment {
internal DB_ENV dbenv;
private IBackup backupObj;
private ErrorFeedbackDelegate errFeedbackHandler;
private EnvironmentFeedbackDelegate feedbackHandler;
private ThreadIsAliveDelegate isAliveHandler;
private EventNotifyDelegate notifyHandler;
private MessageDispatchDelegate messageDispatchHandler;
private MessageFeedbackDelegate msgFeedbackHandler;
private ReplicationTransportDelegate transportHandler;
private ReplicationViewDelegate replicationViewHandler;
private SetThreadIDDelegate threadIDHandler;
private SetThreadNameDelegate threadNameHandler;
private string _pfx;
private DBTCopyDelegate CopyDelegate;
private BDB_BackupCloseDelegate doBackupCloseRef;
private BDB_BackupOpenDelegate doBackupOpenRef;
private BDB_BackupWriteDelegate doBackupWriteRef;
private BDB_ErrcallDelegate doErrFeedbackRef;
private BDB_EnvFeedbackDelegate doFeedbackRef;
private BDB_EventNotifyDelegate doNotifyRef;
private BDB_IsAliveDelegate doIsAliveRef;
private BDB_MessageDispatchDelegate doMessageDispatchRef;
private BDB_MsgcallDelegate doMsgFeedbackRef;
private BDB_ReplicationViewDelegate doRepViewRef;
private BDB_RepTransportDelegate doRepTransportRef;
private BDB_ThreadIDDelegate doThreadIDRef;
private BDB_ThreadNameDelegate doThreadNameRef;
private static long GIGABYTE = (long)(1 << 30);
#region Callbacks
private static int doBackupClose(IntPtr env, string dbname, IntPtr handle) {
DB_ENV dbenv = new DB_ENV(env, false);
return dbenv.api2_internal.backupObj.Close(dbname);
}
private static int doBackupOpen(IntPtr env, string dbname, string target, IntPtr handle) {
DB_ENV dbenv = new DB_ENV(env, false);
return dbenv.api2_internal.backupObj.Open(dbname, target);
}
private static int doBackupWrite(IntPtr env, uint off_gbytes, uint off_bytes, uint usize, IntPtr buf, IntPtr handle) {
int ret, size;
long offset = off_gbytes * GIGABYTE + off_bytes;
DB_ENV dbenv = new DB_ENV(env, false);
if (usize > Int32.MaxValue)
size = Int32.MaxValue;
else
size = (int)usize;
byte[] data = new byte[size];
Marshal.Copy(buf, data, 0, (int)size);
ret = dbenv.api2_internal.backupObj.Write(data, offset, (int)size);
if (ret == 0 && usize > Int32.MaxValue) {
size = (int)(usize - Int32.MaxValue);
/*
* There's no need to re-allocate data, it's already as large as
* we could possibly need it to be. Advance buf beyond what was
* just copied and write the remaining data.
*/
buf = new IntPtr(buf.ToInt64() + Int32.MaxValue);
Marshal.Copy(buf, data, 0, (int)size);
ret = dbenv.api2_internal.backupObj.Write(data, offset, (int)size);
}
return ret;
}
private static void doNotify(IntPtr env, uint eventcode, byte[] event_info) {
DB_ENV dbenv = new DB_ENV(env, false);
dbenv.api2_internal.notifyHandler(
(NotificationEvent)eventcode, event_info);
}
private static void doErrFeedback(IntPtr env, string pfx, string msg) {
DB_ENV dbenv = new DB_ENV(env, false);
dbenv.api2_internal.errFeedbackHandler(
dbenv.api2_internal._pfx, msg);
}
private static void doMsgFeedback(IntPtr env, string msg) {
DB_ENV dbenv = new DB_ENV(env, false);
dbenv.api2_internal.msgFeedbackHandler(msg);
}
private static void doFeedback(IntPtr env, int opcode, int percent) {
DB_ENV dbenv = new DB_ENV(env, false);
dbenv.api2_internal.feedbackHandler(
(EnvironmentFeedbackEvent)opcode, percent);
}
private static int doIsAlive(IntPtr env, int pid, uint tid, uint flags) {
DB_ENV dbenv = new DB_ENV(env, false);
DbThreadID id = new DbThreadID(pid, tid);
bool procOnly = (flags == DbConstants.DB_MUTEX_PROCESS_ONLY);
return dbenv.api2_internal.isAliveHandler(id, procOnly) ? 1 : 0;
}
private static void doMessageDispatch(IntPtr env, IntPtr channel,
IntPtr requestp, uint nrequest, uint cb_flags) {
DB_ENV dbenv = new DB_ENV(env, false);
DbChannel dbchannel = new DbChannel(new DB_CHANNEL(channel, false));
bool need_response =
(cb_flags == DbConstants.DB_REPMGR_NEED_RESPONSE);
IntPtr[] reqp = new IntPtr[nrequest];
Marshal.Copy(requestp, reqp, 0, (int)nrequest);
DatabaseEntry[] requests = new DatabaseEntry[nrequest];
for (int i = 0; i < nrequest; i++) {
requests[i] = DatabaseEntry.fromDBT(new DBT(reqp[i], false));
}
dbenv.api2_internal.messageDispatchHandler(
dbchannel, ref requests, out nrequest, need_response);
}
private static int doRepView(IntPtr envp,
string name, ref int result, uint flags) {
DB_ENV dbenv = new DB_ENV(envp, false);
return dbenv.api2_internal.replicationViewHandler(name,
ref result, flags);
}
private static int doRepTransport(IntPtr envp,
IntPtr controlp, IntPtr recp, IntPtr lsnp, int envid, uint flags) {
DB_ENV dbenv = new DB_ENV(envp, false);
DBT control = new DBT(controlp, false);
DBT rec = new DBT(recp, false);
DB_LSN tmplsn = new DB_LSN(lsnp, false);
LSN dblsn = new LSN(tmplsn.file, tmplsn.offset);
return dbenv.api2_internal.transportHandler(
DatabaseEntry.fromDBT(control),
DatabaseEntry.fromDBT(rec), dblsn, envid, flags);
}
private static void doThreadID(IntPtr env, IntPtr pid, IntPtr tid) {
DB_ENV dbenv = new DB_ENV(env, false);
DbThreadID id = dbenv.api2_internal.threadIDHandler();
/*
* Sometimes the library does not care about either pid or tid
* (usually tid) and will pass NULL instead of a valid pointer.
*/
if (pid != IntPtr.Zero)
Marshal.WriteInt32(pid, id.processID);
if (tid != IntPtr.Zero)
Marshal.WriteInt32(tid, (int)id.threadID);
}
private static string doThreadName(IntPtr env,
int pid, uint tid, ref string buf) {
DB_ENV dbenv = new DB_ENV(env, false);
DbThreadID id = new DbThreadID(pid, tid);
string ret =
dbenv.api2_internal.threadNameHandler(id);
try {
buf = ret;
} catch (NullReferenceException) {
/*
* The library may give us a NULL pointer in buf and there's no
* good way to test for that. Just ignore the exception if
* we're not able to set buf.
*/
}
return ret;
}
#endregion Callbacks
private DatabaseEnvironment(uint flags) {
dbenv = new DB_ENV(flags);
initialize();
}
/* Called by Databases with private environments. */
internal DatabaseEnvironment(DB_ENV dbenvp) {
dbenv = dbenvp;
initialize();
}
private void initialize() {
dbenv.api2_internal = this;
CopyDelegate = new DBTCopyDelegate(DatabaseEntry.dbt_usercopy);
dbenv.set_usercopy(CopyDelegate);
}
private void Config(DatabaseEnvironmentConfig cfg) {
//Alpha by dbenv function call
foreach (string dirname in cfg.DataDirs)
dbenv.add_data_dir(dirname);
if (cfg.BlobDir != null)
dbenv.set_blob_dir(cfg.BlobDir);
if (cfg.blobThresholdIsSet)
dbenv.set_blob_threshold(cfg.BlobThreshold, 0);
if (cfg.CreationDir != null)
dbenv.set_create_dir(cfg.CreationDir);
if (cfg.encryptionIsSet)
dbenv.set_encrypt(
cfg.EncryptionPassword, (uint)cfg.EncryptAlgorithm);
if (cfg.MetadataDir != null)
dbenv.set_metadata_dir(cfg.MetadataDir);
if (cfg.ErrorFeedback != null)
ErrorFeedback = cfg.ErrorFeedback;
ErrorPrefix = cfg.ErrorPrefix;
if (cfg.EventNotify != null)
EventNotify = cfg.EventNotify;
if (cfg.Feedback != null)
Feedback = cfg.Feedback;
if (cfg.IntermediateDirMode != null)
IntermediateDirMode = cfg.IntermediateDirMode;
if (cfg.ThreadIsAlive != null)
ThreadIsAlive = cfg.ThreadIsAlive;
if (cfg.threadCntIsSet)
ThreadCount = cfg.ThreadCount;
if (cfg.SetThreadID != null)
SetThreadID = cfg.SetThreadID;
if (cfg.ThreadName != null)
threadNameHandler = cfg.ThreadName;
if (cfg.lckTimeoutIsSet)
LockTimeout = cfg.LockTimeout;
if (cfg.txnTimeoutIsSet)
TxnTimeout = cfg.TxnTimeout;
if (cfg.TempDir != null)
TempDir = cfg.TempDir;
if (cfg.maxTxnsIsSet)
MaxTransactions = cfg.MaxTransactions;
if (cfg.txnTimestampIsSet)
TxnTimestamp = cfg.TxnTimestamp;
if (cfg.Verbosity != null)
Verbosity = cfg.Verbosity;
if (cfg.flags != 0)
dbenv.set_flags(cfg.flags, 1);
if (cfg.initThreadCountIsSet)
InitThreadCount = cfg.InitThreadCount;
if (cfg.initTxnCountIsSet)
InitTxnCount = cfg.InitTxnCount;
if (cfg.LockSystemCfg != null) {
if (cfg.LockSystemCfg.Conflicts != null)
LockConflictMatrix = cfg.LockSystemCfg.Conflicts;
if (cfg.LockSystemCfg.DeadlockResolution != null)
DeadlockResolution = cfg.LockSystemCfg.DeadlockResolution;
if (cfg.LockSystemCfg.initLockerCountIsSet)
InitLockerCount = cfg.LockSystemCfg.InitLockerCount;
if (cfg.LockSystemCfg.initLockCountIsSet)
InitLockCount = cfg.LockSystemCfg.InitLockCount;
if (cfg.LockSystemCfg.initLockObjectCountIsSet)
InitLockObjectCount = cfg.LockSystemCfg.InitLockObjectCount;
if (cfg.LockSystemCfg.maxLockersIsSet)
MaxLockers = cfg.LockSystemCfg.MaxLockers;
if (cfg.LockSystemCfg.maxLocksIsSet)
MaxLocks = cfg.LockSystemCfg.MaxLocks;
if (cfg.LockSystemCfg.maxObjectsIsSet)
MaxObjects = cfg.LockSystemCfg.MaxObjects;
if (cfg.LockSystemCfg.partitionsIsSet)
LockPartitions = cfg.LockSystemCfg.Partitions;
if (cfg.LockSystemCfg.tablesizeIsSet)
LockTableSize = cfg.LockSystemCfg.TableSize;
}
if (cfg.LogSystemCfg != null) {
if (cfg.LogSystemCfg.bsizeIsSet)
LogBufferSize = cfg.LogSystemCfg.BufferSize;
if (cfg.LogSystemCfg.Dir != null)
LogDir = cfg.LogSystemCfg.Dir;
if (cfg.LogSystemCfg.initLogIdCountIsSet)
InitLogIdCount = cfg.LogSystemCfg.InitLogIdCount;
if (cfg.LogSystemCfg.modeIsSet)
LogFileMode = cfg.LogSystemCfg.FileMode;
if (cfg.LogSystemCfg.maxSizeIsSet)
MaxLogFileSize = cfg.LogSystemCfg.MaxFileSize;
if (cfg.LogSystemCfg.regionSizeIsSet)
LogRegionSize = cfg.LogSystemCfg.RegionSize;
if (cfg.LogSystemCfg.ConfigFlags != 0)
dbenv.log_set_config(cfg.LogSystemCfg.ConfigFlags, 1);
}
if (cfg.MPoolSystemCfg != null) {
if (cfg.MPoolSystemCfg.CacheSize != null)
CacheSize = cfg.MPoolSystemCfg.CacheSize;
if (cfg.MPoolSystemCfg.MaxCacheSize != null)
MaxCacheSize = cfg.MPoolSystemCfg.MaxCacheSize;
if (cfg.MPoolSystemCfg.maxOpenFDIsSet)
MaxOpenFiles = cfg.MPoolSystemCfg.MaxOpenFiles;
if (cfg.MPoolSystemCfg.maxSeqWriteIsSet)
SetMaxSequentialWrites(
cfg.MPoolSystemCfg.MaxSequentialWrites,
cfg.MPoolSystemCfg.SequentialWritePause);
if (cfg.MPoolSystemCfg.mmapSizeSet)
MMapSize = cfg.MPoolSystemCfg.MMapSize;
}
if (cfg.MutexSystemCfg != null) {
if (cfg.MutexSystemCfg.alignmentIsSet)
MutexAlignment = cfg.MutexSystemCfg.Alignment;
/*
* Setting max after increment ensures that the value of max
* will win if both max and increment are set. This is the
* behavior we document in MutexConfig.
*/
if (cfg.MutexSystemCfg.incrementIsSet)
MutexIncrement = cfg.MutexSystemCfg.Increment;
if (cfg.MutexSystemCfg.initMutexesIsSet)
InitMutexes = cfg.MutexSystemCfg.InitMutexes;
if (cfg.MutexSystemCfg.maxMutexesIsSet)
MaxMutexes = cfg.MutexSystemCfg.MaxMutexes;
if (cfg.MutexSystemCfg.numTASIsSet)
NumTestAndSetSpins = cfg.MutexSystemCfg.NumTestAndSetSpins;
}
if (cfg.RepSystemCfg != null) {
if (cfg.RepSystemCfg.ackTimeoutIsSet)
RepAckTimeout = cfg.RepSystemCfg.AckTimeout;
if (cfg.RepSystemCfg.BulkTransfer)
RepBulkTransfer = true;
if (cfg.RepSystemCfg.checkpointDelayIsSet)
RepCheckpointDelay = cfg.RepSystemCfg.CheckpointDelay;
if (cfg.RepSystemCfg.clockskewIsSet)
RepSetClockskew(cfg.RepSystemCfg.ClockskewFast,
cfg.RepSystemCfg.ClockskewSlow);
if (cfg.RepSystemCfg.connectionRetryIsSet)
RepConnectionRetry = cfg.RepSystemCfg.ConnectionRetry;
if (cfg.RepSystemCfg.DelayClientSync)
RepDelayClientSync = true;
if (cfg.RepSystemCfg.electionRetryIsSet)
RepElectionRetry = cfg.RepSystemCfg.ElectionRetry;
if (cfg.RepSystemCfg.electionTimeoutIsSet)
RepElectionTimeout = cfg.RepSystemCfg.ElectionTimeout;
if (cfg.RepSystemCfg.fullElectionTimeoutIsSet)
RepFullElectionTimeout =
cfg.RepSystemCfg.FullElectionTimeout;
if (cfg.RepSystemCfg.heartbeatMonitorIsSet)
RepHeartbeatMonitor = cfg.RepSystemCfg.HeartbeatMonitor;
if (cfg.RepSystemCfg.heartbeatSendIsSet)
RepHeartbeatSend = cfg.RepSystemCfg.HeartbeatSend;
if (cfg.RepSystemCfg.InMemory)
dbenv.rep_set_config(DbConstants.DB_REP_CONF_INMEM, 1);
if (cfg.RepSystemCfg.leaseTimeoutIsSet)
RepLeaseTimeout = cfg.RepSystemCfg.LeaseTimeout;
if (!cfg.RepSystemCfg.AutoInit)
RepAutoInit = false;
if (cfg.RepSystemCfg.NoBlocking)
RepNoBlocking = true;
if (cfg.RepSystemCfg.nsitesIsSet)
RepNSites = cfg.RepSystemCfg.NSites;
for (int i = 0; i < cfg.RepSystemCfg.RepmgrSitesConfig.Count; i++)
RepMgrSiteConfig(cfg.RepSystemCfg.RepmgrSitesConfig[i]);
if (cfg.RepSystemCfg.repViewIsSet) {
ReplicationView = cfg.RepSystemCfg.ReplicationView;
if (ReplicationView == null)
doRepViewRef = null;
else
doRepViewRef = new BDB_ReplicationViewDelegate(doRepView);
dbenv.rep_set_view(doRepViewRef);
}
if (cfg.RepSystemCfg.priorityIsSet)
RepPriority = cfg.RepSystemCfg.Priority;
if (cfg.RepSystemCfg.RepMgrAckPolicy != null)
RepMgrAckPolicy = cfg.RepSystemCfg.RepMgrAckPolicy;
if (cfg.RepSystemCfg.retransmissionRequestIsSet)
RepSetRetransmissionRequest(
cfg.RepSystemCfg.RetransmissionRequestMin,
cfg.RepSystemCfg.RetransmissionRequestMax);
if (cfg.RepSystemCfg.Strict2Site)
RepStrict2Site = true;
if (cfg.RepSystemCfg.transmitLimitIsSet)
RepSetTransmitLimit(
cfg.RepSystemCfg.TransmitLimitGBytes,
cfg.RepSystemCfg.TransmitLimitBytes);
if (cfg.RepSystemCfg.repmgrIncomingQueueMaxIsSet)
RepmgrSetIncomingQueueMax(
cfg.RepSystemCfg.RepmgrIncomingQueueMaxGBytes,
cfg.RepSystemCfg.RepmgrIncomingQueueMaxBytes);
if (cfg.RepSystemCfg.UseMasterLeases)
RepUseMasterLeases = true;
if (!cfg.RepSystemCfg.Elections)
RepMgrRunElections = false;
if (cfg.RepSystemCfg.PrefmasMaster)
RepPrefmasMaster = true;
if (cfg.RepSystemCfg.PrefmasClient)
RepPrefmasClient = true;
}
}
#region Properties
///
/// If true, database operations for which no explicit transaction
/// handle was specified, and which modify databases in the database
/// environment, are automatically enclosed within a transaction.
///
public bool AutoCommit {
get {
uint flags = 0;
dbenv.get_flags(ref flags);
return (flags & DbConstants.DB_AUTO_COMMIT) != 0;
}
set {
dbenv.set_flags(DbConstants.DB_AUTO_COMMIT, value ? 1 : 0);
}
}
///
/// The size of the buffer, in bytes, to read from the database during a
/// hot backup.
///
public uint BackupBufferSize {
get {
uint ret = 0;
dbenv.get_backup_config(DbConstants.DB_BACKUP_SIZE, ref ret);
return ret;
}
set {
dbenv.set_backup_config(DbConstants.DB_BACKUP_SIZE, value);
}
}
///
/// Sets the interface to be used when performing
/// hot backups.
///
/// This interface is used to override the default behavior used by the
/// and
/// methods.
///
///
public IBackup BackupHandler {
get { return backupObj; }
set {
if (value == null) {
dbenv.set_backup_callbacks(null, null, null);
} else if (backupObj == null) {
if (doBackupCloseRef == null)
doBackupCloseRef =
new BDB_BackupCloseDelegate(doBackupClose);
if (doBackupOpenRef == null)
doBackupOpenRef =
new BDB_BackupOpenDelegate(doBackupOpen);
if (doBackupWriteRef == null)
doBackupWriteRef =
new BDB_BackupWriteDelegate(doBackupWrite);
dbenv.set_backup_callbacks(
doBackupOpenRef, doBackupWriteRef, doBackupCloseRef);
}
backupObj = value;
}
}
///
/// The number of pages to read before pausing during the hot backup.
///
/// Increasing this value increases the amount of I/O the backup process
/// performs for any given time interval. If your application is already
/// heavily I/O bound, setting this value to a lower number may help to
/// improve your overall data throughput by reducing the I/O demands
/// placed on your system. By default, all pages are read without a
/// pause.
///
///
public uint BackupReadCount {
get {
uint ret = 0;
dbenv.get_backup_config(DbConstants.DB_BACKUP_READ_COUNT, ref ret);
return ret;
}
set {
dbenv.set_backup_config(DbConstants.DB_BACKUP_READ_COUNT, value);
}
}
///
/// The number of microseconds to sleep between batches of reads during
/// a hot backup.
///
/// Increasing this value decreases the amount of I/O the backup process
/// performs for any given time interval. If your application is already
/// heavily I/O bound, setting this value to a higher number may help to
/// improve your overall data throughput by reducing the I/O demands
/// placed on your system.
///
///
public uint BackupReadSleepDuration {
get {
uint ret = 0;
dbenv.get_backup_config(DbConstants.DB_BACKUP_READ_SLEEP, ref ret);
return ret;
}
set {
dbenv.set_backup_config(DbConstants.DB_BACKUP_READ_SLEEP, value);
}
}
///
/// If true, direct I/O is used when writing pages to the disk during a
/// hot backup.
///
/// For some environments, direct I/O can provide faster write
/// throughput, but usually it is slower because the OS buffer pool
/// offers asynchronous activity.
///
///
public bool BackupWriteDirect {
get {
uint ret = 0;
dbenv.get_backup_config(DbConstants.DB_BACKUP_WRITE_DIRECT, ref ret);
return ret != 0;
}
set {
dbenv.set_backup_config(DbConstants.DB_BACKUP_WRITE_DIRECT, (uint)(value ? 1 : 0));
}
}
///
/// The path of the directory where blobs are stored.
///
public string BlobDir {
get {
string dir;
dbenv.get_blob_dir(out dir);
return dir;
}
}
///
/// The size in bytes which is used to determine when a data item
/// is stored as a blob.
///
/// Any data item that is equal to or larger in size than the
/// threshold value is automatically stored as a blob.
///
///
/// If the threshold value is 0, databases opened in the environment
/// default to never using blob support.
///
///
/// It is illegal to enable blob support if replication is enabled for the
/// environment.
///
///
public uint BlobThreshold {
get {
uint ret = 0;
dbenv.get_blob_threshold(ref ret);
return ret;
}
set {
dbenv.set_blob_threshold(value, 0);
}
}
///
/// The size of the shared memory buffer pool (the cache).
///
///
///
/// The cache should be the size of the normal working data set of the
/// application, with some small amount of additional memory for unusual
/// situations. (Note: the working set is not the same as the number of
/// pages accessed simultaneously, and is usually much larger.)
///
///
/// The default cache size is 256KB, and may not be specified as less
/// than 20KB. Any cache size less than 500MB is automatically increased
/// by 25% to account for buffer pool overhead; cache sizes larger than
/// 500MB are used as specified. The maximum size of a single cache is
/// 4GB on 32-bit systems and 10TB on 64-bit systems. (All sizes are in
/// powers-of-two, 256KB is 2^18 not 256,000.) For information
/// on tuning the Berkeley DB cache size, see Selecting a cache size in
/// the Programmer's Reference Guide.
///
///
public CacheInfo CacheSize {
get {
uint gb = 0;
uint b = 0;
int n = 0;
dbenv.get_cachesize(ref gb, ref b, ref n);
return new CacheInfo(gb, b, n);
}
set {
if (value != null)
dbenv.set_cachesize(
value.Gigabytes, value.Bytes, value.NCaches);
}
}
///
/// If true, Berkeley DB Concurrent Data Store applications perform
/// locking on an environment-wide basis rather than on a per-database
/// basis.
///
public bool CDB_ALLDB {
get {
uint flags = 0;
dbenv.get_flags(ref flags);
return (flags & DbConstants.DB_CDB_ALLDB) != 0;
}
}
///
/// If true, Berkeley DB subsystems create any underlying files, as
/// necessary.
///
public bool Create {
get {
uint flags = 0;
dbenv.get_open_flags(ref flags);
return (flags & DbConstants.DB_CREATE) != 0;
}
}
///
/// The array of directories where database files are stored.
///
public List DataDirs { get { return dbenv.get_data_dirs(); } }
///
/// The deadlock detector configuration, specifying which lock request(s)
/// should be rejected. As transactions acquire locks on behalf of a
/// single locker ID, rejecting a lock request associated with a
/// transaction normally requires the transaction to be aborted.
///
public DeadlockPolicy DeadlockResolution {
get {
uint mode = 0;
dbenv.get_lk_detect(ref mode);
return DeadlockPolicy.fromPolicy(mode);
}
set {
if (value != null)
dbenv.set_lk_detect(value.policy);
else
dbenv.set_lk_detect(DeadlockPolicy.DEFAULT.policy);
}
}
///
/// The algorithm used by the Berkeley DB library to perform encryption
/// and decryption.
///
public EncryptionAlgorithm EncryptAlgorithm {
get {
uint flags = 0;
dbenv.get_encrypt_flags(ref flags);
return (EncryptionAlgorithm)Enum.ToObject(
typeof(EncryptionAlgorithm), flags);
}
}
///
/// The mechanism for reporting detailed error messages to the
/// application.
///
///
///
/// When an error occurs in the Berkeley DB library, a
/// , or subclass of DatabaseException,
/// is thrown. In some cases the exception may be insufficient
/// to completely describe the cause of the error, especially during
/// initial application debugging.
///
///
/// In some cases, when an error occurs, Berkeley DB calls the given
/// delegate with additional error information. It is up to the delegate
/// to display the error message in an appropriate manner.
///
///
/// Setting ErrorFeedback to NULL unconfigures the callback interface.
///
///
/// This error-logging enhancement does not slow performance or
/// significantly increase application size, and may be run during
/// normal operation as well as during application debugging.
///
///
public ErrorFeedbackDelegate ErrorFeedback {
get { return errFeedbackHandler; }
set {
if (value == null)
dbenv.set_errcall(null);
else if (errFeedbackHandler == null) {
if (doErrFeedbackRef == null)
doErrFeedbackRef = new BDB_ErrcallDelegate(doErrFeedback);
dbenv.set_errcall(doErrFeedbackRef);
}
errFeedbackHandler = value;
}
}
///
/// The mechanism for reporting detailed statistic messages to the
/// application.
///
///
///
/// There are interfaces in the Berkeley DB library which either
/// directly output informational messages or statistical
/// information, or configure the library to output such messages
/// when performing other operations.
///
///
/// Berkeley DB calls the given delegate with each message. It is up
/// to the delegate to display the message in an appropriate manner.
///
///
/// Setting MessageFeedback to NULL resets the callback interface.
///
///
public MessageFeedbackDelegate messageFeedback {
get { return msgFeedbackHandler; }
set {
if (value == null)
dbenv.set_msgcall(null);
else if (msgFeedbackHandler == null) {
if (doMsgFeedbackRef == null)
doMsgFeedbackRef = new BDB_MsgcallDelegate(doMsgFeedback);
dbenv.set_msgcall(doMsgFeedbackRef);
}
msgFeedbackHandler = value;
}
}
///
/// The prefix string that appears before error messages issued by
/// Berkeley DB.
///
///
///
/// For databases opened inside of a DatabaseEnvironment, setting
/// ErrorPrefix affects the entire environment and is equivalent to
/// setting .
///
///
/// Setting ErrorPrefix configures operations performed using the
/// specified object, not all operations performed on the underlying
/// database.
///
///
public string ErrorPrefix {
get { return _pfx; }
set { _pfx = value; }
}
///
/// A delegate which is called to notify the process of specific
/// Berkeley DB events.
///
public EventNotifyDelegate EventNotify {
get { return notifyHandler; }
set {
if (value == null)
dbenv.set_event_notify(null);
else if (notifyHandler == null) {
if (doNotifyRef == null)
doNotifyRef = new BDB_EventNotifyDelegate(doNotify);
dbenv.set_event_notify(doNotifyRef);
}
notifyHandler = value;
}
}
///
/// Monitor progress within long running operations.
///
///
///
/// Some operations performed by the Berkeley DB library can take
/// non-trivial amounts of time. When an operation
/// is likely to take a long time, Berkeley DB calls the
/// the Feedback delegate to monitor progress within these operations.
///
///
/// It is up to the delegate to display this information in an
/// appropriate manner.
///
///
public EnvironmentFeedbackDelegate Feedback {
get { return feedbackHandler; }
set {
if (value == null)
dbenv.set_feedback(null);
else if (feedbackHandler == null) {
if (doFeedbackRef == null)
doFeedbackRef = new BDB_EnvFeedbackDelegate(doFeedback);
dbenv.set_feedback(doFeedbackRef);
}
feedbackHandler = value;
}
}
///
/// If true, flush database writes to the backing disk before returning
/// from the write system call, rather than flushing database writes
/// explicitly in a separate system call, as necessary.
///
///
/// This flag may result in inaccurate file modification times and other
/// file-level information for Berkeley DB database files. This flag
/// almost certainly results in a performance decrease on most
/// systems.
///
public bool ForceFlush {
get {
uint flags = 0;
dbenv.get_flags(ref flags);
return (flags & DbConstants.DB_DSYNC_DB) != 0;
}
set {
dbenv.set_flags(DbConstants.DB_DSYNC_DB, value ? 1 : 0);
}
}
///
/// If true, the object is free-threaded; that is, concurrently usable
/// by multiple threads in the address space.
///
public bool FreeThreaded {
get {
uint flags = 0;
dbenv.get_open_flags(ref flags);
return (flags & DbConstants.DB_THREAD) != 0;
}
}
///
/// The database environment home directory.
///
public string Home {
get {
string dir = "";
dbenv.get_home(out dir);
return dir;
}
}
///
/// Whether there is any hot backup in progress.
///
public bool HotbackupInProgress {
get {
uint flags = 0;
dbenv.get_flags(ref flags);
return (flags & DbConstants.DB_HOTBACKUP_IN_PROGRESS) != 0;
}
set {
dbenv.set_flags(
DbConstants.DB_HOTBACKUP_IN_PROGRESS, value ? 1 : 0);
}
}
///
/// The number of locks allocated when the environment is created
///
public uint InitLockCount {
get {
uint ret = 0;
dbenv.get_memory_init(DbConstants.DB_MEM_LOCK, ref ret);
return ret;
}
private set {
dbenv.set_memory_init(DbConstants.DB_MEM_LOCK, value);
}
}
///
/// The number of lock objects allocated when the environment is created
///
public uint InitLockObjectCount {
get {
uint ret = 0;
dbenv.get_memory_init(DbConstants.DB_MEM_LOCKOBJECT, ref ret);
return ret;
}
private set {
dbenv.set_memory_init(DbConstants.DB_MEM_LOCKOBJECT, value);
}
}
///
/// The number of lockers allocated when the environment is created
///
public uint InitLockerCount {
get {
uint ret = 0;
dbenv.get_memory_init(DbConstants.DB_MEM_LOCKER, ref ret);
return ret;
}
private set {
dbenv.set_memory_init(DbConstants.DB_MEM_LOCKER, value);
}
}
///
/// The number of log identifier objects allocated when the
/// environment is created
///
public uint InitLogIdCount {
get {
uint ret = 0;
dbenv.get_memory_init(DbConstants.DB_MEM_LOGID, ref ret);
return ret;
}
private set {
dbenv.set_memory_init(DbConstants.DB_MEM_LOGID, value);
}
}
///
/// The number of thread objects allocated when the environment is
/// created
///
public uint InitThreadCount {
get {
uint ret = 0;
dbenv.get_memory_init(DbConstants.DB_MEM_THREAD, ref ret);
return ret;
}
private set {
dbenv.set_memory_init(DbConstants.DB_MEM_THREAD, value);
}
}
///
/// The number of transaction objects allocated when the environment is
/// created
///
public uint InitTxnCount {
get {
uint ret = 0;
dbenv.get_memory_init(DbConstants.DB_MEM_TRANSACTION, ref ret);
return ret;
}
private set {
dbenv.set_memory_init(DbConstants.DB_MEM_TRANSACTION, value);
}
}
///
/// The initial number of mutexes allocated
///
public uint InitMutexes {
get {
uint ret = 0;
dbenv.mutex_get_init(ref ret);
return ret;
}
private set {
dbenv.mutex_set_init(value);
}
}
///
/// If true, Berkeley DB page-faults shared regions into memory when
/// initially creating or joining a Berkeley DB environment.
///
///
///
/// In some applications, the expense of page-faulting the underlying
/// shared memory regions can affect performance. (For example, if the
/// page-fault occurs while holding a lock, other lock requests can
/// convoy, and overall throughput may decrease.)
///
///
/// In addition to page-faulting, Berkeley DB writes the shared
/// regions when creating an environment, forcing the underlying virtual
/// memory and filesystems to instantiate both the necessary memory and
/// the necessary disk space. This can also avoid out-of-disk space
/// failures later on.
///
///
public bool InitRegions {
get {
uint flags = 0;
dbenv.get_flags(ref flags);
return (flags & DbConstants.DB_REGION_INIT) != 0;
}
set {
dbenv.set_flags(DbConstants.DB_REGION_INIT, value ? 1 : 0);
}
}
///
/// The intermediate directory permissions.
///
public string IntermediateDirMode {
get {
string ret;
dbenv.get_intermediate_dir_mode(out ret);
return ret;
}
private set {
dbenv.set_intermediate_dir_mode(value);
}
}
///
/// The current lock conflicts array.
///
public byte[,] LockConflictMatrix {
get {
int sz = 0;
dbenv.get_lk_conflicts_nmodes(ref sz);
byte [,] ret = new byte[sz, sz];
dbenv.get_lk_conflicts(ret);
return ret;
}
private set {
// Matrix dimensions checked in LockingConfig.
dbenv.set_lk_conflicts(value, (int)Math.Sqrt(value.Length));
}
}
///
/// If true, lock shared Berkeley DB environment files and memory-mapped
/// databases into memory.
///
public bool Lockdown {
get {
uint flags = 0;
dbenv.get_open_flags(ref flags);
return (flags & DbConstants.DB_LOCKDOWN) != 0;
}
}
///
/// The size of the lock table in the Berkeley DB environment.
///
public uint LockTableSize {
get {
uint ret = 0;
dbenv.get_lk_tablesize(ref ret);
return ret;
}
private set {
dbenv.set_lk_tablesize(value);
}
}
///
/// The number of lock table partitions used in the Berkeley DB
/// environment.
///
public uint LockPartitions {
get {
uint ret = 0;
dbenv.get_lk_partitions(ref ret);
return ret;
}
private set {
dbenv.set_lk_partitions(value);
}
}
///
/// A value, in microseconds, representing lock timeouts.
///
///
///
/// All timeouts are checked whenever a thread of control blocks on a
/// lock or when deadlock detection is performed. 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 specified for the database environment may be
/// overridden on a per-transaction basis, see
/// .
///
///
public uint LockTimeout {
get {
uint timeout = 0;
dbenv.get_timeout(ref timeout, DbConstants.DB_SET_LOCK_TIMEOUT);
return timeout;
}
set {
dbenv.set_timeout(value, DbConstants.DB_SET_LOCK_TIMEOUT);
}
}
///
/// If true, enables full logging of blob data.
/// Required if using HA or the hotbackup utility.
///
public bool LogBlobContent {
get {
int onoff = 0;
dbenv.log_get_config(DbConstants.DB_LOG_BLOB, ref onoff);
return (onoff != 0);
}
set {
dbenv.log_set_config(DbConstants.DB_LOG_BLOB, value ? 1 : 0);
}
}
///
/// The size of the in-memory log buffer, in bytes
///
public uint LogBufferSize {
get {
uint ret = 0;
dbenv.get_lg_bsize(ref ret);
return ret;
}
private set {
dbenv.set_lg_bsize(value);
}
}
///
/// The path of a directory to be used as the location of logging files.
/// Log files created by the Log Manager subsystem are created in
/// this directory.
///
public string LogDir {
get {
string ret;
dbenv.get_lg_dir(out ret);
return ret;
}
private set {
dbenv.set_lg_dir(value);
}
}
///
/// The absolute file mode for created log files. This property is only
/// useful for the rare Berkeley DB application that does not control
/// its umask value.
///
///
/// Normally, if Berkeley DB applications set their umask appropriately,
/// all processes in the application suite obtain read permission on
/// the log files created by any process in the application suite.
/// However, if the Berkeley DB application is a library, a process
/// using the library might set its umask to a value preventing other
/// processes in the application suite from reading the log files it
/// creates. In this rare case, this property can be used to set the
/// mode of created log files to an absolute value.
///
public int LogFileMode {
get {
int ret = 0;
dbenv.get_lg_filemode(ref ret);
return ret;
}
set {
dbenv.set_lg_filemode(value);
}
}
///
/// If true, system buffering is turned off for Berkeley DB log files to
/// avoid double caching.
///
public bool LogNoBuffer {
get {
int onoff = 0;
dbenv.log_get_config(DbConstants.DB_LOG_DIRECT, ref onoff);
return (onoff != 0);
}
set {
dbenv.log_set_config(DbConstants.DB_LOG_DIRECT, value ? 1 : 0);
}
}
///
/// If true, Berkeley DB flushes log writes to the backing disk
/// before returning from the write system call, rather than flushing
/// log writes explicitly in a separate system call, as necessary.
///
public bool LogForceSync {
get{
int onoff = 0;
dbenv.log_get_config(DbConstants.DB_LOG_DSYNC, ref onoff);
return (onoff != 0);
}
set {
dbenv.log_set_config(DbConstants.DB_LOG_DSYNC, value ? 1 : 0);
}
}
///
/// If true, Berkeley DB automatically removes log files that are no
/// longer needed.
///
public bool LogAutoRemove {
get {
int onoff = 0;
dbenv.log_get_config(DbConstants.DB_LOG_AUTO_REMOVE, ref onoff);
return (onoff != 0);
}
set {
dbenv.log_set_config(
DbConstants.DB_LOG_AUTO_REMOVE, value ? 1 : 0);
}
}
///
/// If true, Berkeley DB avoids the fsync() call when the log files are
/// flushed.
///
public bool LogNoSync {
get {
int onoff = 0;
dbenv.log_get_config(DbConstants.DB_LOG_NOSYNC, ref onoff);
return (onoff != 0);
}
set {
dbenv.log_set_config(
DbConstants.DB_LOG_NOSYNC, value ? 1 : 0);
}
}
///
/// If true, transaction logs are maintained in-memory rather than on
/// disk. This means that transactions exhibit the ACI (atomicity,
/// consistency, and isolation) properties, but not D (durability).
///
public bool LogInMemory {
get {
int onoff = 0;
dbenv.log_get_config(DbConstants.DB_LOG_IN_MEMORY, ref onoff);
return (onoff != 0);
}
}
///
/// If true, all pages of a log file are zeroed when that log file is
/// created.
///
public bool LogZeroOnCreate {
get {
int onoff = 0;
dbenv.log_get_config(DbConstants.DB_LOG_ZERO, ref onoff);
return (onoff != 0);
}
}
///
/// The size of the underlying logging area of the Berkeley DB
/// environment, in bytes.
///
public uint LogRegionSize {
get {
uint ret = 0;
dbenv.get_lg_regionmax(ref ret);
return ret;
}
private set {
dbenv.set_lg_regionmax(value);
}
}
///
/// The maximum cache size
///
public CacheInfo MaxCacheSize {
get {
uint gb = 0;
uint b = 0;
dbenv.get_cache_max(ref gb, ref b);
return new CacheInfo(gb, b, 0);
}
private set {
dbenv.set_cache_max(value.Gigabytes, value.Bytes);
}
}
///
/// The maximum size of a single file in the log, in bytes. Because
/// LSN Offsets are unsigned four-byte
/// values, the size may not be larger than the maximum unsigned
/// four-byte value.
///
///
///
/// When the logging subsystem is configured for on-disk logging, the
/// default size of a log file is 10MB.
///
///
/// When the logging subsystem is configured for in-memory logging, the
/// default size of a log file is 256KB. In addition, the configured log
/// buffer size must be larger than the log file size. (The logging
/// subsystem divides memory configured for in-memory log records into
/// "files", as database environments configured for in-memory log
/// records may exchange log records with other members of a replication
/// group, and those members may be configured to store log records
/// on-disk.) When choosing log buffer and file sizes for in-memory
/// logs, applications should ensure the in-memory log buffer size is
/// large enough that no transaction ever spans the entire buffer,
/// and avoid a state where the in-memory buffer is full and no space
/// can be freed because a transaction that started in the first log
/// "file" is still active.
///
///
/// See Log File Limits in the Programmer's Reference Guide for more
/// information.
///
///
/// If no size is specified by the application, the size last specified
/// for the database region is used, or if no database region
/// previously existed, the default is used.
///
///
public uint MaxLogFileSize {
get {
uint ret = 0;
dbenv.get_lg_max(ref ret);
return ret;
}
set {
dbenv.set_lg_max(value);
}
}
///
/// The maximum number of locking entities supported by the Berkeley DB
/// environment.
///
public uint MaxLockers {
get {
uint ret = 0;
dbenv.get_lk_max_lockers(ref ret);
return ret;
}
private set {
dbenv.set_lk_max_lockers(value);
}
}
///
/// The maximum number of locks supported by the Berkeley DB
/// environment.
///
public uint MaxLocks {
get {
uint ret = 0;
dbenv.get_lk_max_locks(ref ret);
return ret;
}
private set {
dbenv.set_lk_max_locks(value);
}
}
///
/// The total number of mutexes allocated
///
public uint MaxMutexes {
get {
uint ret = 0;
dbenv.mutex_get_max(ref ret);
return ret;
}
private set {
dbenv.mutex_set_max(value);
}
}
///
/// The maximum number of locked objects
///
public uint MaxObjects {
get {
uint ret = 0;
dbenv.get_lk_max_objects(ref ret);
return ret;
}
private set {
dbenv.set_lk_max_objects(value);
}
}
///
/// The number of file descriptors the library opens concurrently
/// when flushing dirty pages from the cache.
///
public int MaxOpenFiles {
get {
int ret = 0;
dbenv.get_mp_max_openfd(ref ret);
return ret;
}
set {
dbenv.set_mp_max_openfd(value);
}
}
///
/// The number of sequential write operations scheduled by the library
/// when flushing dirty pages from the cache.
///
public int MaxSequentialWrites {
get {
int ret = 0;
uint tmp = 0;
dbenv.get_mp_max_write(ref ret, ref tmp);
return ret;
}
}
///
/// The number of active transactions supported by the environment. This
/// value bounds the size of the memory allocated for transactions.
/// Child transactions are counted as active until they either commit or
/// abort.
///
///
///
/// Transactions that update multiversion databases are not freed until
/// the last page version that the transaction created is flushed from
/// cache. This means that applications using multi-version concurrency
/// control may need in the extreme case a transaction for each page in cache.
///
///
/// When all of the memory available in the database environment for
/// transactions is in use, calls to
/// fail (until some active transactions complete). If MaxTransactions
/// is never set, the database environment is configured to support at
/// least 100 active transactions.
///
///
public uint MaxTransactions {
get {
uint ret = 0;
dbenv.get_tx_max(ref ret);
return ret;
}
set {
dbenv.set_tx_max(value);
}
}
///
/// The path of directory to store the persistent metadata.
///
///
///
/// By default, metadata is stored in the environment home directory.
/// See Berkeley DB File Naming in the Programmer's Reference Guide for
/// more information.
///
///
/// When used in a replicated application, the metadata directory must
/// be the same location for all sites within a replication group.
///
///
public string MetadataDir {
get {
string mddir;
dbenv.get_metadata_dir(out mddir);
return mddir;
}
}
///
/// The maximum file size, in bytes, for a file to be mapped into the
/// process address space. If no value is specified, it defaults to
/// 10MB.
///
///
/// Files that are opened read-only in the cache (and that satisfy a few
/// other criteria) are, by default, mapped into the process address
/// space instead of being copied into the local cache. This can result
/// in better-than-usual performance because available virtual memory is
/// normally much larger than the local cache, and page faults are
/// faster than page copying on many systems. However, it can cause
/// resource starvation in the presence of limited virtual memory, and
/// it can result in immense process sizes in the presence of large
/// databases.
///
public uint MMapSize {
get {
uint ret = 0;
dbenv.get_mp_mmapsize(ref ret);
return ret;
}
set {
dbenv.set_mp_mmapsize(value);
}
}
///
/// The message file.
///
public string Msgfile {
set {
int ret = 0;
ret = dbenv.set_msgfile(value);
if(ret != 0) {
throw new Exception("Set message file fails.");
}
}
}
///
/// The mutex alignment, in bytes.
///
public uint MutexAlignment {
get {
uint ret = 0;
dbenv.mutex_get_align(ref ret);
return ret;
}
private set {
dbenv.mutex_set_align(value);
}
}
///
/// The number of additional mutexes allocated.
///
public uint MutexIncrement {
get {
uint ret = 0;
dbenv.mutex_get_increment(ref ret);
return ret;
}
private set {
dbenv.mutex_set_increment(value);
}
}
///
/// If true, turn off system buffering of Berkeley DB database files to
/// avoid double caching.
///
public bool NoBuffer {
get {
uint flags = 0;
dbenv.get_flags(ref flags);
return (flags & DbConstants.DB_DIRECT_DB) != 0;
}
set {
dbenv.set_flags(DbConstants.DB_DIRECT_DB, value ? 1 : 0);
}
}
///
/// If true, Berkeley DB grants all requested mutual exclusion
/// mutexes and database locks without regard for their actual
/// availability. This functionality should never be used for purposes
/// other than debugging.
///
public bool NoLocking {
get {
uint flags = 0;
dbenv.get_flags(ref flags);
return (flags & DbConstants.DB_NOLOCKING) != 0;
}
set {
dbenv.set_flags(DbConstants.DB_NOLOCKING, value ? 1 : 0);
}
}
///
/// If true, Berkeley DB copies read-only database files into the
/// local cache instead of potentially mapping them into process memory.
///
///
public bool NoMMap {
get {
uint flags = 0;
dbenv.get_flags(ref flags);
return (flags & DbConstants.DB_NOMMAP) != 0;
}
set {
dbenv.set_flags(DbConstants.DB_NOMMAP, value ? 1 : 0);
}
}
///
/// If true, Berkeley DB ignores any panic state in the database
/// environment. (Database environments in a panic state normally refuse
/// all attempts to call Berkeley DB functions, throwing
/// .) This functionality should never
/// be used for purposes other than debugging.
///
public bool NoPanic {
get {
uint flags = 0;
dbenv.get_flags(ref flags);
return (flags & DbConstants.DB_NOPANIC) != 0;
}
set {
dbenv.set_flags(DbConstants.DB_NOPANIC, value ? 1 : 0);
}
}
///
/// The number of times that test-and-set mutexes should spin without
/// blocking. The value defaults to 1 on uniprocessor systems and to 50
/// times the number of processors on multiprocessor systems.
///
public uint NumTestAndSetSpins {
get {
uint ret = 0;
dbenv.mutex_get_tas_spins(ref ret);
return ret;
}
set {
dbenv.mutex_set_tas_spins(value);
}
}
///
/// If true, overwrite files stored in encrypted formats before deleting
/// them.
///
///
/// Berkeley DB overwrites files using alternating 0xff, 0x00 and 0xff
/// byte patterns. For an effective overwrite, the underlying
/// file must be stored on a fixed-block filesystem. Systems with
/// journaling or logging filesystems require operating system
/// support and probably modification of the Berkeley DB sources.
///
public bool Overwrite {
get {
uint flags = 0;
dbenv.get_flags(ref flags);
return (flags & DbConstants.DB_OVERWRITE) != 0;
}
set {
dbenv.set_flags(DbConstants.DB_OVERWRITE, value ? 1 : 0);
}
}
///
/// The function used to create a replication view that determines
/// whether a database file is replicated to the local site.
///
///
/// If it is null, the replication view is a full view and all database
/// files are replicated to the local site. Otherwise it is a partial
/// view and only some database files are replicated to the local site.
///
public ReplicationViewDelegate ReplicationView {
get { return replicationViewHandler; }
private set { replicationViewHandler = value;}
}
///
/// If true, allocate region memory from the heap instead of from memory
/// backed by the filesystem or system shared memory.
///
public bool Private {
get {
uint flags = 0;
dbenv.get_open_flags(ref flags);
return (flags & DbConstants.DB_PRIVATE) != 0;
}
}
///
/// The gigabytes component of the byte-count limit on the amount of
/// memory to be used by shared structures in the main environment
/// region. These are the structures other than mutexes and the page
/// cache (memory pool).
///
/// The maximum number of gigabytes used by the main region.
///
public uint RegionMemoryLimitGBytes {
get {
uint gb = 0;
uint b = 0;
dbenv.get_memory_max(ref gb, ref b);
return gb;
}
}
///
/// The bytes component of the byte-count limit on the amount of
/// memory to be used by shared structures in the main environment
/// region. These are the structures other than mutexes and the page
/// cache (memory pool).
///
/// The maximum number of bytes used by the main region.
///
public uint RegionMemoryLimitBytes {
get {
uint gb = 0;
uint b = 0;
dbenv.get_memory_max(ref gb, ref b);
return b;
}
}
///
/// The amount of memory to be used by shared structures in the main
/// environment region. These are structures other than mutexes and
/// the page cache (memory pool).
///
///
/// The number of gigabytes to allocate for the main memory region.
/// The gigabytes allocated are added to the bytes input.
///
///
/// The number of gigabytes to allocate for the main memory region.
/// The bytes allocated are added to the gigabytes input.
///
public void RegionSetMemoryLimit(uint GBytes, uint Bytes) {
dbenv.set_memory_max(GBytes, Bytes);
}
///
/// If true, Berkeley DB checks if recovery is needed to
/// be performed before opening the database environment.
///
public bool Register {
get {
uint flags = 0;
dbenv.get_open_flags(ref flags);
return (flags & DbConstants.DB_REGISTER) != 0;
}
}
///
/// The amount of time the replication manager's transport function
/// waits to collect enough acknowledgments from replication group
/// clients, before giving up and returning a failure indication. The
/// default wait time is 1 second.
///
public uint RepAckTimeout {
get { return getRepTimeout(DbConstants.DB_REP_ACK_TIMEOUT); }
set {
dbenv.rep_set_timeout(
DbConstants.DB_REP_ACK_TIMEOUT, value);
}
}
///
/// If true, the replication master sends groups of records to the
/// clients in a single network transfer
///
public bool RepBulkTransfer {
get { return getRepConfig(DbConstants.DB_REP_CONF_BULK); }
set {
dbenv.rep_set_config(
DbConstants.DB_REP_CONF_BULK, value ? 1 : 0);
}
}
///
/// The amount of time a master site delays between completing a
/// checkpoint and writing a checkpoint record into the log.
///
///
/// This delay allows clients to complete their own checkpoints before
/// the master requires completion of them. The default is 30 seconds.
/// Delay should be set to 0 if all databases in the environment and the
/// environment's transaction log are configured to reside in-memory.
///
public uint RepCheckpointDelay {
get { return getRepTimeout(DbConstants.DB_REP_CHECKPOINT_DELAY); }
set {
dbenv.rep_set_timeout(
DbConstants.DB_REP_CHECKPOINT_DELAY, value);
}
}
///
/// The value, relative to , of the
/// fastest clock in the group of sites.
///
public uint RepClockskewFast {
get {
uint fast = 0;
uint slow = 0;
dbenv.rep_get_clockskew(ref fast, ref slow);
return fast;
}
}
///
/// The value of the slowest clock in the group of sites.
///
public uint RepClockskewSlow {
get {
uint fast = 0;
uint slow = 0;
dbenv.rep_get_clockskew(ref fast, ref slow);
return slow;
}
}
///
/// Set the clock skew ratio among replication group members based on
/// the fastest and slowest measurements among the group for use with
/// master leases.
///
///
///
/// Calling this method is optional, the default values for clock skew
/// assume no skew. The user must also configure leases via
/// . Additionally, the user must also
/// set the master lease timeout via and
/// the number of sites in the replication group via
/// . These settings may be configured in any
/// order. For a description of the clock skew values, see Clock skew
/// in the Berkeley DB Programmer's Reference Guide. For a description
/// of master leases, see Master leases in the Berkeley DB Programmer's
/// Reference Guide.
///
///
/// These arguments can be used to express either raw measurements of a
/// clock timing experiment or a percentage across machines. For
/// instance a group of sites have a 2% variance, then
/// should be set to 102, and
/// should be set to 100. Or, for a 0.03%
/// difference, you can use 10003 and 10000 respectively.
///
///
///
/// The value, relative to , of the fastest clock
/// in the group of sites.
///
///
/// The value of the slowest clock in the group of sites.
///
public void RepSetClockskew(uint fast, uint slow) {
dbenv.rep_set_clockskew(fast, slow);
}
///
/// The amount of time the replication manager waits before trying
/// to re-establish a connection to another site after a communication
/// failure. The default wait time is 30 seconds.
///
public uint RepConnectionRetry {
get { return getRepTimeout(DbConstants.DB_REP_CONNECTION_RETRY); }
set {
dbenv.rep_set_timeout(
DbConstants.DB_REP_CONNECTION_RETRY, value);
}
}
///
/// If true, the client should delay synchronizing to a newly declared
/// master (defaults to false). Clients configured in this way remain
/// unsynchronized until the application calls .
///
public bool RepDelayClientSync {
get { return getRepConfig(DbConstants.DB_REP_CONF_DELAYCLIENT); }
set {
dbenv.rep_set_config(
DbConstants.DB_REP_CONF_DELAYCLIENT, value ? 1 : 0);
}
}
///
/// Configure the amount of time the replication manager waits
/// before retrying a failed election. The default wait time is 10
/// seconds.
///
public uint RepElectionRetry {
get { return getRepTimeout(DbConstants.DB_REP_ELECTION_RETRY); }
set {
dbenv.rep_set_timeout(DbConstants.DB_REP_ELECTION_RETRY, value);
}
}
///
/// The timeout period for an election. The default timeout is 2
/// seconds.
///
public uint RepElectionTimeout {
get { return getRepTimeout(DbConstants.DB_REP_ELECTION_TIMEOUT); }
set {
dbenv.rep_set_timeout(
DbConstants.DB_REP_ELECTION_TIMEOUT, value);
}
}
///
/// An optional configuration timeout period to wait for full election
/// participation the first time the replication group finds a master.
/// By default this option is turned off and normal election timeouts
/// are used. (See the Elections section in the Berkeley DB Reference
/// Guide for more information.)
///
public uint RepFullElectionTimeout {
get {
return getRepTimeout(
DbConstants.DB_REP_FULL_ELECTION_TIMEOUT);
}
set {
dbenv.rep_set_timeout(
DbConstants.DB_REP_FULL_ELECTION_TIMEOUT, value);
}
}
///
/// The amount of time the replication manager, running at a client
/// site, waits for some message activity on the connection from the
/// master (heartbeats or other messages) before concluding that the
/// connection has been lost. When 0 (the default), no monitoring is
/// performed.
///
public uint RepHeartbeatMonitor {
get { return getRepTimeout(DbConstants.DB_REP_HEARTBEAT_MONITOR); }
set {
dbenv.rep_set_timeout(
DbConstants.DB_REP_HEARTBEAT_MONITOR, value);
}
}
///
/// The frequency at which the replication manager, running at a master
/// site, broadcasts a heartbeat message in an otherwise idle system.
/// When 0 (the default), no heartbeat messages are sent.
///
public uint RepHeartbeatSend {
get { return getRepTimeout(DbConstants.DB_REP_HEARTBEAT_SEND); }
set {
dbenv.rep_set_timeout(DbConstants.DB_REP_HEARTBEAT_SEND, value);
}
}
///
/// If true, replication only stores the internal information in-memory
/// and cannot keep persistent state across a site crash or reboot. By
/// default, it is false and replication creates files in the
/// environment home directory to preserve the internal information.
///
public bool RepInMemory {
get { return getRepConfig(DbConstants.DB_REP_CONF_INMEM); }
}
///
/// The amount of time a client grants its master lease to a master.
/// When using master leases all sites in a replication group must use
/// the same lease timeout value. There is no default value. If leases
/// are desired, this method must be called prior to calling
/// or .
///
public uint RepLeaseTimeout {
get { return getRepTimeout(DbConstants.DB_REP_LEASE_TIMEOUT); }
set {
dbenv.rep_set_timeout(DbConstants.DB_REP_LEASE_TIMEOUT, value);
}
}
///
/// Set the message dispatch function. It is responsible for receiving
/// messages sent from remote sites using either
/// or .
/// If the message received by this function was sent using
/// , then no response is required.
/// If the message was sent using ,
/// then this function must send a response using
/// .
///
///
/// It should be called before the Replication Manager has been started.
///
public MessageDispatchDelegate RepMessageDispatch {
get { return messageDispatchHandler; }
set {
if (value == null)
dbenv.repmgr_msg_dispatch(null, 0);
else if (messageDispatchHandler == null) {
if (doMessageDispatchRef == null)
doMessageDispatchRef = new BDB_MessageDispatchDelegate(
doMessageDispatch);
dbenv.repmgr_msg_dispatch(doMessageDispatchRef, 0);
}
messageDispatchHandler = value;
}
}
///
/// Specify how master and client sites handle acknowledgment of
/// replication messages which are necessary for "permanent" records.
/// The current implementation requires all sites in a replication group
/// configure the same acknowledgement policy.
///
///
public AckPolicy RepMgrAckPolicy {
get {
int policy = 0;
dbenv.repmgr_get_ack_policy(ref policy);
return AckPolicy.fromInt(policy);
}
set { dbenv.repmgr_set_ack_policy(value.Policy); }
}
///
/// The gigabytes component of the maximum amount of dynamic memory
/// used by the Replication Manager incoming queue.
///
public uint RepmgrIncomingQueueMaxGBytes {
get {
uint gb = 0;
uint b = 0;
dbenv.repmgr_get_incoming_queue_max(ref gb, ref b);
return gb;
}
}
///
/// The bytes component of the maximum amount of dynamic memory
/// used by the Replication Manager incoming queue.
///
public uint RepmgrIncomingQueueMaxBytes {
get {
uint gb = 0;
uint b = 0;
dbenv.repmgr_get_incoming_queue_max(ref gb, ref b);
return b;
}
}
///
/// Create DbChannel with given eid.
///
///
/// Environment id. If the eid is ,
/// create channel sending to master site only.
///
public DbChannel RepMgrChannel(int eid) {
DB_CHANNEL dbChannel;
dbChannel = dbenv.repmgr_channel(eid, 0);
return new DbChannel(dbChannel);
}
///
/// If true, Replication Manager automatically runs elections to
/// choose a new master when the old master disconnects (defaults to true).
///
public bool RepMgrRunElections {
get { return getRepConfig(DbConstants.DB_REPMGR_CONF_ELECTIONS); }
set {
dbenv.rep_set_config(
DbConstants.DB_REPMGR_CONF_ELECTIONS, value ? 1 : 0);
}
}
///
/// The local site of the replication manager. Returns null if the
/// local site has not been configured.
///
public DbSite RepMgrLocalSite {
get {
DB_SITE site;
try {
site = dbenv.repmgr_local_site();
} catch (NotFoundException) {
// Local site wasn't set.
return null;
}
return new DbSite(site);
}
}
///
/// The status of the sites currently known by the replication manager.
///
public RepMgrSite[] RepMgrRemoteSites {
get { return dbenv.repmgr_site_list(); }
}
///
/// If true, the replication master automatically re-initializes
/// outdated clients (defaults to true).
///
public bool RepAutoInit {
get { return getRepConfig(DbConstants.DB_REP_CONF_AUTOINIT); }
set {
dbenv.rep_set_config(
DbConstants.DB_REP_CONF_AUTOINIT, value ? 1 : 0);
}
}
///
/// If true, errors are returned immediately for Berkeley DB method calls
/// that would normally block while clients are in recovery
/// (defaults to false).
///
public bool RepNoBlocking {
get { return getRepConfig(DbConstants.DB_REP_CONF_NOWAIT); }
set {
dbenv.rep_set_config(
DbConstants.DB_REP_CONF_NOWAIT, value ? 1 : 0);
}
}
///
/// The total number of sites in the replication group.
///
///
///
/// This setting is typically used by applications which use the
/// Berkeley DB library "replication manager" support. (However, see
/// also , the description of the nsites
/// parameter.)
///
///
public uint RepNSites {
get {
uint ret = 0;
dbenv.rep_get_nsites(ref ret);
return ret;
}
set { dbenv.rep_set_nsites(value); }
}
///
/// The database environment's priority in replication group elections.
/// A special value of 0 indicates that this environment cannot be a
/// replication group master. If not configured, then a default value
/// of 100 is used.
///
public uint RepPriority {
get {
uint ret = 0;
dbenv.rep_get_priority(ref ret);
return ret;
}
set { dbenv.rep_set_priority(value); }
}
///
/// The minimum number of microseconds a client waits before requesting
/// retransmission.
///
public uint RepRetransmissionRequestMin {
get {
uint min = 0;
uint max = 0;
dbenv.rep_get_request(ref min, ref max);
return min;
}
}
///
/// The maximum number of microseconds a client waits before requesting
/// retransmission.
///
public uint RepRetransmissionRequestMax {
get {
uint min = 0;
uint max = 0;
dbenv.rep_get_request(ref min, ref max);
return max;
}
}
///
/// Set a threshold for the minimum and maximum time that a client waits
/// before requesting retransmission of a missing message.
///
///
///
/// If the client detects a gap in the sequence of incoming log records
/// or database pages, Berkeley DB will wait for at least
/// microseconds before requesting retransmission
/// of the missing record. Berkeley DB will double that amount before
/// requesting the same missing record again, and so on, up to a
/// maximum threshold of microseconds.
///
///
/// These values are only thresholds. Since Berkeley DB has no thread
/// available as a timer in the library, the threshold is only checked
/// when a thread enters the Berkeley DB library to process an incoming
/// replication message. Berkeley DB checks whether the amount
/// of time since a request was made is beyond the threshold value or
/// not.
///
///
/// By default the minimum is 40000 and the maximum is 1280000 microseconds
/// (1.28 seconds). These defaults are fairly arbitrary and the application
/// likely needs to adjust these. The values should be based on expected
/// load and performance characteristics of the master and client host
/// platforms and transport infrastructure as well as round-trip message
/// time.
///
///
/// The minimum number of microseconds a client waits before requesting
/// retransmission.
///
///
/// The maximum number of microseconds a client waits before requesting
/// retransmission.
///
public void RepSetRetransmissionRequest(uint min, uint max) {
dbenv.rep_set_request(min, max);
}
///
/// Replication Manager observes the strict "majority" rule in managing
/// elections, even in a group with only 2 sites. The client
/// in a 2-site group is unable to take over as master if the
/// original master fails or becomes disconnected. (See the Elections
/// section in the Berkeley DB Reference Guide for more information.)
/// Both sites in the replication group should have the same value for
/// this parameter.
///
public bool RepStrict2Site {
get {
return getRepConfig(DbConstants.DB_REPMGR_CONF_2SITE_STRICT);
}
set {
dbenv.rep_set_config(
DbConstants.DB_REPMGR_CONF_2SITE_STRICT, value ? 1 : 0);
}
}
///
/// This flag is used to specify the preferred master site in a
/// replication group operating in preferred master mode. A preferred
/// master replication group must contain only two sites, with one site
/// specified as the preferred master site and the other site specified
/// as the client site. The preferred master site operates as the
/// master site whenever possible.
///
public bool RepPrefmasMaster {
get { return getRepConfig(DbConstants.DB_REPMGR_CONF_PREFMAS_MASTER); }
set {
dbenv.rep_set_config(
DbConstants.DB_REPMGR_CONF_PREFMAS_MASTER, value ? 1 : 0);
}
}
///
/// This flag is used to specify the client site in a replication group
/// operating in preferred master mode. A preferred master replication
/// group must contain only two sites, with one site specified as the
/// preferred master site and the other site specified as the client
/// site. The client site in a preferred master replication group takes
/// over temporarily as master when the preferred master site is
/// unavailable.
///
public bool RepPrefmasClient {
get { return getRepConfig(DbConstants.DB_REPMGR_CONF_PREFMAS_CLIENT); }
set {
dbenv.rep_set_config(
DbConstants.DB_REPMGR_CONF_PREFMAS_CLIENT, value ? 1 : 0);
}
}
///
/// The gigabytes component of the byte-count limit on the amount of
/// data that is transmitted from a site in response to a single
/// message processed by .
///
public uint RepTransmitLimitGBytes {
get {
uint gb = 0;
uint b = 0;
dbenv.rep_get_limit(ref gb, ref b);
return gb;
}
}
///
/// The bytes component of the byte-count limit on the amount of data
/// that is transmitted from a site in response to a single
/// message processed by .
///
public uint RepTransmitLimitBytes {
get {
uint gb = 0;
uint b = 0;
dbenv.rep_get_limit(ref gb, ref b);
return b;
}
}
///
/// Set a byte-count limit on the amount of data that is
/// transmitted from a site in response to a single message processed by
/// . The limit is not a hard limit, and
/// the record that exceeds the limit is the last record to be sent.
///
///
///
/// Record transmission throttling is turned on by default with a limit
/// of 10MB.
///
///
/// If both and are
/// zero, then the transmission limit is turned off.
///
///
///
/// The number of gigabytes which, when added to
/// , specifies the maximum number of bytes that
/// are sent in a single call to .
///
///
/// The number of bytes which, when added to
/// , specifies the maximum number of bytes
/// that are sent in a single call to
/// .
///
public void RepSetTransmitLimit(uint GBytes, uint Bytes) {
dbenv.rep_set_limit(GBytes, Bytes);
}
///
/// Set a byte-count limit on the maximum amount of dynamic memory
/// used by the Replication Manager incoming queue.
///
///
///
/// By default, the Replication Manager incoming queue size has a
/// limit of 100MB.
///
///
/// If both and are
/// zero, then the Replication Manager incoming queue size is limited
/// by available heap memory.
///
///
///
/// The number of gigabytes which, when added to
/// , specifies the maximum amount of dynamic
/// memory used by the Replication Manager incoming queue.
///
///
/// The number of bytes which, when added to
/// , specifies the maximum amount of dynamic
/// memory used by the Replication Manager incoming queue.
///
public void RepmgrSetIncomingQueueMax(uint GBytes, uint Bytes) {
dbenv.repmgr_set_incoming_queue_max(GBytes, Bytes);
}
///
/// The delegate used to transmit data using the replication
/// application's communication infrastructure.
///
public ReplicationTransportDelegate RepTransport {
get { return transportHandler; }
}
///
/// Initialize the communication infrastructure for a database
/// environment participating in a replicated application.
///
///
/// RepSetTransport is not called by most replication applications. It
/// should only be called by applications implementing their own network
/// transport layer, explicitly holding replication group elections and
/// handling replication messages outside of the replication manager
/// framework.
///
///
/// The local environment's ID. It must be a non-negative integer and
/// uniquely identify this Berkeley DB database environment (see
/// Replication environment IDs in the Programmer's Reference Guide for
/// more information).
///
///
/// The delegate used to transmit data using the replication
/// application's communication infrastructure.
///
public void RepSetTransport(int envid,
ReplicationTransportDelegate transport) {
if (transport == null)
dbenv.rep_set_transport(envid, null);
else if (transportHandler == null) {
if (doRepTransportRef == null)
doRepTransportRef = new BDB_RepTransportDelegate(doRepTransport);
dbenv.rep_set_transport(envid, doRepTransportRef);
}
transportHandler = transport;
}
///
/// If true, master leases are used for this site (defaults to
/// false).
///
///
/// Configuring this option may result in a
/// when attempting to read entries
/// from a database after the site's master lease has expired.
///
public bool RepUseMasterLeases {
get { return getRepConfig(DbConstants.DB_REP_CONF_LEASE); }
set {
dbenv.rep_set_config(
DbConstants.DB_REP_CONF_LEASE, value ? 1 : 0);
}
}
///
/// If true, catastrophic recovery was run on this environment before
/// opening it for normal use.
///
public bool RunFatalRecovery {
get {
uint flags = 0;
dbenv.get_open_flags(ref flags);
return (flags & DbConstants.DB_RECOVER_FATAL) != 0;
}
}
///
/// If true, normal recovery was run on this environment before opening
/// it for normal use.
///
public bool RunRecovery {
get {
uint flags = 0;
dbenv.get_open_flags(ref flags);
return (flags & DbConstants.DB_RECOVER) != 0;
}
}
///
/// The number of microseconds the thread of control pauses before
/// scheduling further write operations.
///
public uint SequentialWritePause {
get {
int tmp = 0;
uint ret = 0;
dbenv.get_mp_max_write(ref tmp, ref ret);
return ret;
}
}
///
/// A delegate that returns a unique identifier pair for the current
/// thread of control.
///
///
/// This delegate supports . For more
/// information, see Architecting Data Store and Concurrent Data Store
/// applications, and Architecting Transactional Data Store
/// applications, both in the Berkeley DB Programmer's Reference Guide.
///
public SetThreadIDDelegate SetThreadID {
get { return threadIDHandler; }
set {
if (value == null)
dbenv.set_thread_id(null);
else if (threadIDHandler == null) {
if (doThreadIDRef == null)
doThreadIDRef = new BDB_ThreadIDDelegate(doThreadID);
dbenv.set_thread_id(doThreadIDRef);
}
threadIDHandler = value;
}
}
///
/// A delegate that formats a process ID and thread ID identifier pair.
///
public SetThreadNameDelegate SetThreadName {
get { return threadNameHandler; }
set {
if (value == null)
dbenv.set_thread_id_string(null);
else if (threadNameHandler == null) {
if (doThreadNameRef == null)
doThreadNameRef =
new BDB_ThreadNameDelegate(doThreadName);
dbenv.set_thread_id_string(doThreadNameRef);
}
threadNameHandler = value;
}
}
///
/// If true, allocate region memory from system shared memory instead of
/// from heap memory or memory backed by the filesystem.
///
public bool SystemMemory {
get {
uint flags = 0;
dbenv.get_open_flags(ref flags);
return (flags & DbConstants.DB_SYSTEM_MEM) != 0;
}
}
///
/// The path of a directory to be used as the location for temporary
/// files.
///
///
///
/// The files created to back in-memory access method databases are
/// created relative to this path. These temporary files can be quite
/// large, depending on the size of the database.
///
///
/// If no directories are specified, the following alternatives are
/// checked in the specified order. The first existing directory path is
/// used for all temporary files.
///
///
/// - The value of the environment variable TMPDIR.
/// - The value of the environment variable TEMP.
/// - The value of the environment variable TMP.
/// - The value of the environment variable TempFolder.
/// - The value returned by the GetTempPath interface.
/// - The directory /var/tmp.
/// - The directory /usr/tmp.
/// - The directory /temp.
/// - The directory /tmp.
/// - The directory C:/temp.
/// - The directory C:/tmp.
///
///
/// Environment variables are only checked if
/// is true.
///
///
public string TempDir {
get {
string ret;
dbenv.get_tmp_dir(out ret);
return ret;
}
set { dbenv.set_tmp_dir(value); }
}
///
/// An approximate number of threads in the database environment.
///
public uint ThreadCount {
get {
uint ret = 0;
dbenv.get_thread_count(ref ret);
return ret;
}
private set { dbenv.set_thread_count(value); }
}
///
/// A delegate that returns if a thread of control (either a true thread
/// or a process) is still running.
///
public ThreadIsAliveDelegate ThreadIsAlive {
get { return isAliveHandler; }
set {
if (value == null)
dbenv.set_isalive(null);
else if (isAliveHandler == null) {
if (doIsAliveRef == null)
doIsAliveRef = new BDB_IsAliveDelegate(doIsAlive);
dbenv.set_isalive(doIsAliveRef);
}
isAliveHandler = value;
}
}
///
/// If true, database calls timing out based on lock or transaction
/// timeout values throw
/// instead of .
///
///
/// If true, allows applications to distinguish between deadlocked operations
/// and operations that have exceeded their time limits.
///
public bool TimeNotGranted {
get {
uint flags = 0;
dbenv.get_flags(ref flags);
return (flags & DbConstants.DB_TIME_NOTGRANTED) != 0;
}
set {
dbenv.set_flags(DbConstants.DB_TIME_NOTGRANTED, value ? 1 : 0);
}
}
///
/// If true, Berkeley DB does not write or synchronously flush the log
/// on transaction commit.
///
///
/// This means that transactions exhibit the ACI (atomicity,
/// consistency, and isolation) properties, but not D (durability);
/// database integrity is maintained, but if the application or
/// 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 many log updates can fit
/// into the log buffer, how often the operating system flushes dirty
/// buffers to disk, and how often the log is checkpointed.
///
public bool TxnNoSync {
get {
uint flags = 0;
dbenv.get_flags(ref flags);
return (flags & DbConstants.DB_TXN_NOSYNC) != 0;
}
set { dbenv.set_flags(DbConstants.DB_TXN_NOSYNC, value ? 1 : 0); }
}
///
/// If true and a lock is unavailable for any Berkeley DB operation
/// performed in the context of a transaction, cause the operation to
/// throw (or
/// if configured with
/// ).
///
public bool TxnNoWait {
get {
uint flags = 0;
dbenv.get_flags(ref flags);
return (flags & DbConstants.DB_TXN_NOWAIT) != 0;
}
set { dbenv.set_flags(DbConstants.DB_TXN_NOWAIT, value ? 1 : 0); }
}
///
/// If true, all transactions in the environment are started as if
/// was passed to
/// , and all non-transactional cursors
/// are opened as if
/// was passed to .
///
public bool TxnSnapshot {
get {
uint flags = 0;
dbenv.get_flags(ref flags);
return (flags & DbConstants.DB_TXN_SNAPSHOT) != 0;
}
set { dbenv.set_flags(DbConstants.DB_TXN_SNAPSHOT, value ? 1 : 0); }
}
///
/// A value, in microseconds, representing transaction timeouts.
///
///
///
/// All timeouts are checked whenever a thread of control blocks on a
/// lock or when deadlock detection is performed. The accuracy of the
/// timeout depends on how often deadlock detection is performed.
///
///
/// Timeout values specified for the database environment may be
/// overridden on a per-transaction basis, see
/// .
///
///
public uint TxnTimeout {
get {
uint timeout = 0;
dbenv.get_timeout(ref timeout, DbConstants.DB_SET_TXN_TIMEOUT);
return timeout;
}
set {
dbenv.set_timeout(value, DbConstants.DB_SET_TXN_TIMEOUT);
}
}
///
/// The recovery timestamp
///
public DateTime TxnTimestamp {
get {
long secs = 0;
dbenv.get_tx_timestamp(ref secs);
DateTime epoch = new DateTime(1970, 1, 1);
DateTime ret = epoch.AddSeconds(secs);
return ret;
}
private set {
if (value != null) {
TimeSpan ts = value - new DateTime(1970, 1, 1);
long secs = (long)ts.TotalSeconds;
dbenv.set_tx_timestamp(ref secs);
}
}
}
///
/// If true, Berkeley DB writes, but does not synchronously flush,
/// the log on transaction commit.
///
///
/// This means that transactions exhibit the ACI (atomicity,
/// consistency, and isolation) properties, but not D (durability); database
/// integrity is maintained, but if the application or
/// system fails, it is possible that 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.
///
public bool TxnWriteNoSync {
get {
uint flags = 0;
dbenv.get_flags(ref flags);
return (flags & DbConstants.DB_TXN_WRITE_NOSYNC) != 0;
}
set {
dbenv.set_flags(DbConstants.DB_TXN_WRITE_NOSYNC, value ? 1 : 0);
}
}
///
/// If true, all databases in the environment are opened as if
/// was set.
///
///
/// This flag is ignored for queue databases for which MVCC is not
/// supported.
///
public bool UseMVCC {
get {
uint flags = 0;
dbenv.get_flags(ref flags);
return (flags & DbConstants.DB_MULTIVERSION) != 0;
}
set { dbenv.set_flags(DbConstants.DB_MULTIVERSION, value ? 1 : 0); }
}
///
/// If true, locking for the Berkeley DB Concurrent Data Store product
/// was initialized.
///
public bool UsingCDB {
get {
uint flags = 0;
dbenv.get_open_flags(ref flags);
return (flags & DbConstants.DB_INIT_CDB) != 0;
}
}
///
/// If true, the locking subsystem was initialized.
///
public bool UsingLocking {
get {
uint flags = 0;
dbenv.get_open_flags(ref flags);
return (flags & DbConstants.DB_INIT_LOCK) != 0;
}
}
///
/// If true, the logging subsystem was initialized.
///
public bool UsingLogging {
get {
uint flags = 0;
dbenv.get_open_flags(ref flags);
return (flags & DbConstants.DB_INIT_LOG) != 0;
}
}
///
/// If true, the shared memory buffer pool subsystem was initialized.
///
public bool UsingMPool {
get {
uint flags = 0;
dbenv.get_open_flags(ref flags);
return (flags & DbConstants.DB_INIT_MPOOL) != 0;
}
}
///
/// If true, the replication subsystem was initialized.
///
public bool UsingReplication {
get {
uint flags = 0;
dbenv.get_open_flags(ref flags);
return (flags & DbConstants.DB_INIT_REP) != 0;
}
}
///
/// If true, the transaction subsystem was initialized.
///
public bool UsingTxns {
get {
uint flags = 0;
dbenv.get_open_flags(ref flags);
return (flags & DbConstants.DB_INIT_TXN) != 0;
}
}
///
/// Specific additional informational and debugging messages in the
/// Berkeley DB message output.
///
public VerboseMessages Verbosity {
get {
uint flags = 0;
dbenv.get_verbose(ref flags);
return VerboseMessages.FromFlags(flags);
}
set {
if (value.MessagesOff != 0)
dbenv.set_verbose(value.MessagesOff, 0);
if (value.MessagesOn != 0)
dbenv.set_verbose(value.MessagesOn, 1);
}
}
///
/// If true, Berkeley DB yields the processor immediately after each
/// page or mutex acquisition.
///
///
/// This functionality should never be used for purposes other than
/// stress testing.
///
public bool YieldCPU {
get {
uint flags = 0;
dbenv.get_flags(ref flags);
return (flags & DbConstants.DB_YIELDCPU) != 0;
}
set {
dbenv.set_flags(DbConstants.DB_YIELDCPU, value ? 1 : 0);
}
}
#endregion Properties
///
/// Instantiate a new DatabaseEnvironment object and open the Berkeley
/// DB environment represented by .
///
///
/// The database environment's home directory. For more information on
/// home, and filename resolution in general, see Berkeley DB File
/// Naming in the Programmer's Reference Guide.
///
/// The environment's configuration
/// A new, open DatabaseEnvironment object
public static DatabaseEnvironment Open(
String home, DatabaseEnvironmentConfig cfg) {
DatabaseEnvironment env = new DatabaseEnvironment(0);
env.Config(cfg);
env.dbenv.open(home, cfg.openFlags, 0);
return env;
}
///
/// Destroy a Berkeley DB environment if it is not currently in use.
///
///
///
/// The environment regions, including any backing files, are removed.
/// Any log or database files and the environment directory are not
/// removed.
///
///
/// If there are processes that have called without
/// calling (that is, there are processes currently
/// using the environment), Remove fails without further action.
///
///
/// Calling Remove should not be necessary for most applications because
/// the Berkeley DB environment is cleaned up as part of normal database
/// recovery procedures. However, applications may want to call Remove
/// as part of application shut down to free up system resources. For
/// example, if was
/// specified to , it may be useful to call Remove in
/// order to release system shared memory segments that have been
/// allocated. Or, on architectures in which mutexes require allocation
/// of underlying system resources, it may be useful to call Remove in
/// order to release those resources. Alternatively, if recovery is not
/// required because no database state is maintained across failures,
/// and no system resources need to be released, it is possible to clean
/// up an environment by simply removing all the Berkeley DB files in
/// the database environment's directories.
///
///
/// In multithreaded applications, only a single thread may call Remove.
///
///
///
/// The database environment to be removed.
///
public static void Remove(string db_home) {
Remove(db_home, false, false, false);
}
///
/// Destroy a Berkeley DB environment if it is not currently in use.
///
///
///
/// Generally, is specified only when
/// applications were unable to shut down cleanly, and there is a risk
/// that an application may have died holding a Berkeley DB lock.)
///
///
/// The result of attempting to forcibly destroy the environment when it
/// is in use is unspecified. Processes using an environment often
/// maintain open file descriptors for shared regions within it. On UNIX
/// systems, the environment removal usually succeeds, and processes
/// that have already joined the region continue to run in that
/// region without change. However, processes attempting to join the
/// environment either fail or create new regions. On non-UNIX systems,
/// region removal is not possible because the unlink(2) system call fails
/// if any process has an open file descriptor for the file.
///
///
///
/// The database environment to be removed.
///
///
/// If true, the environment is removed, regardless of any processes
/// that may still using it, and no locks are acquired during this
/// process.
///
public static void Remove(string db_home, bool force) {
Remove(db_home, force, false, false);
}
private static void Remove(string db_home,
bool force, bool USE_ENVIRON, bool USE_ENVIRON_ROOT) {
DatabaseEnvironment env = new DatabaseEnvironment(0);
uint flags = 0;
flags |= force ? DbConstants.DB_FORCE : 0;
flags |= USE_ENVIRON ? DbConstants.DB_USE_ENVIRON : 0;
flags |= USE_ENVIRON_ROOT ? DbConstants.DB_USE_ENVIRON_ROOT : 0;
env.dbenv.remove(db_home, flags);
}
///
/// Perform a hot back up of the open environment.
///
/// All files used by the environment are backed up, so long as the
/// normal rules for file placement are followed. For information on how
/// files are normally placed relative to the environment directory, see
/// the "Berkeley DB File Naming" section in the Berkeley DB Reference
/// Guide.
///
///
/// By default, data directories and the log directory specified
/// relative to the home directory are recreated relative to the
/// target directory. If absolute path names are used, then use the
/// method.
///
///
/// This method provides the same functionality as the db_hotbackup
/// utility. However, this method does not perform the housekeeping
/// actions performed by that utility. In particular, you may want to
/// run a checkpoint before calling this method. To run a checkpoint,
/// use the method. For
/// more information on checkpoints, see the "Checkpoint" section in the
/// Berkeley DB Reference Guide.
///
///
/// To back up a single database file within the environment, use the
/// method.
///
///
/// In addition to the configuration options available using the
/// class, additional tuning modifications
/// can be made using the ,
/// ,
/// , and
/// properties.
/// Alternatively, you can write your own custom hot back up facility
/// using the interface.
///
///
/// Identifies the directory in which the back up
/// is placed. Any subdirectories required to contain the back up
/// must be placed relative to this directory. If an
/// is configured for the environment, then the
/// value specified to this parameter is passed on to the
/// method. If this parameter is null, then
/// the target must be specified to the
/// method.
///
/// This directory, and any required subdirectories, are created for
/// you if you specify or
/// for the
/// property.
///
///
/// The instance used to
/// configure the hot back up.
public void Backup(string target, BackupOptions opt) {
dbenv.backup(target, opt.flags);
}
///
/// Perform a hot back up of a single database file contained within the
/// environment.
///
/// To back up the entire environment, use the
/// method.
///
///
/// You can make some tuning modifications to the backup process using
/// the ,
/// ,
/// , and
/// properties.
/// Alternatively, you can write your own custom hot back up facility
/// using the interface.
///
///
/// Identifies the directory in which the back up
/// is placed.
/// The database file that you want to back up.
///
/// If true, then if the target file exists,
/// this method throws an exception.
public void BackupDatabase(
string target, string database, bool must_create) {
dbenv.dbbackup(
database, target, must_create ? DbConstants.DB_EXCL : 0);
}
///
/// Hold an election for the master of a replication group.
///
public void RepHoldElection() {
RepHoldElection(0, 0);
}
///
/// Hold an election for the master of a replication group.
///
///
/// The number of replication sites expected to participate in the
/// election. Once the current site has election information from that
/// many sites, it short-circuits the election and immediately casts
/// its vote for a new master. If an application is using master leases,
/// then the value must be 0 and must be used.
///
public void RepHoldElection(uint nsites) {
RepHoldElection(nsites, 0);
}
///
/// Hold an election for the master of a replication group.
///
///
///
/// RepHoldElection is not called by most replication applications. It
/// should only be called by applications implementing their own network
/// transport layer, explicitly holding replication group elections and
/// handling replication messages outside of the replication manager
/// framework.
///
///
/// If the election is successful, Berkeley DB notifies the
/// application of the results of the election by means of either the
/// or
/// events (see
/// for more information). The application is
/// responsible for adjusting its relationship to the other database
/// environments in the replication group, including directing all
/// database updates to the newly selected master, in accordance with
/// the results of the election.
///
///
/// The thread of control that calls RepHoldElection must not be the
/// thread of control that processes incoming messages; processing the
/// incoming messages is necessary to successfully complete an election.
///
///
/// Before calling this method, the delegate
/// must already have been configured to send replication messages.
///
///
///
/// The number of replication sites expected to participate in the
/// election. Once the current site has election information from that
/// many sites, it short-circuits the election and immediately casts
/// its vote for a new master. This parameter must be no less than
/// , or 0 if the election should use
/// . If an application is using master leases,
/// then the value must be 0 and must be used.
///
///
/// The minimum number of replication sites from which the current site
/// must have election information, before the current site casts a
/// vote for a new master. This parameter must be no greater than
/// , or 0 if the election should use the value
/// (( / 2) + 1).
///
public void RepHoldElection(uint nsites, uint nvotes) {
dbenv.rep_elect(nsites, nvotes, 0);
}
///
/// Configure a site in the replication manager.
///
/// The configuration of a site
public void RepMgrSiteConfig(DbSiteConfig siteConfig) {
DB_SITE dbSite;
dbSite = dbenv.repmgr_site(siteConfig.Host, siteConfig.Port);
if (siteConfig.helperIsSet)
dbSite.set_config(DbConstants.DB_BOOTSTRAP_HELPER,
Convert.ToUInt32(siteConfig.Helper));
if (siteConfig.groupCreatorIsSet)
dbSite.set_config(DbConstants.DB_GROUP_CREATOR,
Convert.ToUInt32(siteConfig.GroupCreator));
if (siteConfig.legacyIsSet)
dbSite.set_config(DbConstants.DB_LEGACY,
Convert.ToUInt32(siteConfig.Legacy));
if (siteConfig.localSiteIsSet)
dbSite.set_config(DbConstants.DB_LOCAL_SITE,
Convert.ToUInt32(siteConfig.LocalSite));
if (siteConfig.peerIsSet)
dbSite.set_config(DbConstants.DB_REPMGR_PEER,
Convert.ToUInt32(siteConfig.Peer));
dbSite.close();
}
///
/// Create DbSite with the given eid.
///
///
/// It is only possible to use this method after env open, because EID
/// values are not established before that time.
///
/// The environment id
public DbSite RepMgrSite(int eid) {
DB_SITE dbSite;
dbSite = dbenv.repmgr_site_by_eid(eid);
return new DbSite(dbSite);
}
///
/// Create DbSite with the given host and port.
///
/// The host address
/// The port
public DbSite RepMgrSite(string host, uint port) {
DB_SITE dbSite;
dbSite = dbenv.repmgr_site(host, port);
return new DbSite(dbSite);
}
///
/// Start the replication manager as a client site, and do not call for
/// an election.
///
///
///
/// There are two ways to build Berkeley DB replication applications:
/// the most common approach is to use the Berkeley DB library
/// "replication manager" support, where the Berkeley DB library manages
/// the replication group, including network transport, all replication
/// message processing and acknowledgment, and group elections.
/// Applications using the replication manager support generally make
/// the following calls:
///
///
/// -
/// Configure the local site in the replication group,
/// .
///
/// -
/// Call to configure the remote
/// site(s) in the replication group.
///
/// - Configure the message acknowledgment policy
/// () which provides the replication group's
/// transactional needs.
///
/// -
/// Configure the local site's election priority,
/// .
///
/// -
/// Call or
/// to start the replication
/// application.
///
///
///
/// For more information on building replication manager applications,
/// please see the Replication Getting Started Guide included in the
/// Berkeley DB documentation.
///
///
/// Applications with special needs (for example, applications using
/// network protocols not supported by the Berkeley DB replication
/// manager), must perform additional configuration and call other
/// Berkeley DB replication methods. For more information on building
/// advanced replication applications, please see the Base Replication
/// API section in the Berkeley DB Programmer's Reference Guide for more
/// information.
///
///
/// Starting the replication manager consists of opening the TCP/IP
/// listening socket to accept incoming connections, and starting all
/// necessary background threads. When multiple processes share a
/// database environment, only one process can open the listening
/// socket; (and
/// ) automatically open the socket in
/// the first process to call it, and skips this step in the later calls
/// from other processes.
///
///
///
/// Specify the number of threads of control created and dedicated to
/// processing replication messages. In addition to these message
/// processing threads, the replication manager creates and manages a
/// few of its own threads of control.
///
public void RepMgrStartClient(int nthreads) {
RepMgrStartClient(nthreads, false);
}
///
/// Start the replication manager as a client site, and optionally call
/// for an election.
///
///
/// Specify the number of threads of control created and dedicated to
/// processing replication messages. In addition to these message
/// processing threads, the replication manager creates and manages a
/// few of its own threads of control.
///
///
/// If true, start as a client, and call for an election if no master is
/// found.
///
public void RepMgrStartClient(int nthreads, bool holdElection) {
dbenv.repmgr_start(nthreads,
holdElection ?
DbConstants.DB_REP_ELECTION : DbConstants.DB_REP_CLIENT);
}
///
/// Start the replication manager as a master site, and do not call for
/// an election.
///
///
///
/// There are two ways to build Berkeley DB replication applications:
/// the most common approach is to use the Berkeley DB library
/// "replication manager" support, where the Berkeley DB library manages
/// the replication group, including network transport, all replication
/// message processing and acknowledgment, and group elections.
/// Applications using the replication manager support generally make
/// the following calls:
///
///
/// -
/// Configure the local site in the replication group,
/// .
///
/// -
/// Call to configure the remote
/// site(s) in the replication group.
///
/// - Configure the message acknowledgment policy
/// () which provides the replication group's
/// transactional needs.
///
/// -
/// Configure the local site's election priority,
/// .
///
/// -
/// Call or
/// to start the replication
/// application.
///
///
///
/// For more information on building replication manager applications,
/// please see the Replication Getting Started Guide included in the
/// Berkeley DB documentation.
///
///
/// Applications with special needs (for example, applications using
/// network protocols not supported by the Berkeley DB replication
/// manager), must perform additional configuration and call other
/// Berkeley DB replication methods. For more information on building
/// advanced replication applications, please see the Base Replication
/// API section in the Berkeley DB Programmer's Reference Guide for more
/// information.
///
///
/// Starting the replication manager consists of opening the TCP/IP
/// listening socket to accept incoming connections, and starting all
/// necessary background threads. When multiple processes share a
/// database environment, only one process can open the listening
/// socket; (and
/// ) automatically open the socket in
/// the first process to call it, and skips this step in the later calls
/// from other processes.
///
///
///
/// Specify the number of threads of control created and dedicated to
/// processing replication messages. In addition to these message
/// processing threads, the replication manager creates and manages a
/// few of its own threads of control.
///
public void RepMgrStartMaster(int nthreads) {
dbenv.repmgr_start(nthreads, DbConstants.DB_REP_MASTER);
}
///
/// Process an incoming replication message sent by a member of the
/// replication group to the local database environment.
///
///
///
/// RepProcessMessage is not called by most replication applications. It
/// should only be called by applications implementing their own network
/// transport layer, explicitly holding replication group elections and
/// handling replication messages outside of the replication manager
/// framework.
///
///
/// For implementation reasons, all incoming replication messages must
/// be processed using the same
/// object. It is not required that a single thread of control process
/// all messages, only that all threads of control processing messages
/// use the same object.
///
///
/// Before calling this method, the delegate
/// must already have been configured to send replication messages.
///
///
///
/// A copy of the control parameter specified by Berkeley DB on the
/// sending environment.
///
///
/// A copy of the rec parameter specified by Berkeley DB on the sending
/// environment.
///
///
/// The local identifier that corresponds to the environment that sent
/// the message to be processed (see Replication environment IDs in the
/// Programmer's Reference Guide for more information)..
///
/// The result of processing a message
public RepProcMsgResult RepProcessMessage(
DatabaseEntry control, DatabaseEntry rec, int envid) {
DB_LSN dblsn = new DB_LSN();
int ret = dbenv.rep_process_message(control,
rec, envid, dblsn);
LSN lsnp = new LSN(dblsn.file, dblsn.offset);
RepProcMsgResult result = new RepProcMsgResult(ret, lsnp);
if (result.Result == RepProcMsgResult.ProcMsgResult.ERROR)
DatabaseException.ThrowException(ret);
return result;
}
///
/// Configure the database environment as a client in a group of
/// replicated database environments.
///
public void RepStartClient() {
RepStartClient(null);
}
///
/// Configure the database environment as a client in a group of
/// replicated database environments.
///
///
///
/// RepStartClient is not called by most replication applications. It
/// should only be called by applications implementing their own network
/// transport layer, explicitly holding replication group elections and
/// handling replication messages outside of the replication manager
/// framework.
///
///
/// Replication master environments are the only database environments
/// where replicated databases may be modified. Replication client
/// environments are read-only as long as they are clients. Replication
/// client environments may be upgraded to be replication master
/// environments in the case that the current master fails or there is
/// no master present. If master leases are in use, this method cannot
/// be used to appoint a master, and should only be used to configure a
/// database environment as a master as the result of an election.
///
///
/// Before calling this method, the delegate
/// must already have been configured to send replication messages.
///
///
///
/// An opaque data item that is sent over the communication
/// infrastructure when the client comes online (see Connecting to a new
/// site in the Programmer's Reference Guide for more information). If
/// no such information is useful, cdata should be null.
///
public void RepStartClient(DatabaseEntry cdata) {
dbenv.rep_start(
cdata, DbConstants.DB_REP_CLIENT);
}
///
/// Configure the database environment as a master in a group of
/// replicated database environments.
///
public void RepStartMaster() {
RepStartMaster(null);
}
///
/// Configure the database environment as a master in a group of
/// replicated database environments.
///
///
///
/// RepStartMaster is not called by most replication applications. It
/// should only be called by applications implementing their own network
/// transport layer, explicitly holding replication group elections and
/// handling replication messages outside of the replication manager
/// framework.
///
///
/// Replication master environments are the only database environments
/// where replicated databases may be modified. Replication client
/// environments are read-only as long as they are clients. Replication
/// client environments may be upgraded to be replication master
/// environments in the case that the current master fails or there is
/// no master present. If master leases are in use, this method cannot
/// be used to appoint a master, and should only be used to configure a
/// database environment as a master as the result of an election.
///
///
/// Before calling this method, the delegate
/// must already have been configured to send replication messages.
///
///
///
/// An opaque data item that is sent over the communication
/// infrastructure when the client comes online (see Connecting to a new
/// site in the Programmer's Reference Guide for more information). If
/// no such information is useful, cdata should be null.
///
public void RepStartMaster(DatabaseEntry cdata) {
dbenv.rep_start(
cdata, DbConstants.DB_REP_MASTER);
}
///
/// Force master synchronization to begin for this client.
///
///
///
/// This method is the other half of setting
/// .
///
///
/// If an application has configured delayed master synchronization, the
/// application must synchronize explicitly (otherwise the client
/// remains out-of-date and ignores database changes forwarded
/// from the replication group master). RepSync may be called any time
/// after the client application learns that the new master has been
/// established (by receiving
/// ).
///
///
/// Before calling this method, the delegate
/// must already have been configured to send replication messages.
///
///
public void RepSync() {
dbenv.rep_sync(0);
}
///
/// The names of all of the log files that are no longer in use (for
/// example, that are no longer involved in active transactions), and
/// that may safely be archived for catastrophic recovery and then
/// removed from the system.
///
///
///
/// The Berkeley DB interfaces to the database environment logging
/// subsystem (for example, ) may
/// allocate log cursors and have open file descriptors for log files
/// as well. On operating systems where filesystem related system calls
/// (for example, rename and unlink on Windows/NT) can fail if a process
/// has an open file descriptor for the affected file, attempting to
/// move or remove the log files listed by ArchivableLogFiles may fail.
/// All Berkeley DB internal use of log cursors operates on active log
/// files only and furthermore, is short-lived in nature. So, an
/// application seeing such a failure should be restructured to retry
/// the operation until it succeeds. (Although this is not likely to be
/// necessary; it is hard to imagine a reason to move or rename a log
/// file in which transactions are being logged or aborted.)
///
///
/// When Replication Manager is in use, log archiving is performed
/// in a replication group-aware manner such that the log file status of
/// other sites in the group are examined to determine if a log
/// file could be in use.
///
///
/// See the db_archive utility for more information on database archival
/// procedures.
///
///
///
/// If true, all pathnames are returned as absolute pathnames, instead
/// of relative to the database home directory.
///
///
/// The names of all of the log files that are no longer in use
///
public List ArchivableLogFiles(bool AbsolutePaths) {
uint flags = 0;
flags |= AbsolutePaths ? DbConstants.DB_ARCH_ABS : 0;
return dbenv.log_archive(flags);
}
///
/// The database files that need to be archived in order to recover the
/// database from catastrophic failure. Database files that have not been
/// accessed during the lifetime of the current log files
/// are not included in this list. It is also possible that some
/// of the files referred to by the log have since been deleted from the
/// system.
///
///
///
/// When Replication Manager is in use, log archiving is performed
/// in a replication group-aware manner such that the log file status of
/// other sites in the group are examined to determine if a log
/// file could be in use.
///
///
/// See the db_archive utility for more information on database archival
/// procedures.
///
///
///
/// If true, all pathnames are returned as absolute pathnames, instead
/// of relative to the database home directory.
///
///
/// The database files that need to be archived in order to recover the
/// database from catastrophic failure.
///
public List ArchivableDatabaseFiles(bool AbsolutePaths) {
uint flags = DbConstants.DB_ARCH_DATA;
flags |= AbsolutePaths ? DbConstants.DB_ARCH_ABS : 0;
return dbenv.log_archive(flags);
}
///
/// The names of all of the log files
///
///
///
/// The Berkeley DB interfaces to the database environment logging
/// subsystem (for example, ) may
/// allocate log cursors and have open file descriptors for log files
/// as well. On operating systems where filesystem related system calls
/// (for example, rename and unlink on Windows/NT) can fail if a process
/// has an open file descriptor for the affected file, attempting to
/// move or remove the log files listed by LogFiles may fail. All
/// Berkeley DB internal use of log cursors operates on active log files
/// only and furthermore, is short-lived in nature. So, an application
/// seeing such a failure should be restructured to retry the operation
/// until it succeeds. (Although this is not likely to be necessary; it
/// is hard to imagine a reason to move or rename a log file in which
/// transactions are being logged or aborted.)
///
///
/// See the db_archive utility for more information on database archival
/// procedures.
///
///
///
/// If true, all pathnames are returned as absolute pathnames, instead
/// of relative to the database home directory.
///
///
/// All the log filenames, regardless of whether or not they are in use.
///
public List LogFiles(bool AbsolutePaths) {
uint flags = DbConstants.DB_ARCH_LOG;
flags |= AbsolutePaths ? DbConstants.DB_ARCH_ABS : 0;
return dbenv.log_archive(flags);
}
///
/// Remove log files that are no longer needed. Automatic log file
/// removal is likely to make catastrophic recovery impossible.
///
///
///
/// When Replication Manager is in use, log archiving is performed
/// in a replication group-aware manner such that the log file status of
/// other sites in the group are examined to determine if a log
/// file could be in use.
///
///
public void RemoveUnusedLogFiles() {
dbenv.log_archive(DbConstants.DB_ARCH_REMOVE);
}
///
/// Allocate a locker ID in an environment configured for Berkeley DB
/// Concurrent Data Store applications.
///
///
///
/// Calling discards the allocated
/// locker ID.
///
///
/// See Berkeley DB Concurrent Data Store applications in the
/// Programmer's Reference Guide for more information about when this is
/// required.
///
///
///
/// A Transaction object that uniquely identifies the locker ID
///
public Transaction BeginCDSGroup() {
return new Transaction(dbenv.cdsgroup_begin());
}
///
/// Create a new transaction in the environment, with the default
/// configuration.
///
/// A new transaction object
public Transaction BeginTransaction() {
return BeginTransaction(new TransactionConfig(), null);
}
///
/// Create a new transaction in the environment.
///
///
/// The configuration properties for the transaction
///
/// A new transaction object
public Transaction BeginTransaction(TransactionConfig cfg) {
return BeginTransaction(cfg, null);
}
///
/// Create a new transaction in the environment.
///
///
/// 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
/// .
///
///
/// The configuration properties for the transaction
///
///
/// If non-null, the new transaction is a nested transaction,
/// with as the new transaction's parent.
/// Transactions may be nested to any level.
///
/// A new transaction object
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;
}
///
/// Flush the underlying memory pool, write a checkpoint record to the
/// log, and then flush the log, even if there has been no activity
/// since the last checkpoint.
///
public void Checkpoint() {
dbenv.txn_checkpoint(0, 0, DbConstants.DB_FORCE);
}
///
/// If there has been any logging activity in the database environment
/// since the last checkpoint, flush the underlying memory pool, write a
/// checkpoint record to the log, and then flush the log.
///
///
/// A checkpoint is performed if more than kbytesWritten kilobytes of
/// log data have been written since the last checkpoint.
///
///
/// A checkpoint is performed if more than minutesElapsed minutes have
/// passed since the last checkpoint.
///
public void Checkpoint(uint kbytesWritten, uint minutesElapsed) {
dbenv.txn_checkpoint(kbytesWritten, minutesElapsed, 0);
}
///
/// By closing the Berkeley DB environment you can free allocated resources
/// and close any open databases along with the underlying subsystems.
///
///
///
/// The object should not be closed while any other handle that refers
/// to it is not yet closed; for example, database environment handles
/// must not be closed while transactions in the environment have
/// not yet been committed or aborted.
/// When you close each database handle, by default, the database is not synchronized.
/// To synchronize all open databases ensure that the last environment object is closed by the CloseForceSync() method.
/// When the close operation fails, the method returns a non-zero error value for the first instance of such error,
/// and continues to close the rest of the environment objects.
///
///
/// Where the environment was configured with
/// , calling CloseForceSync
/// aborts any unresolved transactions. Applications should not depend
/// on this behavior for transactions involving Berkeley DB databases;
/// all such transactions should be explicitly resolved. The problem
/// with depending on this semantic is that aborting an unresolved
/// transaction involving database operations requires a database
/// handle. Because the database handles should have been closed before
/// calling CloseForceSync, it is not possible to abort the
/// transaction, and recovery should be run on the Berkeley DB
/// environment before further operations are done.
///
///
/// In multithreaded applications, only a single thread may call
/// CloseForceSync.
///
///
public void Close() {
dbenv.close(0);
}
///
/// Close the Berkeley DB environment, freeing any allocated resources,
/// closing any open databases as well as underlying subsystems.
///
///
///
/// The object should not be closed while any other handle that refers
/// to it is not yet closed; for example, database environment handles
/// must not be closed while transactions in the environment have
/// not yet been committed or aborted. If there are open database
/// handles, they are all closed, and each of them is synced on
/// close. The first error in the close operations, if any, is
/// returned at last, and the environment close procedures
/// carry on anyway.
///
///
/// Where the environment was configured with
/// , calling CloseForceSync
/// aborts any unresolved transactions. Applications should not depend
/// on this behavior for transactions involving Berkeley DB databases;
/// all such transactions should be explicitly resolved. The problem
/// with depending on this semantic is that aborting an unresolved
/// transaction involving database operations requires a database
/// handle. Because the database handles should have been closed before
/// calling CloseForceSync, it is not possible to abort the
/// transaction, and recovery should be run on the Berkeley DB
/// environment before further operations are done.
///
///
/// In multithreaded applications, only a single thread may call
/// CloseForceSync.
///
///
public void CloseForceSync() {
dbenv.close(DbConstants.DB_FORCESYNC);
}
///
/// Close the Berkeley DB environment, freeing any allocated resources,
/// closing any open databases as well as underlying subsystems.
///
///
///
/// The object should not be closed while any other handle that refers
/// to it is not yet closed; for example, database environment handles
/// must not be closed while transactions in the environment have
/// not yet been committed or aborted. Calling CloseForceSyncEnv flushes
/// all memory mapped environment regions before closing the environment.
///
///
public void CloseForceSyncEnv() {
dbenv.close(DbConstants.DB_FORCESYNCENV);
}
///
/// Close the Berkeley DB environment, freeing any allocated resources,
/// closing any open databases as well as underlying subsystems.
///
///
///
/// The object should not be closed while any other handle that refers
/// to it is not yet closed; for example, database environment handles
/// must not be closed while transactions in the environment have
/// not yet been committed or aborted. Calling CloseForceSyncAndForceSyncEnv
/// has the effect of both CloseForceSync and CloseForceSyncEnv. See
/// CloseForceSync and CloseForceSyncEnv documentation for more details.
///
public void CloseForceSyncAndForceSyncEnv() {
dbenv.close(DbConstants.DB_FORCESYNC | DbConstants.DB_FORCESYNCENV);
}
///
/// Run one iteration of the deadlock detector. The deadlock detector
/// traverses the lock table and marks one of the participating lock
/// requesters for rejection in each deadlock it finds.
///
/// Specify which lock request(s) to reject
/// The number of lock requests that were rejected.
public uint DetectDeadlocks(DeadlockPolicy atype) {
uint rejectCount = 0;
if (atype == null)
atype = DeadlockPolicy.DEFAULT;
dbenv.lock_detect(0, atype.policy, ref rejectCount);
return rejectCount;
}
///
/// Check for threads of control (either a true thread or a process)
/// that have exited while manipulating Berkeley DB library data
/// structures, while holding a logical database lock, or with an
/// unresolved transaction (that is, a transaction that was never
/// aborted or committed).
///
///
///
/// For more information, see Architecting Data Store and Concurrent
/// Data Store applications, and Architecting Transactional Data Store
/// applications, both in the Berkeley DB Programmer's Reference Guide.
///
///
/// FailCheck is based on the and
/// delegates. Applications calling
/// FailCheck must have already set , and
/// must have configured .
///
///
/// If FailCheck determines a thread of control exited while holding
/// database read locks, it releases those locks. If FailCheck
/// determines a thread of control exited with an unresolved
/// transaction, the transaction aborts. In either of these
/// cases, FailCheck returns successfully and the application may
/// continue to use the database environment.
///
///
/// In either of these cases, FailCheck also reports the process and
/// thread IDs associated with any released locks or aborted
/// transactions. The information is printed to a specified output
/// channel (see for more information), or
/// passed to an application delegate (see for
/// more information).
///
///
/// If FailCheck determines a thread of control has exited such that
/// database environment recovery is required, it throws
/// . In this case, the application
/// should not continue to use the database environment. For a further
/// description as to the actions the application should take when this
/// failure occurs, see Handling failure in Data Store and Concurrent
/// Data Store applications, and Handling failure in Transactional Data
/// Store applications, both in the Berkeley DB Programmer's Reference
/// Guide.
///
///
public void FailCheck() {
dbenv.failchk(0);
}
///
/// This method checks to see if a specified transaction has been replicated from
/// the master of a replication group. It may be called by applications using either
/// the Base API or the Replication Manager.
///
///
/// The commit token from a transaction previously written at a master
/// site in the replication group. Commit tokens are retrieved using
/// the method.
///
///
/// The maximum time to wait for the transaction to arrive by replication, expressed in
/// microseconds. To check the status of the transaction without waiting, the timeout
/// may be specified as 0.
///
///
/// This method returns TransactionAppliedStatus.APPLIED to indicate that the specified
/// transaction has indeed been applied at the local site. TransactionAppliedStatus.TIMEOUT
/// returns if the specified transaction has not yet arrived at the calling site,
/// but can be expected to arrive soon. TransactionAppliedStatus.NOTFOUND is returned
/// if the transaction has not been applied at the local site, and it can be determined that
/// the transaction has been rolled back due to a master takeover, and is therefore never
/// expected to arrive. TransactionAppliedStatus.EMPTY_TRANSACTION returns if the specified
/// token was generated by a transaction that did not modify the database environment
/// (e.g., a read-only transaction).
///
public TransactionAppliedStatus IsTransactionApplied(byte[] token, uint timeout)
{
if (token == null)
throw new ArgumentNullException("The token cannot be null.");
if (token.Length != DbConstants.DB_TXN_TOKEN_SIZE)
{
throw new ArgumentOutOfRangeException("The token size must be "
+ DbConstants.DB_TXN_TOKEN_SIZE);
}
DB_TXN_TOKEN txn_token = new DB_TXN_TOKEN(token);
int ret = dbenv.is_transaction_applied(txn_token, timeout, 0);
switch (ret)
{
case 0:
return TransactionAppliedStatus.APPLIED;
case DbConstants.DB_TIMEOUT:
return TransactionAppliedStatus.TIMEOUT;
case DbConstants.DB_NOTFOUND:
return TransactionAppliedStatus.NOTFOUND;
case DbConstants.DB_KEYEMPTY:
return TransactionAppliedStatus.EMPTY_TRANSACTION;
default:
throw new DatabaseException(ret);
}
}
///
/// Map an LSN object to a log filename
///
///
/// The DB_LSN structure for which a filename is wanted.
///
///
/// The name of the file containing the record named by
/// .
///
public string LogFile(LSN logSeqNum) {
return dbenv.log_file(LSN.getDB_LSN(logSeqNum));
}
///
/// Write all log records to disk.
///
public void LogFlush() {
LogFlush(null);
}
///
/// Write log records to disk.
///
///
/// All log records with LSN values less than or equal to
/// are written to disk. If null, all
/// records in the log are flushed.
///
public void LogFlush(LSN logSeqNum) {
dbenv.log_flush(LSN.getDB_LSN(logSeqNum));
}
///
/// Verify log records of this environment.
///
///
/// Log verification configuration object.
///
public int LogVerify(LogVerifyConfig config) {
String dbfile, dbname, home;
int etime, stime;
uint cachesize;
uint efile, eoffset, sfile, soffset;
int caf, ret, verbose;
caf = ret = verbose = 0;
etime = stime = 0;
home = config.EnvHome;
dbfile = config.DbFile;
dbname = config.DbName;
try {
etime = (int)config.EndTime.ToFileTimeUtc();
stime = (int)config.StartTime.ToFileTimeUtc();
} catch (Exception){}
efile = config.EndLsn.LogFileNumber;
eoffset = config.EndLsn.Offset;
sfile = config.StartLsn.LogFileNumber;
soffset = config.StartLsn.Offset;
cachesize = config.CacheSize;
if (config.Verbose)
verbose = 1;
if (config.ContinueAfterFail)
caf = 1;
try {
ret = dbenv.log_verify(home, cachesize, dbfile, dbname,
stime, etime, sfile, soffset, efile, eoffset, caf, verbose);
} catch (Exception){}
return (ret);
}
///
/// Append a record to the log
///
/// The record to write to the log.
///
/// If true, the log is forced to disk after this record is written,
/// guaranteeing that all records with LSN values less than or equal to
/// the one being "put" are on disk before LogWrite returns.
///
/// The LSN of the written record
public LSN LogWrite(DatabaseEntry dbt, bool flush) {
DB_LSN lsn = new DB_LSN();
dbenv.log_put(lsn,
dbt, flush ? DbConstants.DB_FLUSH : 0);
return new LSN(lsn.file, lsn.offset);
}
///
/// Set the panic state for the database environment. (Database
/// environments in a panic state normally refuse all attempts to call
/// Berkeley DB functions, throwing .)
///
public void Panic() {
dbenv.set_flags(DbConstants.DB_PANIC_ENVIRONMENT, 1);
}
///
/// Restore transactions that were prepared, but not yet resolved at the
/// time of the system shut down or crash, to their state prior to the
/// shut down or crash, including any locks previously held.
///
///
/// Calls to Recover from different threads of control should not be
/// intermixed in the same environment.
///
///
/// The maximum number of objects
/// to return.
///
///
/// If true, continue returning a list of prepared, but not yet resolved
/// transactions, starting where the last call to Recover left off. If
/// false, begins a new pass over all prepared, but not yet completed
/// transactions, regardless of whether they have already been returned
/// in previous calls to Recover.
///
/// A list of the prepared transactions
public PreparedTransaction[] Recover(int count, bool resume) {
uint flags = 0;
flags |= resume ? DbConstants.DB_NEXT : DbConstants.DB_FIRST;
return dbenv.txn_recover(count, flags);
}
///
/// Remove the underlying file represented by ,
/// incidentally removing all of the databases it contained.
///
/// The physical file to be removed.
///
/// If true, enclose RemoveDB within a transaction. If the call
/// succeeds, changes made by the operation are recoverable. If the
/// call fails, the operation has made no changes.
///
public void RemoveDB(string file, bool autoCommit) {
RemoveDB(file, null, autoCommit, null);
}
///
/// Remove the database specified by and
/// . If no database is specified, the
/// underlying file represented by is removed,
/// incidentally removing all of the databases it contained.
///
///
/// The physical file which contains the database(s) to be removed.
///
/// The database to be removed.
///
/// If true, enclose RemoveDB within a transaction. If the call
/// succeeds, changes made by the operation are recoverable. If the
/// call fails, the operation has made no changes.
///
public void RemoveDB(string file, string database, bool autoCommit) {
RemoveDB(file, database, autoCommit, null);
}
///
/// Remove the underlying file represented by ,
/// incidentally removing all of the databases it contained.
///
/// The physical file to be removed.
///
/// If true, enclose RemoveDB within a transaction. If the call
/// succeeds, changes made by the operation are recoverable. If the
/// call fails, the operation has made no changes.
///
///
/// If the operation is part of an application-specified transaction,
/// is a Transaction object returned from
/// ; if
/// the operation is part of a Berkeley DB Concurrent Data Store group,
/// is a handle returned from
/// ; otherwise null. If
/// null, but or
/// is true, the operation is implicitly transaction protected.
///
public void RemoveDB(string file, bool autoCommit, Transaction txn) {
RemoveDB(file, null, autoCommit, txn);
}
///
/// Remove the database specified by and
/// . If no database is specified, the
/// underlying file represented by is removed,
/// incidentally removing all of the databases it contained.
///
///
/// The physical file which contains the database(s) to be removed.
///
/// The database to be removed.
///
/// If true, enclose RemoveDB within a transaction. If the call
/// succeeds, changes made by the operation are recoverable. If the
/// call fails, the operation has made no changes.
///
///
/// If the operation is part of an application-specified transaction,
/// is a Transaction object returned from
/// ; if
/// the operation is part of a Berkeley DB Concurrent Data Store group,
/// is a handle returned from
/// ; otherwise null. If
/// null, but or
/// is true, the operation is implicitly transaction protected.
///
public void RemoveDB(
string file, string database, bool autoCommit, Transaction txn) {
dbenv.dbremove(Transaction.getDB_TXN(txn),
file, database, autoCommit ? DbConstants.DB_AUTO_COMMIT : 0);
}
///
/// Rename the underlying file represented by
/// using the value supplied to , incidentally
/// renaming all of the databases it contained.
///
/// The physical file to be renamed.
/// The new name of the database or file.
///
/// If true, enclose RenameDB within a transaction. If the call
/// succeeds, changes made by the operation are recoverable. If the
/// call fails, the operation has made no changes.
///
public void RenameDB(string file, string newname, bool autoCommit) {
RenameDB(file, null, newname, autoCommit, null);
}
///
/// Rename the database specified by and
/// to . If no
/// database is specified, the underlying file represented by
/// is renamed using the value supplied to
/// , incidentally renaming all of the
/// databases it contained.
///
///
/// The physical file which contains the database(s) to be renamed.
///
/// The database to be renamed.
/// The new name of the database or file.
///
/// If true, enclose RenameDB within a transaction. If the call
/// succeeds, changes made by the operation are recoverable. If the
/// call fails, the operation has made no changes.
///
public void RenameDB(
string file, string database, string newname, bool autoCommit) {
RenameDB(file, database, newname, autoCommit, null);
}
///
/// Rename the underlying file represented by
/// using the value supplied to , incidentally
/// renaming all of the databases it contained.
///
/// The physical file to be renamed.
/// The new name of the database or file.
///
/// If true, enclose RenameDB within a transaction. If the call
/// succeeds, changes made by the operation are recoverable. If the
/// call fails, the operation has made no changes.
///
///
/// If the operation is part of an application-specified transaction,
/// is a Transaction object returned from
/// ; if
/// the operation is part of a Berkeley DB Concurrent Data Store group,
/// is a handle returned from
/// ; otherwise null. If
/// null, but or
/// is true, the operation is implicitly transaction protected.
///
public void RenameDB(string file,
string newname, bool autoCommit, Transaction txn) {
RenameDB(file, null, newname, autoCommit, txn);
}
///
/// Rename the database specified by and
/// to . If no
/// database is specified, the underlying file represented by
/// is renamed using the value supplied to
/// , incidentally renaming all of the
/// databases it contained.
///
///
/// The physical file which contains the database(s) to be renamed.
///
/// The database to be renamed.
/// The new name of the database or file.
///
/// If true, enclose RenameDB within a transaction. If the call
/// succeeds, changes made by the operation are recoverable. If the
/// call fails, the operation has made no changes.
///
///
/// If the operation is part of an application-specified transaction,
/// is a Transaction object returned from
/// ; if
/// the operation is part of a Berkeley DB Concurrent Data Store group,
/// is a handle returned from
/// ; otherwise null. If
/// null, but or
/// is true, the operation is implicitly transaction protected.
///
public void RenameDB(string file,
string database, string newname, bool autoCommit, Transaction txn) {
dbenv.dbrename(Transaction.getDB_TXN(txn), file,
database, newname, autoCommit ? DbConstants.DB_AUTO_COMMIT : 0);
}
///
/// Allow database files to be copied and used in the same database
/// environment as the original.
///
///
///
/// All databases contain an ID string used to identify the database in
/// the database environment cache. If a physical database file is
/// copied, and used in the same environment as another file with the
/// same ID strings, corruption can occur. ResetFileID creates new ID
/// strings for all of the databases in the physical file.
///
///
/// ResetFileID modifies the physical file, in-place. Applications
/// should not reset IDs in files that are currently in use.
///
///
///
/// The name of the physical file in which new file IDs are to be created.
///
///
/// If true, the file contains encrypted databases.
///
public void ResetFileID(string file, bool encrypted) {
dbenv.fileid_reset(file, encrypted ? DbConstants.DB_ENCRYPT : 0);
}
///
/// Allow database files to be moved from one transactional database
/// environment to another.
///
///
///
/// Database pages in transactional database environments contain
/// references to the environment's log files (that is, log sequence
/// numbers, or s). Copying or moving a database file
/// from one database environment to another, and then modifying it, can
/// result in data corruption if the LSNs are not first cleared.
///
///
/// LSNs should be reset before moving or copying the database
/// file into a new database environment, rather than moving or copying
/// the database file and then resetting the LSNs. Berkeley DB has
/// consistency checks that may be triggered if an application calls
/// ResetLSN on a database in a new environment when the database LSNs
/// still reflect the old environment.
///
///
/// The ResetLSN method modifies the physical file, in-place.
/// Applications should not reset LSNs in files that are currently in
/// use.
///
///
///
///
public void ResetLSN(string file, bool encrypted) {
dbenv.lsn_reset(file, encrypted ? DbConstants.DB_ENCRYPT : 0);
}
///
/// Limit the number of sequential write operations scheduled by the
/// library when flushing dirty pages from the cache.
///
///
/// The maximum number of sequential write operations scheduled by the
/// library when flushing dirty pages from the cache, or 0 if there is
/// no limitation on the number of sequential write operations.
///
///
/// The number of microseconds the thread of control should pause before
/// scheduling further write operations. It must be specified as an
/// unsigned 32-bit number of microseconds, limiting the maximum pause
/// to roughly 71 minutes.
///
public void SetMaxSequentialWrites(int maxWrites, uint pause) {
dbenv.set_mp_max_write(maxWrites, pause);
}
///
/// Flush all modified pages in the cache to their backing files.
///
///
/// Pages in the cache that cannot be immediately written back to disk
/// (for example, pages that are currently in use by another thread of
/// control) are waited for and written to disk as soon as it is
/// possible to do so.
///
public void SyncMemPool() {
SyncMemPool(null);
}
///
/// Flush modified pages in the cache with log sequence numbers less
/// than to their backing files.
///
///
/// Pages in the cache that cannot be immediately written back to disk
/// (for example, pages that are currently in use by another thread of
/// control) are waited for and written to disk as soon as it is
/// possible to do so.
///
///
/// All modified pages with a log sequence number less than the minLSN
/// parameter are written to disk. If null, all modified pages in the
/// cache are written to disk.
///
public void SyncMemPool(LSN minLSN) {
dbenv.memp_sync(LSN.getDB_LSN(minLSN));
}
///
/// Ensure that a specified percent of the pages in the cache are clean,
/// by writing dirty pages to their backing files.
///
///
/// The percent of the pages in the cache that should be clean.
///
///
/// The number of pages written to reach the specified percentage is
/// copied.
///
public int TrickleCleanMemPool(int pctClean) {
int ret = 0;
dbenv.memp_trickle(pctClean, ref ret);
return ret;
}
///
/// Append an informational message to the Berkeley DB database
/// environment log files.
///
///
/// WriteToLog allows applications to include information in the
/// database environment log files, for later review using the
/// db_printlog utility. This method is intended for debugging and
/// performance tuning.
///
/// The message to append to the log files
public void WriteToLog(string str) {
dbenv.log_printf(null, str);
}
///
/// Append an informational message to the Berkeley DB database
/// environment log files.
///
///
/// WriteToLog allows applications to include information in the
/// database environment log files, for later review using the
/// db_printlog utility. This method is intended for debugging and
/// performance tuning.
///
/// The message to append to the log files
///
/// If the operation is part of an application-specified transaction,
/// is a Transaction object returned from
/// ;
/// otherwise null.
///
public void WriteToLog(string str, Transaction txn) {
dbenv.log_printf(Transaction.getDB_TXN(txn), str);
}
#region Stats
///
/// The locking subsystem statistics
///
/// The locking subsystem statistics
public LockStats LockingSystemStats() {
return LockingSystemStats(false);
}
///
/// The locking subsystem statistics
///
///
/// If true, reset statistics after returning their values.
///
/// The locking subsystem statistics
public LockStats LockingSystemStats(bool clearStats) {
uint flags = 0;
flags |= clearStats ? DbConstants.DB_STAT_CLEAR : 0;
LockStatStruct st = dbenv.lock_stat(flags);
return new LockStats(st);
}
///
/// The logging subsystem statistics
///
/// The logging subsystem statistics
public LogStats LoggingSystemStats() {
return LoggingSystemStats(false);
}
///
/// The logging subsystem statistics
///
///
/// If true, reset statistics after returning their values.
///
/// The logging subsystem statistics
public LogStats LoggingSystemStats(bool clearStats) {
uint flags = 0;
flags |= clearStats ? DbConstants.DB_STAT_CLEAR : 0;
LogStatStruct st = dbenv.log_stat(flags);
return new LogStats(st);
}
///
/// The memory pool (that is, the buffer cache) subsystem statistics
///
/// The memory pool subsystem statistics
public MPoolStats MPoolSystemStats() {
return MPoolSystemStats(false);
}
///
/// The memory pool (that is, the buffer cache) subsystem statistics
///
///
/// If true, reset statistics after returning their values.
///
/// The memory pool subsystem statistics
public MPoolStats MPoolSystemStats(bool clearStats) {
uint flags = 0;
flags |= clearStats ? DbConstants.DB_STAT_CLEAR : 0;
MempStatStruct st = dbenv.memp_stat(flags);
return new MPoolStats(st);
}
///
/// The mutex subsystem statistics
///
/// The mutex subsystem statistics
public MutexStats MutexSystemStats() {
return MutexSystemStats(false);
}
///
/// The mutex subsystem statistics
///
///
/// If true, reset statistics after returning their values.
///
/// The mutex subsystem statistics
public MutexStats MutexSystemStats(bool clearStats) {
uint flags = 0;
flags |= clearStats ? DbConstants.DB_STAT_CLEAR : 0;
MutexStatStruct st = dbenv.mutex_stat(flags);
return new MutexStats(st);
}
///
/// The replication manager statistics
///
/// The replication manager statistics
public RepMgrStats RepMgrSystemStats() {
return RepMgrSystemStats(false);
}
///
/// The replication manager statistics
///
///
/// If true, reset statistics after returning their values.
///
/// The replication manager statistics
public RepMgrStats RepMgrSystemStats(bool clearStats) {
uint flags = 0;
flags |= clearStats ? DbConstants.DB_STAT_CLEAR : 0;
RepMgrStatStruct st = dbenv.repmgr_stat(flags);
return new RepMgrStats(st);
}
///
/// The replication subsystem statistics
///
/// The replication subsystem statistics
public ReplicationStats ReplicationSystemStats() {
return ReplicationSystemStats(false);
}
///
/// The replication subsystem statistics
///
///
/// If true, reset statistics after returning their values.
///
/// The replication subsystem statistics
public ReplicationStats ReplicationSystemStats(bool clearStats) {
uint flags = 0;
flags |= clearStats ? DbConstants.DB_STAT_CLEAR : 0;
ReplicationStatStruct st = dbenv.rep_stat(flags);
return new ReplicationStats(st);
}
///
/// The transaction subsystem statistics
///
/// The transaction subsystem statistics
public TransactionStats TransactionSystemStats() {
return TransactionSystemStats(false);
}
///
/// The transaction subsystem statistics
///
///
/// If true, reset statistics after returning their values.
///
/// The transaction subsystem statistics
public TransactionStats TransactionSystemStats(bool clearStats) {
uint flags = 0;
flags |= clearStats ? DbConstants.DB_STAT_CLEAR : 0;
TxnStatStruct st = dbenv.txn_stat(flags);
return new TransactionStats(st);
}
#endregion Stats
#region Print Stats
///
/// Display the locking subsystem statistical information, as described
/// by .
///
public void PrintLockingSystemStats() {
PrintLockingSystemStats
(false, false, false, false, false, false, false);
}
///
/// Display the locking subsystem statistical information, as described
/// by .
///
///
/// If true, display all available information.
///
///
/// If true, reset statistics after displaying their values.
///
public void PrintLockingSystemStats(bool PrintAll, bool ClearStats) {
PrintLockingSystemStats(
PrintAll, ClearStats, false, false, false, false, false);
}
///
/// Display the locking subsystem statistical information, as described
/// by .
///
///
/// If true, display all available information.
///
///
/// If true, reset statistics after displaying their values.
///
///
/// If true, display the lock conflict matrix.
///
///
/// If true, display the lockers within hash chains.
///
///
/// If true, display the lock objects within hash chains.
///
///
/// If true, display the locking subsystem parameters.
///
public void PrintLockingSystemStats(bool PrintAll, bool ClearStats,
bool ConflictMatrix, bool Lockers, bool Objects, bool Parameters) {
PrintLockingSystemStats(PrintAll, ClearStats, ConflictMatrix,
Lockers, Objects, Parameters, false);
}
///
/// Display the locking subsystem statistical information, as described
/// by .
///
///
/// If true, display all available information.
///
///
/// If true, reset statistics after displaying their values.
///
///
/// If true, display the lock conflict matrix.
///
///
/// If true, display the lockers within hash chains.
///
///
/// If true, display the lock objects within hash chains.
///
///
/// If true, display the locking subsystem parameters.
///
///
/// If true, display allocation information.
///
public void PrintLockingSystemStats(bool PrintAll, bool ClearStats,
bool ConflictMatrix, bool Lockers, bool Objects, bool Parameters,
bool PrintAlloc) {
uint flags = 0;
flags |= PrintAll ? DbConstants.DB_STAT_ALL : 0;
flags |= ClearStats ? DbConstants.DB_STAT_CLEAR : 0;
flags |= ConflictMatrix ? DbConstants.DB_STAT_LOCK_CONF : 0;
flags |= Lockers ? DbConstants.DB_STAT_LOCK_LOCKERS : 0;
flags |= Objects ? DbConstants.DB_STAT_LOCK_OBJECTS : 0;
flags |= Parameters ? DbConstants.DB_STAT_LOCK_PARAMS : 0;
flags |= PrintAlloc ? DbConstants.DB_STAT_ALLOC : 0;
dbenv.lock_stat_print(flags);
}
///
/// Display the logging subsystem statistical information, as described
/// by .
///
public void PrintLoggingSystemStats() {
PrintLoggingSystemStats(false, false, false);
}
///
/// Display the logging subsystem statistical information, as described
/// by .
///
///
/// If true, display all available information.
///
///
/// If true, reset statistics after displaying their values.
///
public void PrintLoggingSystemStats(bool PrintAll, bool ClearStats) {
PrintLoggingSystemStats(PrintAll, ClearStats, false);
}
///
/// Display the logging subsystem statistical information, as described
/// by .
///
///
/// If true, display all available information.
///
///
/// If true, reset statistics after displaying their values.
///
///
/// If true, display allocation information.
///
public void PrintLoggingSystemStats(bool PrintAll, bool ClearStats,
bool PrintAlloc) {
uint flags = 0;
flags |= PrintAll ? DbConstants.DB_STAT_ALL : 0;
flags |= ClearStats ? DbConstants.DB_STAT_CLEAR : 0;
flags |= PrintAlloc ? DbConstants.DB_STAT_ALLOC : 0;
dbenv.log_stat_print(flags);
}
///
/// Display the memory pool (buffer cache) subsystem
/// statistical information, as described by .
///
public void PrintMPoolSystemStats() {
PrintMPoolSystemStats(false, false, false, false);
}
///
/// Display the memory pool (buffer cache) subsystem
/// statistical information, as described by .
///
///
/// If true, display all available information.
///
///
/// If true, reset statistics after displaying their values.
///
public void PrintMPoolSystemStats(bool PrintAll, bool ClearStats) {
PrintMPoolSystemStats(PrintAll, ClearStats, false, false);
}
///
/// Display the memory pool (buffer cache) subsystem
/// statistical information, as described by .
///
///
/// If true, display all available information.
///
///
/// If true, reset statistics after displaying their values.
///
///
/// If true, display the buffers with hash chains.
///
public void PrintMPoolSystemStats(
bool PrintAll, bool ClearStats, bool HashChains) {
PrintMPoolSystemStats(PrintAll, ClearStats, HashChains, false);
}
///
/// Display the memory pool (that is, buffer cache) subsystem
/// statistical information, as described by .
///
///
/// If true, display all available information.
///
///
/// If true, display allocation information.
///
///
/// If true, reset statistics after displaying their values.
///
///
/// If true, display the buffers with hash chains.
///
public void PrintMPoolSystemStats(
bool PrintAll, bool ClearStats, bool HashChains, bool PrintAlloc) {
uint flags = 0;
flags |= PrintAll ? DbConstants.DB_STAT_ALL : 0;
flags |= ClearStats ? DbConstants.DB_STAT_CLEAR : 0;
flags |= HashChains ? DbConstants.DB_STAT_MEMP_HASH : 0;
flags |= PrintAlloc ? DbConstants.DB_STAT_ALLOC : 0;
dbenv.memp_stat_print(flags);
}
///
/// Display the mutex subsystem statistical information, as described
/// by .
///
public void PrintMutexSystemStats() {
PrintMutexSystemStats(false, false, false);
}
///
/// Display the mutex subsystem statistical information, as described
/// by .
///
///
/// If true, display all available information.
///
///
/// If true, reset statistics after displaying their values.
///
public void PrintMutexSystemStats(bool PrintAll, bool ClearStats) {
PrintMutexSystemStats(PrintAll, ClearStats, false);
}
///
/// Display the mutex subsystem statistical information, as described
/// by .
///
///
/// If true, display all available information.
///
///
/// If true, display allocation information.
///
///
/// If true, reset statistics after displaying their values.
///
public void PrintMutexSystemStats(bool PrintAll, bool ClearStats,
bool PrintAlloc) {
uint flags = 0;
flags |= PrintAll ? DbConstants.DB_STAT_ALL : 0;
flags |= ClearStats ? DbConstants.DB_STAT_CLEAR : 0;
flags |= PrintAlloc ? DbConstants.DB_STAT_ALLOC : 0;
dbenv.mutex_stat_print(flags);
}
///
/// Display the replication manager statistical information, as
/// described by .
///
public void PrintRepMgrSystemStats() {
PrintRepMgrSystemStats(false, false);
}
///
/// Display the replication manager statistical information, as
/// described by .
///
///
/// If true, display all available information.
///
///
/// If true, reset statistics after displaying their values.
///
public void PrintRepMgrSystemStats(bool PrintAll, bool ClearStats) {
uint flags = 0;
flags |= PrintAll ? DbConstants.DB_STAT_ALL : 0;
flags |= ClearStats ? DbConstants.DB_STAT_CLEAR : 0;
dbenv.repmgr_stat_print(flags);
}
///
/// Display the replication subsystem statistical information, as
/// described by .
///
public void PrintReplicationSystemStats() {
PrintReplicationSystemStats(false, false);
}
///
/// Display the replication subsystem statistical information, as
/// described by .
///
///
/// If true, display all available information.
///
///
/// If true, reset statistics after displaying their values.
///
public void
PrintReplicationSystemStats(bool PrintAll, bool ClearStats) {
uint flags = 0;
flags |= PrintAll ? DbConstants.DB_STAT_ALL : 0;
flags |= ClearStats ? DbConstants.DB_STAT_CLEAR : 0;
dbenv.rep_stat_print(flags);
}
///
/// Display the default statistical information.
///
public void PrintStats() {
PrintStats(false, false, false, false);
}
///
/// Display the default statistical information.
///
///
/// If true, display all available information.
///
///
/// If true, reset statistics after displaying their values.
///
public void PrintStats(bool PrintAll, bool ClearStats) {
PrintStats(PrintAll, ClearStats, false, false);
}
///
/// Display the default subsystem statistical information.
///
public void PrintSubsystemStats() {
PrintStats(false, false, true, false);
}
///
/// Display the default subsystem statistical information.
///
///
/// If true, display all available information.
///
///
/// If true, reset statistics after displaying their values.
///
public void PrintSubsystemStats(bool PrintAll, bool ClearStats) {
PrintStats(PrintAll, ClearStats, true, false);
}
///
/// Display the default statistical information.
///
///
/// If true, display all available information.
///
///
/// If true, reset statistics after displaying their values.
///
///
/// If true, display subsystem statistical information.
///
private void PrintStats(bool PrintAll, bool ClearStats, bool PrintSubs) {
PrintStats(PrintAll, ClearStats, PrintSubs, false);
}
///
/// Display the default statistical information.
///
///
/// If true, display all available information.
///
///
/// If true, reset statistics after displaying their values.
///
///
/// If true, display subsystem statistical information.
///
///
/// If true, display allocation information.
///
private void PrintStats(bool PrintAll, bool ClearStats, bool PrintSubs,
bool PrintAlloc) {
uint flags = 0;
flags |= PrintAll ? DbConstants.DB_STAT_ALL : 0;
flags |= ClearStats ? DbConstants.DB_STAT_CLEAR : 0;
flags |= PrintSubs ? DbConstants.DB_STAT_SUBSYSTEM : 0;
flags |= PrintAlloc ? DbConstants.DB_STAT_ALLOC : 0;
dbenv.stat_print(flags);
}
///
/// Display the transaction subsystem statistical information, as
/// described by .
///
public void PrintTransactionSystemStats() {
PrintTransactionSystemStats(false, false, false);
}
///
/// Display the transaction subsystem statistical information, as
/// described by .
///
///
/// If true, display all available information.
///
///
/// If true, reset statistics after displaying their values.
///
public void PrintTransactionSystemStats(bool PrintAll, bool ClearStats) {
PrintTransactionSystemStats(PrintAll, ClearStats, false);
}
///
/// Display the transaction subsystem statistical information, as
/// described by .
///
///
/// If true, display all available information.
///
///
/// If true, reset statistics after displaying their values.
///
///
/// If true, display allocation information.
///
public void PrintTransactionSystemStats(bool PrintAll, bool ClearStats,
bool PrintAlloc) {
uint flags = 0;
flags |= PrintAll ? DbConstants.DB_STAT_ALL : 0;
flags |= ClearStats ? DbConstants.DB_STAT_CLEAR : 0;
flags |= PrintAlloc ? DbConstants.DB_STAT_ALLOC : 0;
dbenv.txn_stat_print(flags);
}
#endregion Print Stats
private uint getRepTimeout(int which) {
uint ret = 0;
dbenv.rep_get_timeout(which, ref ret);
return ret;
}
private bool getRepConfig(uint which) {
int onoff = 0;
dbenv.rep_get_config(which, ref onoff);
return (onoff != 0);
}
#region Unsupported Subsystem Methods
///
/// The Berkeley DB process' environment may be permitted to specify
/// information to be used when naming files; see Berkeley DB File
/// Naming in the Programmer's Reference Guide for more information.
///
public bool UseEnvironmentVars {
get {
uint flags = 0;
dbenv.get_open_flags(ref flags);
return (flags & DbConstants.DB_USE_ENVIRON) != 0;
}
}
private bool USE_ENVIRON_ROOT {
get {
uint flags = 0;
dbenv.get_open_flags(ref flags);
return (flags & DbConstants.DB_USE_ENVIRON_ROOT) != 0;
}
}
private uint CreateLockerID() {
uint ret = 0;
dbenv.lock_id(ref ret);
return ret;
}
private void FreeLockerID(uint locker) {
dbenv.lock_id_free(locker);
}
private Lock GetLock(
uint locker, bool wait, DatabaseEntry obj, LockMode mode) {
return new Lock(dbenv.lock_get(locker,
wait ? 0 : DbConstants.DB_LOCK_NOWAIT,
obj, LockMode.GetMode(mode)));
}
private Mutex GetMutex(bool SelfBlock, bool SingleProcess) {
uint m = 0;
uint flags = 0;
flags |= SelfBlock ? DbConstants.DB_MUTEX_SELF_BLOCK : 0;
flags |= SingleProcess ? DbConstants.DB_MUTEX_PROCESS_ONLY : 0;
dbenv.mutex_alloc(flags, ref m);
return new Mutex(this, m);
}
private void LockMany(uint locker, bool wait, LockRequest[] vec) {
LockMany(locker, wait, vec, null);
}
private void LockMany(
uint locker, bool wait, LockRequest[] vec, LockRequest failedReq) {
IntPtr[] reqList = new IntPtr[vec.Length];
DB_LOCKREQ[] lst = new DB_LOCKREQ[vec.Length];
for (int i = 0; i < vec.Length; i++) {
reqList[i] = DB_LOCKREQ.getCPtr(
LockRequest.get_DB_LOCKREQ(vec[i])).Handle;
lst[i] = LockRequest.get_DB_LOCKREQ(vec[i]);
}
dbenv.lock_vec(locker, wait ? 0 : DbConstants.DB_TXN_NOWAIT,
reqList, vec.Length, LockRequest.get_DB_LOCKREQ(failedReq));
}
private void PutLock(Lock lck) {
dbenv.lock_put(Lock.GetDB_LOCK(lck));
}
#endregion
}
}