Subject: | request for enhancements to version 0.26 |
In building my BerkeleyDB application, I have made a few enhancements to the BerkeleyDB Perl module. Perhaps you would consider adding them to the standard package? It would be great for me and perhaps useful for others as well.
Thanks,
Mike
* Support for the panic callback.
This is useful in detecting when the environment might need recovery. In the patch, setting the callback is done with an argument to the new method of the BerkeleyDB::Env package. Then in the XS file when the environment is opened, the callback is stored in the BerkeleyDB_ENV_type data structure and the BerkeleyDB API DB_ENV->set_paniccall is called to register the new function env_paniccall as the panic callback. Also, in the environment's app_private variable (provided by the BerekeleyDB API to store application-specific data along with it's data structure) is stored a pointer to the Perl BerkeleyDB environment object. So on a database panic, env_paniccall is called. It pushes a pointer to the Perl BerkeleyDB environment object (from the app_private variable) and the error value on to the stack. It then calls the registered Perl callback.
To use the callback feature then, you first open the environment someway like this:
$dbEnv = BerkeleyDB::Env->new (
...
-PanicCall => \&panicCall
);
where panicCall is defined perhaps like this:
sub panicCall
{
my $dbEnv = shift;
my $errVal = shift;
my $envSettings = $dbEnv->get_settings ( );
my $dbEnvPath = $envSettings->{ home };
my $dbLock = synchronizeDB ( undef, $dbEnvPath ); # One process at a time.
setRecoveryFlag ( $dbEnvPath, $dbInRecovery ? 2 : 1 );
synchronizeDB ( $dbLock, $dbEnvPath ) if $dbLock;
exit ( 1 );
}
* New method to get the settings of an environment.
When dealing with multiple environments at once, it is necessary to have a way to differentiate one from another via an environment pointer. For example, in the panicCall callback in the example above, it is necessary to be able to retrieve some settings about the environment in order to know in which one the database panic occurred. To support that there is a new method defined in the BerkeleyDB::Env package in BerkeleyDB.xs called get_settings. It returns a hash reference with the home path of the environment (with key "home") and the flags (with key "flags") used when opening the environment. To support this method there is a new helper function call hv_store_pv. (This function is really just the BerkeleyDB APIs DB_ENV->get_home and DB_ENV->get_open_flags rolled up into one. In hindsight, I would have simply added these two methods rather than inventing this new one.)
* Support for setting environment and transaction timeouts.
To avoid deadlocks from tying up the system, it is useful to have the DB_ENV->set_timeout and DB_TXN->set_timeout APIs. Two new methods were added to the BerkeleyDB::Env package in BerkeleyDB.xs to support this.
* Support ability to remove an environment.
To be able to delete an environment, it is useful to have the DB_ENV->remove API. A new method was added to the BerkeleyDB::Env package in BerkeleyDB.xs to support this.
Message body not shown because it is not plain text.