/*-
* See the file LICENSE for redistribution information.
*
* Copyright (c) 2009 Oracle. All rights reserved.
*
*/
using System;
using System.Collections.Generic;
using System.Text;
namespace BerkeleyDB {
///
/// A class representing configuration parameters for
///
public class DatabaseConfig {
///
/// The Berkeley DB environment within which to create a database. If
/// null, the database will be created stand-alone; that is, it is not
/// part of any Berkeley DB environment.
///
///
/// The database access methods automatically make calls to the other
/// subsystems in Berkeley DB, based on the enclosing environment. For
/// example, if the environment has been configured to use locking, the
/// access methods will automatically acquire the correct locks when
/// reading and writing pages of the database.
///
public DatabaseEnvironment Env;
///
/// The cache priority for pages referenced by the database.
///
///
/// The priority of a page biases the replacement algorithm to be more
/// or less likely to discard a page when space is needed in the buffer
/// pool. The bias is temporary, and pages will eventually be discarded
/// if they are not referenced again. This priority is only advisory,
/// and does not guarantee pages will be treated in a specific way.
///
public CachePriority Priority;
///
/// The size of the shared memory buffer pool -- that is, 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, that is, 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;
///
/// The byte order for integers in the stored database metadata. The
/// host byte order of the machine where the Berkeley DB library was
/// compiled is the default value.
///
///
///
/// The access methods provide no guarantees about the byte ordering of
/// the application data stored in the database, and applications are
/// responsible for maintaining any necessary ordering.
///
///
/// If creating additional databases in a single physical file, this
/// parameter will be ignored and the byte order of the existing
/// databases will be used.
///
///
public ByteOrder ByteOrder = ByteOrder.MACHINE;
internal bool pagesizeIsSet;
private uint pgsz;
///
/// The size of the pages used to hold items in the database, in bytes.
///
///
///
/// The minimum page size is 512 bytes, the maximum page size is 64K
/// bytes, and the page size must be a power-of-two. If the page size is
/// not explicitly set, one is selected based on the underlying
/// filesystem I/O block size. The automatically selected size has a
/// lower limit of 512 bytes and an upper limit of 16K bytes.
///
///
/// For information on tuning the Berkeley DB page size, see Selecting a
/// page size in the Programmer's Reference Guide.
///
///
/// If creating additional databases in a single physical file, this
/// parameter will be ignored and the page size of the existing
/// databases will be used.
///
///
public uint PageSize {
get { return pgsz; }
set {
pagesizeIsSet = true;
pgsz = value;
}
}
internal bool encryptionIsSet;
private String encryptPwd;
private EncryptionAlgorithm encryptAlg;
///
/// Set the password and algorithm used by the Berkeley DB library to
/// perform encryption and decryption.
///
///
/// The password used to perform encryption and decryption.
///
///
/// The algorithm used to perform encryption and decryption.
///
public void SetEncryption(String password, EncryptionAlgorithm alg) {
encryptionIsSet = true;
encryptPwd = password;
encryptAlg = alg;
}
///
/// The password used to perform encryption and decryption.
///
public string EncryptionPassword { get { return encryptPwd; } }
///
/// The algorithm used to perform encryption and decryption.
///
public EncryptionAlgorithm EncryptAlgorithm {
get { return encryptAlg; }
}
///
/// The prefix string that appears before error messages issued by
/// Berkeley DB.
///
public String ErrorPrefix;
///
/// The mechanism for reporting error messages to the application.
///
///
///
/// In some cases, when an error occurs, Berkeley DB will call
/// ErrorFeedback with additional error information. It is up to the
/// delegate function to display the error message in an appropriate
/// manner.
///
///
/// 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.
///
///
/// For databases opened inside of Berkeley DB environments, setting
/// ErrorFeedback affects the entire environment and is equivalent to
/// setting .
///
///
public ErrorFeedbackDelegate ErrorFeedback;
///
///
///
public DatabaseFeedbackDelegate Feedback;
///
/// If true, do checksum verification of pages read into the cache from
/// the backing filestore.
///
///
///
/// Berkeley DB uses the SHA1 Secure Hash Algorithm if encryption is
/// configured and a general hash algorithm if it is not.
///
///
/// If the database already exists, this setting will be ignored.
///
///
public bool DoChecksum;
///
/// If true, Berkeley DB will not write log records for this database.
///
///
/// If Berkeley DB does not write log records, updates of this database
/// will exhibit the ACI (atomicity, consistency, and isolation)
/// properties, but not D (durability); that is, database integrity will
/// be maintained, but if the application or system fails, integrity
/// will not persist. The database file must be verified and/or restored
/// from backup after a failure. In order to ensure integrity after
/// application shut down, the database must be synced when closed, or
/// all database changes must be flushed from the database environment
/// cache using either
/// or
/// . All database objects
/// for a single physical file must set NonDurableTxns, including
/// database objects for different databases in a physical file.
///
public bool NonDurableTxns;
internal uint flags {
get {
uint ret = 0;
ret |= DoChecksum ? Internal.DbConstants.DB_CHKSUM : 0;
ret |= encryptionIsSet ? Internal.DbConstants.DB_ENCRYPT : 0;
ret |= NonDurableTxns ? Internal.DbConstants.DB_TXN_NOT_DURABLE : 0;
return ret;
}
}
///
/// Enclose the open call within a transaction. If the call succeeds,
/// the open operation will be recoverable and all subsequent database
/// modification operations based on this handle will be transactionally
/// protected. If the call fails, no database will have been created.
///
public bool AutoCommit;
///
/// Cause the database object to be free-threaded; that is, concurrently
/// usable by multiple threads in the address space.
///
public bool FreeThreaded;
///
/// Do not map this database into process memory.
///
public bool NoMMap;
///
/// Open the database for reading only. Any attempt to modify items in
/// the database will fail, regardless of the actual permissions of any
/// underlying files.
///
public bool ReadOnly;
///
/// Support transactional read operations with degree 1 isolation.
///
///
/// Read operations on the database may request the return of modified
/// but not yet committed data. This flag must be specified on all
/// database objects used to perform dirty reads or database updates,
/// otherwise requests for dirty reads may not be honored and the read
/// may block.
///
public bool ReadUncommitted;
///
/// Physically truncate the underlying file, discarding all previous databases it might have held.
///
///
///
/// Underlying filesystem primitives are used to implement this flag.
/// For this reason, it is applicable only to the file and cannot be
/// used to discard databases within a file.
///
///
/// This setting cannot be lock or transaction-protected, and it is an
/// error to specify it in a locking or transaction-protected
/// environment.
///
///
public bool Truncate;
///
/// Open the database with support for multiversion concurrency control.
///
///
/// This will cause updates to the database to follow a copy-on-write
/// protocol, which is required to support snapshot isolation. This
/// settting requires that the database be transactionally protected
/// during its open and is not supported by the queue format.
///
public bool UseMVCC;
internal uint openFlags {
get {
uint ret = 0;
ret |= AutoCommit ? Internal.DbConstants.DB_AUTO_COMMIT : 0;
ret |= FreeThreaded ? Internal.DbConstants.DB_THREAD : 0;
ret |= NoMMap ? Internal.DbConstants.DB_NOMMAP : 0;
ret |= ReadOnly ? Internal.DbConstants.DB_RDONLY : 0;
ret |= ReadUncommitted ? Internal.DbConstants.DB_READ_UNCOMMITTED : 0;
ret |= Truncate ? Internal.DbConstants.DB_TRUNCATE : 0;
ret |= UseMVCC ? Internal.DbConstants.DB_MULTIVERSION : 0;
return ret;
}
}
///
/// Instantiate a new DatabaseConfig object
///
public DatabaseConfig() {
Env = null;
Priority = CachePriority.DEFAULT;
pagesizeIsSet = false;
encryptionIsSet = false;
ErrorPrefix = null;
Feedback = null;
DoChecksum = false;
NonDurableTxns = false;
AutoCommit = false;
FreeThreaded = false;
NoMMap = false;
ReadOnly = false;
ReadUncommitted = false;
Truncate = false;
UseMVCC = false;
}
}
}