@@ -32,12 +32,12 @@ void CheckUniqueFileid(const BerkeleyEnvironment& env, const std::string& filena
32
32
33
33
int ret = db.get_mpf ()->get_fileid (fileid.value );
34
34
if (ret != 0 ) {
35
- throw std::runtime_error (strprintf (" BerkeleyBatch : Can't open database %s (get_fileid failed with %d)" , filename, ret));
35
+ throw std::runtime_error (strprintf (" BerkeleyDatabase : Can't open database %s (get_fileid failed with %d)" , filename, ret));
36
36
}
37
37
38
38
for (const auto & item : env.m_fileids ) {
39
39
if (fileid == item.second && &fileid != &item.second ) {
40
- throw std::runtime_error (strprintf (" BerkeleyBatch : Can't open database %s (duplicates fileid %s from %s)" , filename,
40
+ throw std::runtime_error (strprintf (" BerkeleyDatabase : Can't open database %s (duplicates fileid %s from %s)" , filename,
41
41
HexStr (std::begin (item.second .value ), std::end (item.second .value )), item.first ));
42
42
}
43
43
}
@@ -309,6 +309,8 @@ BerkeleyDatabase::~BerkeleyDatabase()
309
309
{
310
310
if (env) {
311
311
LOCK (cs_db);
312
+ env->CloseDb (strFile);
313
+ assert (!m_db);
312
314
size_t erased = env->m_databases .erase (strFile);
313
315
assert (erased == 1 );
314
316
env->m_fileids .erase (strFile);
@@ -373,25 +375,12 @@ void BerkeleyDatabase::Open(const char* pszMode)
373
375
if (ret != 0 ) {
374
376
throw std::runtime_error (strprintf (" BerkeleyDatabase: Error %d, can't open database %s" , ret, strFile));
375
377
}
378
+ m_file_path = (env->Directory () / strFile).string ();
376
379
377
380
// Call CheckUniqueFileid on the containing BDB environment to
378
381
// avoid BDB data consistency bugs that happen when different data
379
382
// files in the same environment have the same fileid.
380
- //
381
- // Also call CheckUniqueFileid on all the other g_dbenvs to prevent
382
- // bitcoin from opening the same data file through another
383
- // environment when the file is referenced through equivalent but
384
- // not obviously identical symlinked or hard linked or bind mounted
385
- // paths. In the future a more relaxed check for equal inode and
386
- // device ids could be done instead, which would allow opening
387
- // different backup copies of a wallet at the same time. Maybe even
388
- // more ideally, an exclusive lock for accessing the database could
389
- // be implemented, so no equality checks are needed at all. (Newer
390
- // versions of BDB have an set_lk_exclusive method for this
391
- // purpose, but the older version we use does not.)
392
- for (const auto & env : g_dbenvs) {
393
- CheckUniqueFileid (*env.second .lock ().get (), strFile, *pdb_temp, this ->env ->m_fileids [strFile]);
394
- }
383
+ CheckUniqueFileid (*env, strFile, *pdb_temp, this ->env ->m_fileids [strFile]);
395
384
396
385
m_db.reset (pdb_temp.release ());
397
386
0 commit comments