Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/db.cpp
// Copyright (c) 2009-2010 Satoshi Nakamoto | // Copyright (c) 2009-2010 Satoshi Nakamoto | ||||
// Copyright (c) 2009-2016 The Bitcoin Core developers | // Copyright (c) 2009-2016 The Bitcoin Core developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#include "db.h" | #include "db.h" | ||||
#include "addrman.h" | #include "addrman.h" | ||||
#include "fs.h" | |||||
#include "hash.h" | #include "hash.h" | ||||
#include "protocol.h" | #include "protocol.h" | ||||
#include "util.h" | #include "util.h" | ||||
#include "utilstrencodings.h" | #include "utilstrencodings.h" | ||||
#include <boost/filesystem.hpp> | |||||
#include <boost/thread.hpp> | #include <boost/thread.hpp> | ||||
#include <boost/version.hpp> | #include <boost/version.hpp> | ||||
#include <cstdint> | #include <cstdint> | ||||
#ifndef WIN32 | #ifndef WIN32 | ||||
#include <sys/stat.h> | #include <sys/stat.h> | ||||
#endif | #endif | ||||
Show All 38 Lines | CDBEnv::~CDBEnv() { | ||||
delete dbenv; | delete dbenv; | ||||
dbenv = nullptr; | dbenv = nullptr; | ||||
} | } | ||||
void CDBEnv::Close() { | void CDBEnv::Close() { | ||||
EnvShutdown(); | EnvShutdown(); | ||||
} | } | ||||
bool CDBEnv::Open(const boost::filesystem::path &pathIn) { | bool CDBEnv::Open(const fs::path &pathIn) { | ||||
if (fDbEnvInit) { | if (fDbEnvInit) { | ||||
return true; | return true; | ||||
} | } | ||||
boost::this_thread::interruption_point(); | boost::this_thread::interruption_point(); | ||||
strPath = pathIn.string(); | strPath = pathIn.string(); | ||||
boost::filesystem::path pathLogDir = pathIn / "database"; | fs::path pathLogDir = pathIn / "database"; | ||||
TryCreateDirectory(pathLogDir); | TryCreateDirectory(pathLogDir); | ||||
boost::filesystem::path pathErrorFile = pathIn / "db.log"; | fs::path pathErrorFile = pathIn / "db.log"; | ||||
LogPrintf("CDBEnv::Open: LogDir=%s ErrorFile=%s\n", pathLogDir.string(), | LogPrintf("CDBEnv::Open: LogDir=%s ErrorFile=%s\n", pathLogDir.string(), | ||||
pathErrorFile.string()); | pathErrorFile.string()); | ||||
unsigned int nEnvFlags = 0; | unsigned int nEnvFlags = 0; | ||||
if (GetBoolArg("-privdb", DEFAULT_WALLET_PRIVDB)) { | if (GetBoolArg("-privdb", DEFAULT_WALLET_PRIVDB)) { | ||||
nEnvFlags |= DB_PRIVATE; | nEnvFlags |= DB_PRIVATE; | ||||
} | } | ||||
dbenv->set_lg_dir(pathLogDir.string().c_str()); | dbenv->set_lg_dir(pathLogDir.string().c_str()); | ||||
// 1 MiB should be enough for just the wallet | // 1 MiB should be enough for just the wallet | ||||
dbenv->set_cachesize(0, 0x100000, 1); | dbenv->set_cachesize(0, 0x100000, 1); | ||||
dbenv->set_lg_bsize(0x10000); | dbenv->set_lg_bsize(0x10000); | ||||
dbenv->set_lg_max(1048576); | dbenv->set_lg_max(1048576); | ||||
dbenv->set_lk_max_locks(40000); | dbenv->set_lk_max_locks(40000); | ||||
dbenv->set_lk_max_objects(40000); | dbenv->set_lk_max_objects(40000); | ||||
/// debug | /// debug | ||||
dbenv->set_errfile(fopen(pathErrorFile.string().c_str(), "a")); | dbenv->set_errfile(fsbridge::fopen(pathErrorFile, "a")); | ||||
dbenv->set_flags(DB_AUTO_COMMIT, 1); | dbenv->set_flags(DB_AUTO_COMMIT, 1); | ||||
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); | ||||
▲ Show 20 Lines • Show All 370 Lines • ▼ Show 20 Lines | if (!fDbEnvInit) { | ||||
fDbEnvInit ? "" : " database not started", | fDbEnvInit ? "" : " database not started", | ||||
GetTimeMillis() - nStart); | GetTimeMillis() - nStart); | ||||
if (fShutdown) { | if (fShutdown) { | ||||
char **listp; | char **listp; | ||||
if (mapFileUseCount.empty()) { | if (mapFileUseCount.empty()) { | ||||
dbenv->log_archive(&listp, DB_ARCH_REMOVE); | dbenv->log_archive(&listp, DB_ARCH_REMOVE); | ||||
Close(); | Close(); | ||||
if (!fMockDb) { | if (!fMockDb) { | ||||
boost::filesystem::remove_all( | fs::remove_all(fs::path(strPath) / "database"); | ||||
boost::filesystem::path(strPath) / "database"); | |||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } |