|
|
@ -42,6 +42,7 @@ void CDBEnv::EnvShutdown() |
|
|
|
{ |
|
|
|
{ |
|
|
|
printf("EnvShutdown exception: %s (%d)\n", e.what(), e.get_errno()); |
|
|
|
printf("EnvShutdown exception: %s (%d)\n", e.what(), e.get_errno()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (!fMockDb) |
|
|
|
DbEnv(0).remove(GetDataDir().string().c_str(), 0); |
|
|
|
DbEnv(0).remove(GetDataDir().string().c_str(), 0); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -103,12 +104,48 @@ bool CDBEnv::Open(boost::filesystem::path pathEnv_) |
|
|
|
return error("CDB() : error %d opening database environment", ret); |
|
|
|
return error("CDB() : error %d opening database environment", ret); |
|
|
|
|
|
|
|
|
|
|
|
fDbEnvInit = true; |
|
|
|
fDbEnvInit = true; |
|
|
|
|
|
|
|
fMockDb = false; |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void CDBEnv::MakeMock() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (fDbEnvInit) |
|
|
|
|
|
|
|
throw runtime_error("CDBEnv::MakeMock(): already initialized"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (fShutdown) |
|
|
|
|
|
|
|
throw runtime_error("CDBEnv::MakeMock(): during shutdown"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
printf("CDBEnv::MakeMock()\n"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
dbenv.set_cachesize(1, 0, 1); |
|
|
|
|
|
|
|
dbenv.set_lg_bsize(10485760*4); |
|
|
|
|
|
|
|
dbenv.set_lg_max(10485760); |
|
|
|
|
|
|
|
dbenv.set_lk_max_locks(10000); |
|
|
|
|
|
|
|
dbenv.set_lk_max_objects(10000); |
|
|
|
|
|
|
|
dbenv.set_flags(DB_AUTO_COMMIT, 1); |
|
|
|
|
|
|
|
dbenv.log_set_config(DB_LOG_IN_MEMORY, 1); |
|
|
|
|
|
|
|
int ret = dbenv.open(NULL, |
|
|
|
|
|
|
|
DB_CREATE | |
|
|
|
|
|
|
|
DB_INIT_LOCK | |
|
|
|
|
|
|
|
DB_INIT_LOG | |
|
|
|
|
|
|
|
DB_INIT_MPOOL | |
|
|
|
|
|
|
|
DB_INIT_TXN | |
|
|
|
|
|
|
|
DB_THREAD | |
|
|
|
|
|
|
|
DB_PRIVATE, |
|
|
|
|
|
|
|
S_IRUSR | S_IWUSR); |
|
|
|
|
|
|
|
if (ret > 0) |
|
|
|
|
|
|
|
throw runtime_error(strprintf("CDBEnv::MakeMock(): error %d opening database environment", ret)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fDbEnvInit = true; |
|
|
|
|
|
|
|
fMockDb = true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void CDBEnv::CheckpointLSN(std::string strFile) |
|
|
|
void CDBEnv::CheckpointLSN(std::string strFile) |
|
|
|
{ |
|
|
|
{ |
|
|
|
dbenv.txn_checkpoint(0, 0, 0); |
|
|
|
dbenv.txn_checkpoint(0, 0, 0); |
|
|
|
|
|
|
|
if (fMockDb) |
|
|
|
|
|
|
|
return; |
|
|
|
dbenv.lsn_reset(strFile.c_str(), 0); |
|
|
|
dbenv.lsn_reset(strFile.c_str(), 0); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -138,8 +175,17 @@ CDB::CDB(const char *pszFile, const char* pszMode) : |
|
|
|
{ |
|
|
|
{ |
|
|
|
pdb = new Db(&bitdb.dbenv, 0); |
|
|
|
pdb = new Db(&bitdb.dbenv, 0); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool fMockDb = bitdb.IsMock(); |
|
|
|
|
|
|
|
if (fMockDb) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
DbMpoolFile*mpf = pdb->get_mpf(); |
|
|
|
|
|
|
|
ret = mpf->set_flags(DB_MPOOL_NOFILE, 1); |
|
|
|
|
|
|
|
if (ret != 0) |
|
|
|
|
|
|
|
throw runtime_error(strprintf("CDB() : failed to configure for no temp file backing for database %s", pszFile)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
ret = pdb->open(NULL, // Txn pointer
|
|
|
|
ret = pdb->open(NULL, // Txn pointer
|
|
|
|
pszFile, // Filename
|
|
|
|
fMockDb ? NULL : pszFile, // Filename
|
|
|
|
"main", // Logical db name
|
|
|
|
"main", // Logical db name
|
|
|
|
DB_BTREE, // Database type
|
|
|
|
DB_BTREE, // Database type
|
|
|
|
nFlags, // Flags
|
|
|
|
nFlags, // Flags
|
|
|
@ -337,6 +383,7 @@ void CDBEnv::Flush(bool fShutdown) |
|
|
|
dbenv.txn_checkpoint(0, 0, 0); |
|
|
|
dbenv.txn_checkpoint(0, 0, 0); |
|
|
|
if (!IsChainFile(strFile) || fDetachDB) { |
|
|
|
if (!IsChainFile(strFile) || fDetachDB) { |
|
|
|
printf("%s detach\n", strFile.c_str()); |
|
|
|
printf("%s detach\n", strFile.c_str()); |
|
|
|
|
|
|
|
if (!fMockDb) |
|
|
|
dbenv.lsn_reset(strFile.c_str(), 0); |
|
|
|
dbenv.lsn_reset(strFile.c_str(), 0); |
|
|
|
} |
|
|
|
} |
|
|
|
printf("%s closed\n", strFile.c_str()); |
|
|
|
printf("%s closed\n", strFile.c_str()); |
|
|
|