2 * See the file LICENSE for redistribution information.
4 * Copyright (c) 2009, 2012 Oracle and/or its affiliates. All rights reserved.
8 using System.Collections.Generic;
10 using BerkeleyDB.Internal;
12 namespace BerkeleyDB {
14 /// A class representing configuration parameters for a
15 /// <see cref="DatabaseEnvironment"/>'s logging subsystem.
17 public class LogConfig {
19 /// If true, Berkeley DB will automatically remove log files that are no
24 /// Automatic log file removal is likely to make catastrophic recovery
28 /// Replication Manager applications operate in a group-aware manner for
29 /// log file removal, and automatic log file removal simplifies the
33 /// Replication Base API applications will rarely want to configure
34 /// automatic log file removal as it increases the likelihood a master
35 /// will be unable to satisfy a client's request for a recent log
39 public bool AutoRemove;
41 /// If true, Berkeley DB will flush log writes to the backing disk
42 /// before returning from the write system call, rather than flushing
43 /// log writes explicitly in a separate system call, as necessary.
47 /// This is only available on some systems (for example, systems
48 /// supporting the IEEE/ANSI Std 1003.1 (POSIX) standard O_DSYNC flag,
49 /// or systems supporting the Windows FILE_FLAG_WRITE_THROUGH flag).
50 /// This flag may result in inaccurate file modification times and other
51 /// file-level information for Berkeley DB log files. This flag may
52 /// offer a performance increase on some systems and a performance
53 /// decrease on others.
56 public bool ForceSync;
58 /// If true, maintain transaction logs in memory rather than on disk.
62 /// This means that transactions exhibit the ACI (atomicity,
63 /// consistency, and isolation) properties, but not D (durability); that
64 /// is, database integrity will be maintained, but if the application or
65 /// system fails, integrity will not persist. All database files must be
66 /// verified and/or restored from a replication group master or archival
67 /// backup after application or system failure.
70 /// When in-memory logs are configured and no more log buffer space is
71 /// available, Berkeley DB methods may throw
72 /// <see cref="FullLogBufferException"/>. When choosing log buffer and
73 /// file sizes for in-memory logs, applications should ensure the
74 /// in-memory log buffer size is large enough that no transaction will
75 /// ever span the entire buffer, and avoid a state where the in-memory
76 /// buffer is full and no space can be freed because a transaction that
77 /// started in the first log "file" is still active.
82 /// If true, turn off system buffering of Berkeley DB log files to avoid
87 /// If true, zero all pages of a log file when that log file is created.
91 /// This has shown to provide greater transaction throughput in some
92 /// environments. The log file will be zeroed by the thread which needs
93 /// to re-create the new log file. Other threads may not write to the
94 /// log file while this is happening.
97 public bool ZeroOnCreate;
99 internal uint ConfigFlags {
103 ret |= DbConstants.DB_LOG_AUTO_REMOVE;
105 ret |= DbConstants.DB_LOG_DSYNC;
107 ret |= DbConstants.DB_LOG_IN_MEMORY;
109 ret |= DbConstants.DB_LOG_DIRECT;
111 ret |= DbConstants.DB_LOG_ZERO;
116 internal bool bsizeIsSet;
119 /// The size of the in-memory log buffer, in bytes.
123 /// When the logging subsystem is configured for on-disk logging, the
124 /// default size of the in-memory log buffer is approximately 32KB. Log
125 /// information is stored in-memory until the storage space fills up or
126 /// transaction commit forces the information to be flushed to stable
127 /// storage. In the presence of long-running transactions or
128 /// transactions producing large amounts of data, larger buffer sizes
129 /// can increase throughput.
132 /// When the logging subsystem is configured for in-memory logging, the
133 /// default size of the in-memory log buffer is 1MB. Log information is
134 /// stored in-memory until the storage space fills up or transaction
135 /// abort or commit frees up the memory for new transactions. In the
136 /// presence of long-running transactions or transactions producing
137 /// large amounts of data, the buffer size must be sufficient to hold
138 /// all log information that can accumulate during the longest running
139 /// transaction. When choosing log buffer and file sizes for in-memory
140 /// logs, applications should ensure the in-memory log buffer size is
141 /// large enough that no transaction will ever span the entire buffer,
142 /// and avoid a state where the in-memory buffer is full and no space
143 /// can be freed because a transaction that started in the first log
144 /// "file" is still active.
147 /// If the database environment already exists when
148 /// <see cref="DatabaseEnvironment.Open"/> is called, the value of
149 /// BufferSize will be ignored.
152 public uint BufferSize {
153 get { return _bsize; }
161 /// The path of a directory to be used as the location of logging files.
162 /// Log files created by the Log Manager subsystem will be created in
167 /// If no logging directory is specified, log files are created in the
168 /// environment home directory. See Berkeley DB File Naming in the
169 /// Programmer's Reference Guide for more information.
172 /// For the greatest degree of recoverability from system or application
173 /// failure, database files and log files should be located on separate
174 /// physical devices.
177 /// If the database environment already exists when
178 /// <see cref="DatabaseEnvironment.Open"/> is called, the value of
179 /// Dir must be consistent with the existing environment or corruption
185 private uint _initlogidcount;
186 internal bool initLogIdCountIsSet;
188 /// The initial number of log identifier entities created by the
189 /// Berkeley DB environment
193 /// This value is used by <see cref="DatabaseEnvironment.Open"/> to
194 /// force Berkeley DB to allocate a certain number of log identifier
195 /// objects when the environment is created. This can be useful if an
196 /// application uses a large number of log identifier objects, and
197 /// experiences performance issues with the default dynamic allocation
201 /// If the database environment already exists when
202 /// <see cref="DatabaseEnvironment.Open"/> is called, the value of
203 /// InitLogIds will be ignored.
206 public uint InitLogIdCount {
207 get { return _initlogidcount; }
209 initLogIdCountIsSet = true;
210 _initlogidcount = value;
214 internal bool modeIsSet;
217 /// The absolute file mode for created log files.
221 /// This method is only useful for the rare Berkeley DB application that
222 /// does not control its umask value.
225 /// Normally, if Berkeley DB applications set their umask appropriately,
226 /// all processes in the application suite will have read permission on
227 /// the log files created by any process in the application suite.
228 /// However, if the Berkeley DB application is a library, a process
229 /// using the library might set its umask to a value preventing other
230 /// processes in the application suite from reading the log files it
231 /// creates. In this rare case, the DB_ENV->set_lg_filemode() method can
232 /// be used to set the mode of created log files to an absolute value.
235 public int FileMode {
236 get { return _mode; }
243 internal bool maxSizeIsSet;
244 private uint _maxSize;
246 /// The maximum size of a single file in the log, in bytes. Because
247 /// <see cref="LSN.Offset"/> is an unsigned four-byte value, MaxFileSize
248 /// may not be larger than the maximum unsigned four-byte value.
252 /// When the logging subsystem is configured for on-disk logging, the
253 /// default size of a log file is 10MB.
256 /// When the logging subsystem is configured for in-memory logging, the
257 /// default size of a log file is 256KB. In addition, the
258 /// <see cref="BufferSize">configured log buffer size</see> must be
259 /// larger than the log file size. (The logging subsystem divides memory
260 /// configured for in-memory log records into "files", as database
261 /// environments configured for in-memory log records may exchange log
262 /// records with other members of a replication group, and those members
263 /// may be configured to store log records on-disk.) When choosing log
264 /// buffer and file sizes for in-memory logs, applications should ensure
265 /// the in-memory log buffer size is large enough that no transaction
266 /// will ever span the entire buffer, and avoid a state where the
267 /// in-memory buffer is full and no space can be freed because a
268 /// transaction that started in the first log "file" is still active.
271 /// See Log File Limits in the Programmer's Reference Guide for more
275 /// If no size is specified by the application, the size last specified
276 /// for the database region will be used, or if no database region
277 /// previously existed, the default will be used.
278 /// </para></remarks>
279 public uint MaxFileSize {
280 get { return _maxSize; }
287 internal bool regionSizeIsSet;
288 private uint _regionSize;
290 /// Te size of the underlying logging area of the Berkeley DB
291 /// environment, in bytes.
295 /// By default, or if the value is set to 0, the default size is
296 /// approximately 60KB. The log region is used to store filenames, and
297 /// so may need to be increased in size if a large number of files will
298 /// be opened and registered with the specified Berkeley DB
299 /// environment's log manager.
302 /// If the database environment already exists when
303 /// <see cref="DatabaseEnvironment.Open"/> is called, the value of
304 /// RegionSize will be ignored.
307 public uint RegionSize {
308 get { return _regionSize; }
310 regionSizeIsSet = true;