Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/db.cpp
Show First 20 Lines • Show All 135 Lines • ▼ Show 20 Lines | bool CDBEnv::Open(const fs::path &pathIn) { | ||||
dbenv->set_flags(DB_TXN_WRITE_NOSYNC, 1); | dbenv->set_flags(DB_TXN_WRITE_NOSYNC, 1); | ||||
dbenv->log_set_config(DB_LOG_AUTO_REMOVE, 1); | dbenv->log_set_config(DB_LOG_AUTO_REMOVE, 1); | ||||
int ret = | int ret = | ||||
dbenv->open(strPath.c_str(), | dbenv->open(strPath.c_str(), | ||||
DB_CREATE | DB_INIT_LOCK | DB_INIT_LOG | DB_INIT_MPOOL | | DB_CREATE | DB_INIT_LOCK | DB_INIT_LOG | DB_INIT_MPOOL | | ||||
DB_INIT_TXN | DB_THREAD | DB_RECOVER | nEnvFlags, | DB_INIT_TXN | DB_THREAD | DB_RECOVER | nEnvFlags, | ||||
S_IRUSR | S_IWUSR); | S_IRUSR | S_IWUSR); | ||||
if (ret != 0) { | if (ret != 0) { | ||||
dbenv->close(0); | |||||
return error( | return error( | ||||
"CDBEnv::Open: Error %d opening database environment: %s\n", ret, | "CDBEnv::Open: Error %d opening database environment: %s\n", ret, | ||||
DbEnv::strerror(ret)); | DbEnv::strerror(ret)); | ||||
} | } | ||||
fDbEnvInit = true; | fDbEnvInit = true; | ||||
fMockDb = false; | fMockDb = false; | ||||
return true; | return true; | ||||
▲ Show 20 Lines • Show All 82 Lines • ▼ Show 20 Lines | bool CDB::Recover(const std::string &filename, void *callbackDataIn, | ||||
int ret = pdbCopy->open(nullptr, // Txn pointer | int ret = pdbCopy->open(nullptr, // Txn pointer | ||||
filename.c_str(), // Filename | filename.c_str(), // Filename | ||||
"main", // Logical db name | "main", // Logical db name | ||||
DB_BTREE, // Database type | DB_BTREE, // Database type | ||||
DB_CREATE, // Flags | DB_CREATE, // Flags | ||||
0); | 0); | ||||
if (ret > 0) { | if (ret > 0) { | ||||
LogPrintf("Cannot create database file %s\n", filename); | LogPrintf("Cannot create database file %s\n", filename); | ||||
pdbCopy->close(0); | |||||
return false; | return false; | ||||
} | } | ||||
DbTxn *ptxn = bitdb.TxnBegin(); | DbTxn *ptxn = bitdb.TxnBegin(); | ||||
for (CDBEnv::KeyValPair &row : salvagedData) { | for (CDBEnv::KeyValPair &row : salvagedData) { | ||||
if (recoverKVcallback) { | if (recoverKVcallback) { | ||||
CDataStream ssKey(row.first, SER_DISK, CLIENT_VERSION); | CDataStream ssKey(row.first, SER_DISK, CLIENT_VERSION); | ||||
CDataStream ssValue(row.second, SER_DISK, CLIENT_VERSION); | CDataStream ssValue(row.second, SER_DISK, CLIENT_VERSION); | ||||
▲ Show 20 Lines • Show All 355 Lines • ▼ Show 20 Lines | while (true) { | ||||
} | } | ||||
} | } | ||||
if (fSuccess) { | if (fSuccess) { | ||||
db.Close(); | db.Close(); | ||||
env->CloseDb(strFile); | env->CloseDb(strFile); | ||||
if (pdbCopy->close(0)) { | if (pdbCopy->close(0)) { | ||||
fSuccess = false; | fSuccess = false; | ||||
} | } | ||||
} else { | |||||
pdbCopy->close(0); | |||||
} | } | ||||
} | } | ||||
if (fSuccess) { | if (fSuccess) { | ||||
Db dbA(env->dbenv.get(), 0); | Db dbA(env->dbenv.get(), 0); | ||||
if (dbA.remove(strFile.c_str(), nullptr, 0)) { | if (dbA.remove(strFile.c_str(), nullptr, 0)) { | ||||
fSuccess = false; | fSuccess = false; | ||||
} | } | ||||
Db dbB(env->dbenv.get(), 0); | Db dbB(env->dbenv.get(), 0); | ||||
▲ Show 20 Lines • Show All 161 Lines • Show Last 20 Lines |