2 Replies Latest reply on Jan 28, 2011 6:40 PM by 524722

    multiple processes accessing a replicated database


      I am after some help with multiple processes and replicated databases.

      I have a primary and secondary database replicated across a pair of servers and this seems to be working well. I'm trying to run another process on one of the machines that opens the environment and databases to view and/or modify the data.

      The problem is that when I run this process it causes some sort of corruption such that the server process on the same box gets a DB_EVENT_PANIC the next time it accesses the database. I would like to understand what I am doing wrong.

      The servers and standalone process all use the same code to open and close the environment and databases (see below). Just calling
      in the utility process causes DB_EVENT_PANIC in the server process.

      Can anybody spot what I am doing wrong? I am using DB Version 4.7


      open_env() {
      db_env_create(&dbenv, 0);
      dbenv->app_private = &my_app_data;
      dbenv->set_event_notify(dbenv, event_callback);
      dbenv->rep_set_limit(dbenv, 0, REPLIMIT);
      dbenv->set_flags(dbenv, DB_AUTO_COMMIT | DB_TXN_NOSYNC, 1);
      dbenv->set_lk_detect(dbenv, DB_LOCK_DEFAULT)
      int flags = DB_CREATE | DB_INIT_LOCK |
                DB_INIT_LOG | DB_INIT_MPOOL |
                DB_INIT_TXN | DB_RECOVER | DB_THREAD;

      flags |= DB_INIT_REP;
      dbenv->repmgr_set_local_site(dbenv, listen_host, port, 0);
      dbenv->rep_set_priority(dbenv, 100);
      dbenv->repmgr_set_ack_policy(dbenv, DB_REPMGR_ACKS_ONE);

      for (x = 0; x < num_peers; x++) {
      dbenv->repmgr_add_remote_site(dbenv, peers[x].name, peers[x].port, &peers[x].eid, 0);
      dbenv->rep_set_nsites(dbenv, num_peers + 1);
      dbenv->open(dbenv, ".", flags, S_IRUSR | S_IWUSR);
      dbenv->repmgr_start(dbenv, 3, DB_REP_ELECTION);

      close_env() {
      dbenv_p->txn_checkpoint(dbenv_p, 0, 0, 0);
      dbenv_p->close(dbenv_p, 0);

      open_databases() {
      db_create(&dbp, dbenv_p, 0)
      flags = 0;
      if (app_data->is_master)
      flags |= DB_CREATE;
      dbp->open(dbp, NULL, "primary", NULL, DB_HASH, flags, 0);
      ... Wait for db if slave and ENOENT ...
      primary = dbp;
      dbp->open(dbp, NULL, "secondary", NULL, DB_BTREE, flags, 0);
      ... Wait for db if slave and ENOENT
      secondary = dbp;
      while (app_data->client_sync) {

      close_databases() {
           secondary->close(secondary, 0);
           primary->close(primary, 0);
           dbenv_p->txn_checkpoint(dbenv_p, 0, 0, 0);