DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 

Configuring the Transaction Subsystem

Most of the configuration activities that you need to perform for your transactional JE application will involve the locking and logging subsystems. See Concurrency and Managing JE Files for details.

However, there are a couple of things that you can do to configure your transaction subsystem directly. These things are:

For example:

#include <stdio.h>
#include <stdlib.h>

#include "db.h"

int
main(void)
{
    int ret, ret_c;
    u_int32_t db_flags, env_flags;
    DB *dbp;
    DB_ENV *envp;
    DB_TXN *txn;
    const char *db_home_dir = "/tmp/myEnvironment";
    const char *file_name = "mydb.db";
    
    envp = NULL;

    /* Open the environment */
    ret = db_env_create(&envp, 0);
    if (ret != 0) {
        fprintf(stderr, "Error creating environment handle: %s\n",
            db_strerror(ret));
        return (EXIT_FAILURE);
    }
                                                                                                                                  
    env_flags = DB_CREATE     |  /* If the environment does not
                                  * exist, create it. */
                DB_INIT_LOCK  |  /* Initialize locking */
                DB_INIT_LOG   |  /* Initialize logging */
                DB_INIT_MPOOL |  /* Initialize the cache */
                DB_THREAD     |  /* Free-thread the env handle. */
                DB_INIT_TXN;     /* Initialize transactions */

    /*
     * Configure a maximum transaction timeout of 1 second.
     */
    ret = envp->set_timeout(envp, DB_SET_TXN_TIMEOUT, 1000000);
    if (ret != 0) {
        fprintf(stderr, "Error setting txn timeout: %s\n",
            db_strerror(ret));
        goto err;
    }

    /*
     * Configure 40 maximum transactions.
     */
    ret = envp->set_tx_max(envp, 40);
    if (ret != 0) {
        fprintf(stderr, "Error setting max txns: %s\n",
            db_strerror(ret));
        goto err;
    }

    ret = envp->open(envp, db_home_dir, env_flags, 0);
    if (ret != 0) {
        fprintf(stderr, "Error opening environment: %s\n",
            db_strerror(ret));
        goto err;
    }

    /* 
     * From here, you open your databases, proceed with your 
     * database operations, and respond to deadlocks as 
     * is normal (omitted for brevity).
     */
     ...