|
|
DbEnv::open |
#include <db_cxx.h>int DbEnv::open(const char *db_home, u_int32_t flags, int mode);
int DbEnv::get_home(const char **homep);
int DbEnv::get_open_flags(u_int32_t *flagsp);
The DbEnv::open method opens a Berkeley DB environment. It provides a structure for creating a consistent environment for processes using one or more of the features of Berkeley DB.
The DbEnv::open method either returns a non-zero error value or throws an exception that encapsulates a non-zero error value on failure, and returns 0 on success. If DbEnv::open fails, the DbEnv::close method should be called to discard the DbEnv handle.
On Windows, the db_home argument will be interpreted as a UTF-8 string, which is equivalent to ASCII for Latin characters.
Because there are a large number of flags that can be specified, they have been grouped together by functionality. The first group of flags indicates which of the Berkeley DB subsystems should be initialized.
The choice of subsystems initialized for a Berkeley DB database environment is specified by the thread of control initially creating the environment. Any subsequent thread of control joining the environment will automatically be configured to use the same subsystems as were created in the environment (unless the thread of control requests a subsystem not available in the environment, which will fail). Applications joining an environment, able to adapt to whatever subsystems have been configured in the environment, should open the environment without specifying any subsystem flags. Applications joining an environment, requiring specific subsystems from their environments, should open the environment specifying those specific subsystem flags.
The second group of flags govern what recovery, if any, is performed when the environment is initialized:
A standard part of the recovery process is to remove the existing Berkeley DB environment and create a new one in which to perform recovery. If the thread of control performing recovery does not specify the correct region initialization information (for example, the correct memory pool cache size), the result can be an application running in an environment with incorrect cache and other subsystem sizes. For this reason, the thread of control performing recovery should specify correct configuration information before calling the DbEnv::open method; or it should remove the environment after recovery is completed, leaving creation of the correctly sized environment to a subsequent call to DbEnv::open.
All Berkeley DB recovery processing must be single-threaded; that is, only a single thread of control may perform recovery or access a Berkeley DB environment while recovery is being performed. Because it is not an error to specify DB_RECOVER for an environment for which no recovery is required, it is reasonable programming practice for the thread of control responsible for performing recovery and creating the environment to always specify the DB_CREATE and DB_RECOVER flags during startup.
The DbEnv::open function returns successfully if DB_RECOVER or DB_RECOVER_FATAL is specified and no log files exist, so it is necessary to ensure that all necessary log files are present before running recovery. For further information, consult db_archive and db_recover.
The third group of flags govern file-naming extensions in the environment:
Finally, there are a few additional unrelated flags:
This flag implies the environment will only be accessed by a single process (although that process may be multithreaded). This flag has two effects on the Berkeley DB environment. First, all underlying data structures are allocated from per-process memory instead of from shared memory that is accessible to more than a single process. Second, mutexes are only configured to work between threads.
This flag should not be specified if more than a single process is accessing the environment because it is likely to cause database corruption and unpredictable behavior. For example, if both a server application and Berkeley DB utilities (for example, db_archive, db_checkpoint or db_stat) are expected to access the environment, the DB_PRIVATE flag should not be specified.
See Shared Memory Regions for more information.
See Shared Memory Regions for more information.
On UNIX systems or in IEEE/ANSI Std 1003.1 (POSIX) environments, files created by Berkeley DB are created with mode mode (as described in chmod(2)) and modified by the process' umask value at the time of creation (see umask(2)). Created files are owned by the process owner; the group ownership of created files is based on the system and directory defaults, and is not further specified by Berkeley DB. System shared memory segments created by Berkeley DB are created with mode mode, unmodified by the process' umask value. If mode is 0, Berkeley DB will use a default mode of readable and writable by both owner and group.
The DbEnv::open method may fail and throw DbException, encapsulating one of the following non-zero errors, or return one of the following non-zero errors:
The DbEnv::get_home method returns the database environment home directory.
The DbEnv::get_home method may be called at any time during the life of the application.
The DbEnv::get_open_flags method returns the open method flags.
The DbEnv::get_open_flags method may not be called before the DbEnv::open method has been called.
The DbEnv::get_open_flags method either returns a non-zero error value or throws an exception that encapsulates a non-zero error value on failure, and returns 0 on success.
Copyright (c) 1996-2005 Sleepycat Software, Inc. - All rights reserved.