Fix MDB backend for directory creation

This commit is contained in:
Vinnie Falco
2013-07-21 12:50:58 -07:00
parent 4fcbbe6072
commit 1d0795095b

View File

@@ -26,41 +26,55 @@ public:
{
String path (keyValues ["path"]);
m_name = path.toStdString();
if (path.isEmpty ())
Throw (std::runtime_error ("Missing path in MDB backend"));
int error = 0;
m_basePath = path.toStdString();
error = mdb_env_create (&m_env);
// Regarding the path supplied to mdb_env_open:
// This directory must already exist and be writable.
//
File dir (File::getCurrentWorkingDirectory().getChildFile (path));
Result result = dir.createDirectory ();
if (error == 0) // Should use the size of the file plus the free space on the disk
error = mdb_env_set_mapsize (m_env, 512L * 1024L * 1024L * 1024L);
if (result.wasOk ())
{
int error = mdb_env_create (&m_env);
if (error == 0)
error = mdb_env_open (
m_env,
m_name.c_str (),
MDB_NOTLS,
0664);
// Should use the size of the file plus the free space on the disk
if (error == 0)
error = mdb_env_set_mapsize (m_env, 512L * 1024L * 1024L * 1024L);
MDB_txn* txn;
if (error == 0)
error = mdb_env_open (
m_env,
m_basePath.c_str (),
MDB_NOTLS,
0664);
if (error == 0)
error = mdb_txn_begin (m_env, NULL, 0, &txn);
MDB_txn* txn;
if (error == 0)
error = mdb_dbi_open (txn, NULL, 0, &m_dbi);
if (error == 0)
error = mdb_txn_begin (m_env, NULL, 0, &txn);
if (error == 0)
error = mdb_txn_commit (txn);
if (error == 0)
error = mdb_dbi_open (txn, NULL, 0, &m_dbi);
if (error != 0)
if (error == 0)
error = mdb_txn_commit (txn);
if (error != 0)
{
String s;
s << "Error #" << error << " creating mdb environment";
Throw (std::runtime_error (s.toStdString ()));
}
}
else
{
String s;
s << "Error #" << error << " creating mdb environment";
Throw (std::runtime_error (s.toStdString ()));
s << "MDB Backend failed to create directory, " << result.getErrorMessage ();
Throw (std::runtime_error (s.toStdString().c_str()));
}
}
@@ -75,7 +89,7 @@ public:
std::string getName()
{
return m_name;
return m_basePath;
}
//--------------------------------------------------------------------------
@@ -227,7 +241,7 @@ private:
NodeStore::Scheduler& m_scheduler;
NodeStore::BatchWriter m_batch;
NodeStore::EncodedBlob::Pool m_blobPool;
std::string m_name;
std::string m_basePath;
MDB_env* m_env;
MDB_dbi m_dbi;
};