in src/qpid/linearstore/MessageStoreImpl.cpp [215:296]
void MessageStoreImpl::init(const bool truncateFlag)
{
const int retryMax = 3;
int bdbRetryCnt = 0;
do {
if (bdbRetryCnt++ > 0)
{
closeDbs();
::usleep(1000000); // 1 sec delay
QLS_LOG(error, "Previoius BDB store initialization failed, retrying (" << bdbRetryCnt << " of " << retryMax << ")...");
}
try {
qpid::linearstore::journal::jdir::create_dir(getBdbBaseDir());
dbenv.reset(new DbEnv(0));
dbenv->set_errpfx("linearstore");
dbenv->set_lg_regionmax(256000); // default = 65000
dbenv->open(getBdbBaseDir().c_str(), DB_THREAD | DB_CREATE | DB_INIT_TXN | DB_INIT_LOCK | DB_INIT_LOG | DB_INIT_MPOOL | DB_USE_ENVIRON | DB_RECOVER, 0);
// Databases are constructed here instead of the constructor so that the DB_RECOVER flag can be used
// against the database environment. Recover can only be performed if no databases have been created
// against the environment at the time of recovery, as recovery invalidates the environment.
queueDb.reset(new Db(dbenv.get(), 0));
dbs.push_back(queueDb);
configDb.reset(new Db(dbenv.get(), 0));
dbs.push_back(configDb);
exchangeDb.reset(new Db(dbenv.get(), 0));
dbs.push_back(exchangeDb);
mappingDb.reset(new Db(dbenv.get(), 0));
dbs.push_back(mappingDb);
bindingDb.reset(new Db(dbenv.get(), 0));
dbs.push_back(bindingDb);
generalDb.reset(new Db(dbenv.get(), 0));
dbs.push_back(generalDb);
TxnCtxt txn;
txn.begin(dbenv.get(), false);
try {
open(queueDb, txn.get(), "queues.db", false);
open(configDb, txn.get(), "config.db", false);
open(exchangeDb, txn.get(), "exchanges.db", false);
open(mappingDb, txn.get(), "mappings.db", true);
open(bindingDb, txn.get(), "bindings.db", true);
open(generalDb, txn.get(), "general.db", false);
txn.commit();
} catch (...) { txn.abort(); throw; }
// NOTE: during normal initialization, agent == 0 because the store is initialized before the management infrastructure.
// However during a truncated initialization in a cluster, agent != 0. We always pass 0 as the agent for the
// TplStore to keep things consistent in a cluster. See https://bugzilla.redhat.com/show_bug.cgi?id=681026
tplStorePtr.reset(new TplJournalImpl(broker->getTimer(), "TplStore", getTplBaseDir(), jrnlLog, defJournalGetEventsTimeoutNs, journalFlushTimeout, 0));
isInit = true;
} catch (const DbException& e) {
if (e.get_errno() == DB_VERSION_MISMATCH)
{
QLS_LOG(error, "Database environment mismatch: This version of db4 does not match that which created the store database.: " << e.what());
THROW_STORE_EXCEPTION_2("Database environment mismatch: This version of db4 does not match that which created the store database. "
"(If recovery is not important, delete the contents of the store directory. Otherwise, try upgrading the database using "
"db_upgrade or using db_recover - but the db4-utils package must also be installed to use these utilities.)", e);
}
QLS_LOG(error, "BDB exception occurred while initializing store: " << e.what());
if (bdbRetryCnt >= retryMax)
THROW_STORE_EXCEPTION_2("BDB exception occurred while initializing store", e);
} catch (const StoreException&) {
throw;
} catch (const qpid::linearstore::journal::jexception& e) {
QLS_LOG(error, "Journal Exception occurred while initializing store: " << e);
THROW_STORE_EXCEPTION_2("Journal Exception occurred while initializing store", e.what());
} catch (...) {
QLS_LOG(error, "Unknown exception occurred while initializing store.");
throw;
}
} while (!isInit);
efpMgr.reset(new qpid::linearstore::journal::EmptyFilePoolManager(getStoreTopLevelDir(),
defaultEfpPartitionNumber,
defaultEfpFileSize_kib,
overwriteBeforeReturnFlag,
truncateFlag,
jrnlLog));
efpMgr->findEfpPartitions();
}