Remember the following things as you use Berkeley DB Database and Environment handles with dbstl:

    • If you share environment or database handles among multiple threads, remember to specify the flag in the open call to the handle.

    • If you create or open environment and/or database handles without using the dbstl helper functions, or dbstl::open_env(), remember that your environment and database handles should be:

      1. Created using the DB_CXX_NO_EXCEPTIONS flag.

      2. In each thread sharing the handles, the handles are registered using either dbstl::register_db() or dbstl::register_dbenv().

    Some Berkeley DB operations require there to be no open cursors on the database handle at the time the operation occurs. Dbstl is aware of these requirements, and will attempt to close the cursors opened in the current thread when it performs these operations. However, the scope of dbstl’s activities in this regard are limited to the current thread; it makes no attempt to close cursors opened in other threads. So you are required to ensure there are no open cursors on database handles shared across threads when operations are performed that require all cursors on that handle to be closed.

    There are only a a few operations which require all open cursors to be closed. This include all container clear() and swap() functions, and all versions of db_vection<>::assign() functions. These functions require all cursors to be closed for the database because by default they remove all key/data pairs from the database by truncating it.

    When a function removes all key/data pairs from a database, there are two ways it can perform this activity:

    • Alternatively, you can specify that the database not be truncated. Instead, you can cause dbstl to delete all key/data pairs individually, one after another. In this situation, open cursors in the database will not cause the delete operations to fail. However, due to lock contention, the delete operations might not complete until all cursors are closed, which is when all their read locks are released.

    Dbstl supports auto commit for some of its container’s operations. When a dbstl container is created using a Db or object, if that object was opened using the flag, then every operation subsequently performed on that object will be automatically enclosed in a unique transaction (unless the operation is already in an external transaction). This is identical to how the Berkeley DB C, C++ and Java APIs behave.

    The dbstl API documentation identifies when a method supports auto commit transactions.

    When a container member function involves another container (for example, db_vector::swap(self& v2)), the two containers involved in the operation must not use the same database. Further, if the function is in an external or internal transaction context, then both containers must belong to the same transactional database environment; Otherwise, the two containers can belong to the same database environment, or two different ones.

    For example, if db_vector::swap(self& v2) is an auto commit method or it is in an external transaction context, then v2 must be in the same transactional database environment as this container, because a transaction is started internally that must be used by both v2 and this container. If this container and the v2 container have different database environments, and either of them are using transactions, an exception is thrown. This condition is checked in every such member function.

    However, if the function is not in a transactional context, then the databases used by these containers can be in different environments because in this situation dbstl makes no attempt to wrap container operations in a common transaction context.

    You can use dbstl with all Berkeley DB products (DS, CDS, TDS, and HA). Because dbstl is a Berkeley DB interface, all necessary configurations for these products are performed using Berkeley DB’s standard create/open/set APIs.

    As a result, the dbstl container constructors differ from those of C++ STL because in dbstl no configuration is supported using the container constructors. On the other hand, dbstl container constructors accept already opened and configured environment and database handles. They also provide functions to retrieve some handle configuration, such as key comparison and hash functions, as required by the C++ STL specifications.

    If a container constructor is not passed a database or environment handle, an internal anonymous database is created for you by dbstl. This anonymous database does not provide data persistence.