Skip to content

Commit f7257cf

Browse files
author
Philip Kaufmann
committed
unified and better log/error messages for CDBEnv/CDB
1 parent d8dcfb9 commit f7257cf

File tree

1 file changed

+22
-23
lines changed

1 file changed

+22
-23
lines changed

src/db.cpp

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ void CDBEnv::EnvShutdown()
4242
fDbEnvInit = false;
4343
int ret = dbenv.close(0);
4444
if (ret != 0)
45-
LogPrintf("EnvShutdown exception: %s (%d)\n", DbEnv::strerror(ret), ret);
45+
LogPrintf("CDBEnv::EnvShutdown : Error %d shutting down database environment: %s\n", ret, DbEnv::strerror(ret));
4646
if (!fMockDb)
4747
DbEnv(0).remove(path.string().c_str(), 0);
4848
}
@@ -74,7 +74,7 @@ bool CDBEnv::Open(const boost::filesystem::path& pathIn)
7474
filesystem::path pathLogDir = path / "database";
7575
TryCreateDirectory(pathLogDir);
7676
filesystem::path pathErrorFile = path / "db.log";
77-
LogPrintf("dbenv.open LogDir=%s ErrorFile=%s\n", pathLogDir.string(), pathErrorFile.string());
77+
LogPrintf("CDBEnv::Open : LogDir=%s ErrorFile=%s\n", pathLogDir.string(), pathErrorFile.string());
7878

7979
unsigned int nEnvFlags = 0;
8080
if (GetBoolArg("-privdb", true))
@@ -101,7 +101,7 @@ bool CDBEnv::Open(const boost::filesystem::path& pathIn)
101101
nEnvFlags,
102102
S_IRUSR | S_IWUSR);
103103
if (ret != 0)
104-
return error("CDB() : error %s (%d) opening database environment", DbEnv::strerror(ret), ret);
104+
return error("CDBEnv::Open : Error %d opening database environment: %s\n", ret, DbEnv::strerror(ret));
105105

106106
fDbEnvInit = true;
107107
fMockDb = false;
@@ -111,11 +111,11 @@ bool CDBEnv::Open(const boost::filesystem::path& pathIn)
111111
void CDBEnv::MakeMock()
112112
{
113113
if (fDbEnvInit)
114-
throw runtime_error("CDBEnv::MakeMock(): already initialized");
114+
throw runtime_error("CDBEnv::MakeMock : Already initialized");
115115

116116
boost::this_thread::interruption_point();
117117

118-
LogPrint("db", "CDBEnv::MakeMock()\n");
118+
LogPrint("db", "CDBEnv::MakeMock\n");
119119

120120
dbenv.set_cachesize(1, 0, 1);
121121
dbenv.set_lg_bsize(10485760*4);
@@ -134,7 +134,7 @@ void CDBEnv::MakeMock()
134134
DB_PRIVATE,
135135
S_IRUSR | S_IWUSR);
136136
if (ret > 0)
137-
throw runtime_error(strprintf("CDBEnv::MakeMock(): error %d opening database environment", ret));
137+
throw runtime_error(strprintf("CDBEnv::MakeMock : Error %d opening database environment.", ret));
138138

