Berkley DB non deterministic error occurrence when adding an encrypted database within environment

43 Views Asked by At

I'm trying to add new and first encrypted database within an environment which already contains several unencrypted databases.

the problem is that once in several attempts to update our software version (to the version that contains the new encrypted database creation), db->open returns error 22 and the following logs from BDB being printed:

enter image description here

Berkeley DB version that being used is 4.8.30

I followed those instructions https://docs.oracle.com/cd/E17076_05/html/programmer_reference/env_encrypt.html

I didn't created new environment, I used the already exist environment with the following configurations:

static STATUS sPR_create_env(const char *passwd, BOOL open_env)
{
STATUS ret=OK, err=OK;

if( db_env_passwd == NULL )
{
    asprintf(&db_env_passwd, "%s", passwd);
}

/* Create an environment object and initialize it */
ret = db_env_create(&dbenv, 0 );

dbenv->set_msgcall(dbenv, sPR_db_print_to_syslog);
dbenv->set_errcall(dbenv, sPR_db_err_print);

/*
* We want to specify the shared memory buffer pool cachesize
*/
ret = dbenv->set_cachesize(dbenv, 0, (4 * 1024 * 1024), 0);


/* Set databases prefix to data files. */
(void)dbenv->set_data_dir(dbenv, data_dir);

/* Set encrypt to environment for the supporting secure DB */
ret = dbenv->set_encrypt(dbenv, passwd, DB_ENCRYPT_AES);

ret = dbenv->set_tx_max(dbenv, MAX_NUM_OF_TRANSACTIONS);

ret = dbenv->set_lk_partitions(dbenv, 1); /* optimized for single CPU systems */

/* Set Log file auto-removal on */
ret = dbenv->log_set_config(dbenv, DB_LOG_AUTO_REMOVE, 1);

/* Set the maximum # of locks/lockers/lock-objects (should be at least 5*lock-partitions) */
ret = dbenv->set_lk_max_locks(dbenv, 4000);

ret = dbenv->set_lk_max_objects(dbenv, 4000);

ret = dbenv->set_lk_max_lockers(dbenv, 4000);

/* Reject lock request leading to deadlocks which have the least # of locks taken */
ret = dbenv->set_lk_detect(dbenv, DB_LOCK_MINWRITE);

ret = dbenv->set_lg_dir(dbenv, DB_LOG_FILE_PATH);

ret = dbenv->set_lg_max(dbenv, DB_LOG_FILE_SIZE);

if( open_env )
{
    /* open environment DB */
    ret = dbenv->open(dbenv, DB_home,
            DB_THREAD | DB_CREATE | DB_INIT_MPOOL | DB_PRIVATE |
            DB_INIT_TXN | DB_INIT_LOCK | DB_INIT_LOG | DB_RECOVER,
            0644);
}
exit:
if( err == ERROR )
{
    dbenv->close(dbenv, 0);
    dbenv=NULL;
}

return err;
}

the way of opening my new database is as follow:

/* set encryption */

ret = dbp->set_flags(dbp, DB_ENCRYPT);

/* Open a database with DB_BTREE access method.*/
ret = dbp->open(dbp,
                NULL,
                file_name,
                NULL,
                DB_BTREE,
                flags,
                0644);

all other databases being open like this:

/* Open a database with DB_BTREE access method.*/

ret = dbp->open(dbp,
                NULL,
                file_name,
                NULL,
                DB_BTREE,
                flags,
                0644);

what can be the reason for this error 22? can it be related to the mixing of encrypted together with unencrypted databases within the same environment? why sometimes the program runs properly and sometimes not? is there something wrong with the environment configurations? flags? thanks.

0

There are 0 best solutions below