mirror of
https://github.com/monero-project/monero.git
synced 2024-11-17 16:27:39 +00:00
Allow BlockchainLMDB to be opened in read-only mode
Have blockchain_export use read-only mode when source is BlockchainLMDB.
This commit is contained in:
parent
73d3511412
commit
d35bffb950
2 changed files with 11 additions and 4 deletions
|
@ -678,9 +678,13 @@ void BlockchainLMDB::open(const std::string& filename, const int mdb_flags)
|
||||||
if (auto result = mdb_env_open(m_env, filename.c_str(), mdb_flags, 0644))
|
if (auto result = mdb_env_open(m_env, filename.c_str(), mdb_flags, 0644))
|
||||||
throw0(DB_ERROR(std::string("Failed to open lmdb environment: ").append(mdb_strerror(result)).c_str()));
|
throw0(DB_ERROR(std::string("Failed to open lmdb environment: ").append(mdb_strerror(result)).c_str()));
|
||||||
|
|
||||||
// get a read/write MDB_txn
|
int txn_flags = 0;
|
||||||
|
if (mdb_flags & MDB_RDONLY)
|
||||||
|
txn_flags |= MDB_RDONLY;
|
||||||
|
|
||||||
|
// get a read/write MDB_txn, depending on mdb_flags
|
||||||
mdb_txn_safe txn;
|
mdb_txn_safe txn;
|
||||||
if (mdb_txn_begin(m_env, NULL, 0, txn))
|
if (mdb_txn_begin(m_env, NULL, txn_flags, txn))
|
||||||
throw0(DB_ERROR("Failed to create a transaction for the db"));
|
throw0(DB_ERROR("Failed to create a transaction for the db"));
|
||||||
|
|
||||||
// open necessary databases, and set properties as needed
|
// open necessary databases, and set properties as needed
|
||||||
|
|
|
@ -129,11 +129,14 @@ int main(int argc, char* argv[])
|
||||||
BlockchainDB* db = new BlockchainLMDB();
|
BlockchainDB* db = new BlockchainLMDB();
|
||||||
boost::filesystem::path folder(m_config_folder);
|
boost::filesystem::path folder(m_config_folder);
|
||||||
folder /= db->get_db_name();
|
folder /= db->get_db_name();
|
||||||
LOG_PRINT_L0("Loading blockchain from folder " << folder.string() << " ...");
|
int lmdb_flags = 0;
|
||||||
|
lmdb_flags |= MDB_RDONLY;
|
||||||
const std::string filename = folder.string();
|
const std::string filename = folder.string();
|
||||||
|
|
||||||
|
LOG_PRINT_L0("Loading blockchain from folder " << filename << " ...");
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
db->open(filename);
|
db->open(filename, lmdb_flags);
|
||||||
}
|
}
|
||||||
catch (const std::exception& e)
|
catch (const std::exception& e)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue