0

I have the following program which creates a Berkeley DB environment.

#include <db.h>
#include <stdio.h>

int main()
{
DB_ENV *env=NULL;
DB* m_db=NULL;

if(db_env_create(&env,0)==-1) printf("fail create\n");
env->set_lk_max_locks(env, 100000);
env->set_lk_max_lockers(env, 100000);
env->set_lk_max_objects(env, 100000);

if(env->open(env,"/tmp/cc", DB_INIT_MPOOL | DB_INIT_CDB, 0)!=0) 
{
    printf("No env, creating one\n");
    if(env->open(env, "/tmp/cc", DB_CREATE | DB_INIT_MPOOL | DB_INIT_CDB, 0) == -1)
        printf("Failed creating env\n");
}

env->close(env,0);  

return 0;
}

If you delete the /tmp/cc/__db.002 file (which is one of the indexes Berkeley DB creates), and re-run the program, it will get a SIGBUS when opening the environment (tries to map a non-existent file). Is there any way to avoid this using their API or is this a bug?

florinp
  • 329
  • 2
  • 5
  • 13

1 Answers1

0

florinp, I think this is Berkeley DB's bug. It really should be checking that the files in the environment are all intact before moving ahead.

Of course, there's not much you can do about a CDP database that's been trashed like this, other than delete it and start over. If this is a common failure type you have to deal with, you could wrap your program with a shell script that looks for exit status 135, then roasts the old database and restarts the program... but that could be risky depending on your application.

You could also move to a transactional data store. That'd give you more recovery options, and probably fewer SIGBUSes. :)

Mike Andrews
  • 3,045
  • 18
  • 28