139139
fDbEnvInit = true;
140140
fMockDb = true;
@@ -172,16 +172,16 @@ bool CDBEnv::Salvage(std::string strFile, bool fAggressive,
172172
int result = db.verify(strFile.c_str(), NULL, &strDump, flags);
173173
if (result == DB_VERIFY_BAD)
174174
{
175-
LogPrintf("Error: Salvage found errors, all data may not be recoverable.\n");
175+
LogPrintf("CDBEnv::Salvage : Database salvage found errors, all data may not be recoverable.\n");
176176
if (!fAggressive)
177177
{
178-
LogPrintf("Error: Rerun with aggressive mode to ignore errors and continue.\n");
178+
LogPrintf("CDBEnv::Salvage : Rerun with aggressive mode to ignore errors and continue.\n");
179179
return false;
180180
}
181181
}
182182
if (result != 0 && result != DB_VERIFY_BAD)
183183
{
184-
LogPrintf("ERROR: db salvage failed: %d\n",result);
184+
LogPrintf("CDBEnv::Salvage : Database salvage failed with result %d.\n", result);
185185
return false;
186186
}
187187

@@ -237,7 +237,7 @@ CDB::CDB(const char *pszFile, const char* pszMode) :
237237
{
238238
LOCK(bitdb.cs_db);
239239
if (!bitdb.Open(GetDataDir()))
240-
throw runtime_error("env open failed");
240+
throw runtime_error("CDB : Failed to open database environment.");
241241

242242
strFile = pszFile;
243243
++bitdb.mapFileUseCount[strFile];
@@ -252,7 +252,7 @@ CDB::CDB(const char *pszFile, const char* pszMode) :
252252
DbMpoolFile*mpf = pdb->get_mpf();
253253
ret = mpf->set_flags(DB_MPOOL_NOFILE, 1);
254254
if (ret != 0)
255-
throw runtime_error(strprintf("CDB() : failed to configure for no temp file backing for database %s", pszFile));
255+
throw runtime_error(strprintf("CDB : Failed to configure for no temp file backing for database %s", pszFile));
256256
}
257257

258258
ret = pdb->open(NULL, // Txn pointer
@@ -268,7 +268,7 @@ CDB::CDB(const char *pszFile, const char* pszMode) :
268268
pdb = NULL;
269269
--bitdb.mapFileUseCount[strFile];
270270
strFile = "";
271-
throw runtime_error(strprintf("CDB() : can't open database file %s, error %d", pszFile, ret));
271+
throw runtime_error(strprintf("CDB : Error %d, can't open database %s", ret, pszFile));
272272
}
273273

274274
if (fCreate && !Exists(string("version")))
@@ -352,7 +352,7 @@ bool CDB::Rewrite(const string& strFile, const char* pszSkip)
352352
bitdb.mapFileUseCount.erase(strFile);
353353

354354
bool fSuccess = true;
355-
LogPrintf("Rewriting %s...\n", strFile);
355+
LogPrintf("CDB::Rewrite : Rewriting %s...\n", strFile);
356356
string strFileRes = strFile + ".rewrite";
357357
{ // surround usage of db with extra {}
358358
CDB db(strFile.c_str(), "r");
@@ -366,7 +366,7 @@ bool CDB::Rewrite(const string& strFile, const char* pszSkip)
366366
0);
367367
if (ret > 0)
368368
{
369-
LogPrintf("Cannot create database file %s\n", strFileRes);
369+
LogPrintf("CDB::Rewrite : Can't create database file %s\n", strFileRes);
370370
fSuccess = false;
371371
}
372372

@@ -422,7 +422,7 @@ bool CDB::Rewrite(const string& strFile, const char* pszSkip)
422422
fSuccess = false;
423423
}
424424
if (!fSuccess)
425-
LogPrintf("Rewriting of %s FAILED!\n", strFileRes);
425+
LogPrintf("CDB::Rewrite : Failed to rewrite database file %s\n", strFileRes);
426426
return fSuccess;
427427
}
428428
}
@@ -435,9 +435,8 @@ bool CDB::Rewrite(const string& strFile, const char* pszSkip)
435435
void CDBEnv::Flush(bool fShutdown)
436436
{
437437
int64_t nStart = GetTimeMillis();
438-
// Flush log data to the actual data file
439-
// on all files that are not in use
440-
LogPrint("db", "Flush(%s)%s\n", fShutdown ? "true" : "false", fDbEnvInit ? "" : " db not started");
438+
// Flush log data to the actual data file on all files that are not in use
439+
LogPrint("db", "CDBEnv::Flush : Flush(%s)%s\n", fShutdown ? "true" : "false", fDbEnvInit ? "" : " database not started");
441440
if (!fDbEnvInit)
442441
return;
443442
{
@@ -447,23 +446,23 @@ void CDBEnv::Flush(bool fShutdown)
447446
{
448447
string strFile = (*mi).first;
449448
int nRefCount = (*mi).second;
450-
LogPrint("db", "%s refcount=%d\n", strFile, nRefCount);
449+
LogPrint("db", "CDBEnv::Flush : Flushing %s (refcount = %d)...\n", strFile, nRefCount);
451450
if (nRefCount == 0)
452451
{
453452
// Move log data to the dat file
454453
CloseDb(strFile);
455-
LogPrint("db", "%s checkpoint\n", strFile);
454+
LogPrint("db", "CDBEnv::Flush : %s checkpoint\n", strFile);
456455
dbenv.txn_checkpoint(0, 0, 0);
457-
LogPrint("db", "%s detach\n", strFile);
456+
LogPrint("db", "CDBEnv::Flush : %s detach\n", strFile);
458457
if (!fMockDb)
459458
dbenv.lsn_reset(strFile.c_str(), 0);
460-
LogPrint("db", "%s closed\n", strFile);
459+
LogPrint("db", "CDBEnv::Flush : %s closed\n", strFile);
461460
mapFileUseCount.erase(mi++);
462461
}
463462
else
464463
mi++;
465464
}
466-
LogPrint("db", "DBFlush(%s)%s ended %15dms\n", fShutdown ? "true" : "false", fDbEnvInit ? "" : " db not started", GetTimeMillis() - nStart);
465+
LogPrint("db", "CDBEnv::Flush : Flush(%s)%s took %15dms\n", fShutdown ? "true" : "false", fDbEnvInit ? "" : " database not started", GetTimeMillis() - nStart);
467466
if (fShutdown)
468467
{
469468
char** listp;

0 commit comments

Comments
 (0)