Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/db.cpp
Show First 20 Lines • Show All 224 Lines • ▼ Show 20 Lines | bool CDB::Recover(const std::string &filename, void *callbackDataIn, | ||||
std::vector<CDBEnv::KeyValPair> salvagedData; | std::vector<CDBEnv::KeyValPair> salvagedData; | ||||
bool fSuccess = bitdb.Salvage(newFilename, true, salvagedData); | bool fSuccess = bitdb.Salvage(newFilename, true, salvagedData); | ||||
if (salvagedData.empty()) { | if (salvagedData.empty()) { | ||||
LogPrintf("Salvage(aggressive) found no records in %s.\n", newFilename); | LogPrintf("Salvage(aggressive) found no records in %s.\n", newFilename); | ||||
return false; | return false; | ||||
} | } | ||||
LogPrintf("Salvage(aggressive) found %u records\n", salvagedData.size()); | LogPrintf("Salvage(aggressive) found %u records\n", salvagedData.size()); | ||||
std::unique_ptr<Db> pdbCopy = MakeUnique<Db>(bitdb.dbenv.get(), 0); | std::unique_ptr<Db> pdbCopy = std::make_unique<Db>(bitdb.dbenv.get(), 0); | ||||
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); | ||||
▲ Show 20 Lines • Show All 191 Lines • ▼ Show 20 Lines | if (fCreate) { | ||||
LOCK(env->cs_db); | LOCK(env->cs_db); | ||||
if (!env->Open(GetWalletDir())) { | if (!env->Open(GetWalletDir())) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
"CDB: Failed to open database environment."); | "CDB: Failed to open database environment."); | ||||
} | } | ||||
pdb = env->mapDb[strFilename]; | pdb = env->mapDb[strFilename]; | ||||
if (pdb == nullptr) { | if (pdb == nullptr) { | ||||
std::unique_ptr<Db> pdb_temp = MakeUnique<Db>(env->dbenv.get(), 0); | std::unique_ptr<Db> pdb_temp = | ||||
std::make_unique<Db>(env->dbenv.get(), 0); | |||||
bool fMockDb = env->IsMock(); | bool fMockDb = env->IsMock(); | ||||
if (fMockDb) { | if (fMockDb) { | ||||
DbMpoolFile *mpf = pdb_temp->get_mpf(); | DbMpoolFile *mpf = pdb_temp->get_mpf(); | ||||
ret = mpf->set_flags(DB_MPOOL_NOFILE, 1); | ret = mpf->set_flags(DB_MPOOL_NOFILE, 1); | ||||
if (ret != 0) { | if (ret != 0) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
strprintf("CDB: Failed to configure for no temp file " | strprintf("CDB: Failed to configure for no temp file " | ||||
▲ Show 20 Lines • Show All 99 Lines • ▼ Show 20 Lines | while (true) { | ||||
bool fSuccess = true; | bool fSuccess = true; | ||||
LogPrintf("CDB::Rewrite: Rewriting %s...\n", strFile); | LogPrintf("CDB::Rewrite: Rewriting %s...\n", strFile); | ||||
std::string strFileRes = strFile + ".rewrite"; | std::string strFileRes = strFile + ".rewrite"; | ||||
{ | { | ||||
// surround usage of db with extra {} | // surround usage of db with extra {} | ||||
CDB db(dbw, "r"); | CDB db(dbw, "r"); | ||||
std::unique_ptr<Db> pdbCopy = | std::unique_ptr<Db> pdbCopy = | ||||
MakeUnique<Db>(env->dbenv.get(), 0); | std::make_unique<Db>(env->dbenv.get(), 0); | ||||
int ret = pdbCopy->open(nullptr, // Txn pointer | int ret = pdbCopy->open(nullptr, // Txn pointer | ||||
strFileRes.c_str(), // Filename | strFileRes.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) { | ||||
▲ Show 20 Lines • Show All 215 Lines • Show Last 20 Lines |