Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions src/db.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,26 +55,24 @@ void CDBEnv::Close()
EnvShutdown();
}

bool CDBEnv::Open(boost::filesystem::path pathEnv_)
bool CDBEnv::Open(const boost::filesystem::path& path)
{
if (fDbEnvInit)
return true;

if (fShutdown)
return false;

pathEnv = pathEnv_;
filesystem::path pathDataDir = pathEnv;
filesystem::path pathLogDir = pathDataDir / "database";
filesystem::path pathLogDir = path / "database";
filesystem::create_directory(pathLogDir);
filesystem::path pathErrorFile = pathDataDir / "db.log";
filesystem::path pathErrorFile = path / "db.log";
printf("dbenv.open LogDir=%s ErrorFile=%s\n", pathLogDir.string().c_str(), pathErrorFile.string().c_str());

unsigned int nEnvFlags = 0;
if (GetBoolArg("-privdb", true))
nEnvFlags |= DB_PRIVATE;

int nDbCache = GetArg("-dbcache", 25);
unsigned int nDbCache = GetArg("-dbcache", 25);
dbenv.set_lg_dir(pathLogDir.string().c_str());
dbenv.set_cachesize(nDbCache / 1024, (nDbCache % 1024)*1048576, 1);
dbenv.set_lg_bsize(1048576);
Expand All @@ -85,7 +83,7 @@ bool CDBEnv::Open(boost::filesystem::path pathEnv_)
dbenv.set_flags(DB_AUTO_COMMIT, 1);
dbenv.set_flags(DB_TXN_WRITE_NOSYNC, 1);
dbenv.log_set_config(DB_LOG_AUTO_REMOVE, 1);
int ret = dbenv.open(pathDataDir.string().c_str(),
int ret = dbenv.open(path.string().c_str(),
DB_CREATE |
DB_INIT_LOCK |
DB_INIT_LOG |
Expand Down
5 changes: 2 additions & 3 deletions src/db.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ class CDBEnv
private:
bool fDbEnvInit;
bool fMockDb;
boost::filesystem::path pathEnv;

void EnvShutdown();

Expand All @@ -46,7 +45,7 @@ class CDBEnv
CDBEnv();
~CDBEnv();
void MakeMock();
bool IsMock() { return fMockDb; };
bool IsMock() { return fMockDb; }

/*
* Verify that database file strFile is OK. If it is not,
Expand All @@ -66,7 +65,7 @@ class CDBEnv
typedef std::pair<std::vector<unsigned char>, std::vector<unsigned char> > KeyValPair;
bool Salvage(std::string strFile, bool fAggressive, std::vector<KeyValPair>& vResult);

bool Open(boost::filesystem::path pathEnv_);
bool Open(const boost::filesystem::path &path);
void Close();
void Flush(bool fShutdown);
void CheckpointLSN(std::string strFile);
Expand Down