NAME

Apache2::Translation::BDB - A provider for Apache2::Translation

SYNOPSIS

<TranslationProvider BDB>
    BDBEnv   /path/to/directory
    ReadOnly 1
</TranslationProvider>

or

$provider=Apache2::Translation::BDB->new(BDBEnv=>..., ...);

$provider->start;
$provider->stop;

DESCRIPTION

The BDB provider implements the Apache2::Translation provider interface as documented in Apache2::Translation::_base. It provides for all optional functions.

Other than the DB providers BDB doesn't implement a cache. BerkeleyDB is fast enough on its own. Neither does it monitor the timestamp of a file on disk. Hence it doesn't need a version or timestamp field.

Nevertheless it implements a timestamp method that can be used by external tools to synchronize the database state with external sources.

Parameters

bdbenv /path/to/directory

Here you can pass a directory name or a BerkeleyDB::Env object. In the latter case, the environment must be initialized with DB_INIT_MPOOL, DB_INIT_LOCK, DB_INIT_TXN and DB_INIT_LOG. Further, you need to specify a deadlock detection method.

If a directory is passed (the normal case) the provider initializes the environment if it is not already set up. It creates 3 databases, Apache2::Translation::BDB-id.db, Apache2::Translation::BDB-keyuri.db and Apache2::Translation::BDB-extra.db. Apache2::Translation::BDB-keyuri.db is used as an associated database for Apache2::Translation::BDB-id.db. That means it is a secondary index.

The extra database holds only the timestamp value. But the provider offers an extra method to store more information in this database.

See CONFIGFURATION below for performance tuning.

readonly 1

If set to true the databases are opened in readonly mode. Please note that the program needs write permission to the database files even if this flag is set.

Additional Methods

parent_txn

BerkeleyDB supports nested transactions. If you provide a parent transaction the provider wraps its changes in a child transaction. Otherwise it works in an unrelated transaction.

extra_db

returns the database handle of the extra database.

extra key value

stores and retrieves information from the extra database. If value is given it is written as value for the key to the database.

returns the previous value of the key.

Note, the key \ttmstmp is reserved.

timestamp time

sets or retrieves the timestamp from the extra database.

CONFIGURATION

A Berkeley database is configured and tuned via a config file named DB_CONFIG located in the environment directory. The default parameters are quite small for a WEB server application where many processes access the database in parallel.

To tune your database create an empty directory and within it a file named DB_CONFIG. Then start the WEB Server or a helper program to create and initialize the databases.

For me I found these values sufficient for a fairly large WEB Server:

set_lk_max_locks   5000
set_lk_max_lockers 5000
set_lk_max_objects 5000
set_tx_max         200
set_flags          DB_LOG_INMEMORY
set_lg_regionmax   1048576
set_lg_bsize       10485760

See http://www.oracle.com/technology/documentation/berkeley-db/db/ref/toc.html for further information.

SEE ALSO

Apache2::Translation
Apache2::Translation::DB
Apache2::Translation::File
Apache2::Translation::_base

AUTHOR

Torsten Foertsch, <torsten.foertsch@gmx.net>

COPYRIGHT AND LICENSE

Copyright (C) 2005-2008 by Torsten Foertsch

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.