Browse Source

simplify CDBEnv::Open() / fix small glitches

- remove pathEnv from CDBEnv, as this attribute is not needed
- change path parameter in ::Open() to a reference
- make nDbCache variable an unsigned integer
- remove a missplaced ";" behin ::IsMock()
0.8
Philip Kaufmann 12 years ago
parent
commit
c74bae0fdf
  1. 12
      src/db.cpp
  2. 5
      src/db.h

12
src/db.cpp

@ -55,7 +55,7 @@ void CDBEnv::Close()
EnvShutdown(); EnvShutdown();
} }
bool CDBEnv::Open(boost::filesystem::path pathEnv_) bool CDBEnv::Open(const boost::filesystem::path& path)
{ {
if (fDbEnvInit) if (fDbEnvInit)
return true; return true;
@ -63,18 +63,16 @@ bool CDBEnv::Open(boost::filesystem::path pathEnv_)
if (fShutdown) if (fShutdown)
return false; return false;
pathEnv = pathEnv_; filesystem::path pathLogDir = path / "database";
filesystem::path pathDataDir = pathEnv;
filesystem::path pathLogDir = pathDataDir / "database";
filesystem::create_directory(pathLogDir); 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()); printf("dbenv.open LogDir=%s ErrorFile=%s\n", pathLogDir.string().c_str(), pathErrorFile.string().c_str());
unsigned int nEnvFlags = 0; unsigned int nEnvFlags = 0;
if (GetBoolArg("-privdb", true)) if (GetBoolArg("-privdb", true))
nEnvFlags |= DB_PRIVATE; nEnvFlags |= DB_PRIVATE;
int nDbCache = GetArg("-dbcache", 25); unsigned int nDbCache = GetArg("-dbcache", 25);
dbenv.set_lg_dir(pathLogDir.string().c_str()); dbenv.set_lg_dir(pathLogDir.string().c_str());
dbenv.set_cachesize(nDbCache / 1024, (nDbCache % 1024)*1048576, 1); dbenv.set_cachesize(nDbCache / 1024, (nDbCache % 1024)*1048576, 1);
dbenv.set_lg_bsize(1048576); dbenv.set_lg_bsize(1048576);
@ -85,7 +83,7 @@ bool CDBEnv::Open(boost::filesystem::path pathEnv_)
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 = dbenv.open(pathDataDir.string().c_str(), int ret = dbenv.open(path.string().c_str(),
DB_CREATE | DB_CREATE |
DB_INIT_LOCK | DB_INIT_LOCK |
DB_INIT_LOG | DB_INIT_LOG |

5
src/db.h

@ -33,7 +33,6 @@ class CDBEnv
private: private:
bool fDbEnvInit; bool fDbEnvInit;
bool fMockDb; bool fMockDb;
boost::filesystem::path pathEnv;
void EnvShutdown(); void EnvShutdown();
@ -46,7 +45,7 @@ public:
CDBEnv(); CDBEnv();
~CDBEnv(); ~CDBEnv();
void MakeMock(); void MakeMock();
bool IsMock() { return fMockDb; }; bool IsMock() { return fMockDb; }
/* /*
* Verify that database file strFile is OK. If it is not, * Verify that database file strFile is OK. If it is not,
@ -66,7 +65,7 @@ public:
typedef std::pair<std::vector<unsigned char>, std::vector<unsigned char> > KeyValPair; typedef std::pair<std::vector<unsigned char>, std::vector<unsigned char> > KeyValPair;
bool Salvage(std::string strFile, bool fAggressive, std::vector<KeyValPair>& vResult); 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 Close();
void Flush(bool fShutdown); void Flush(bool fShutdown);
void CheckpointLSN(std::string strFile); void CheckpointLSN(std::string strFile);

Loading…
Cancel
Save