From f88029e72afa2b53455568209be1001c1bf36769 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Fri, 26 Aug 2016 19:33:25 +0100 Subject: db_lmdb: do not try to modify the database in read only mode --- src/blockchain_db/lmdb/db_lmdb.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/blockchain_db/lmdb/db_lmdb.cpp b/src/blockchain_db/lmdb/db_lmdb.cpp index 2bab4b2dd..0464ece59 100644 --- a/src/blockchain_db/lmdb/db_lmdb.cpp +++ b/src/blockchain_db/lmdb/db_lmdb.cpp @@ -1084,7 +1084,12 @@ void BlockchainLMDB::open(const std::string& filename, const int mdb_flags) lmdb_db_open(txn, LMDB_SPENT_KEYS, MDB_INTEGERKEY | MDB_CREATE | MDB_DUPSORT | MDB_DUPFIXED, m_spent_keys, "Failed to open db handle for m_spent_keys"); - lmdb_db_open(txn, LMDB_HF_STARTING_HEIGHTS, MDB_CREATE, m_hf_starting_heights, "Failed to open db handle for m_hf_starting_heights"); + // this subdb is dropped on sight, so it may not be present when we open the DB. + // Since we use MDB_CREATE, we'll get an exception if we open read-only and it does not exist. + // So we don't open for read-only, and also not drop below. It is not used elsewhere. + if (!(mdb_flags & MDB_RDONLY)) + lmdb_db_open(txn, LMDB_HF_STARTING_HEIGHTS, MDB_CREATE, m_hf_starting_heights, "Failed to open db handle for m_hf_starting_heights"); + lmdb_db_open(txn, LMDB_HF_VERSIONS, MDB_INTEGERKEY | MDB_CREATE, m_hf_versions, "Failed to open db handle for m_hf_versions"); lmdb_db_open(txn, LMDB_PROPERTIES, MDB_CREATE, m_properties, "Failed to open db handle for m_properties"); @@ -1098,9 +1103,12 @@ void BlockchainLMDB::open(const std::string& filename, const int mdb_flags) mdb_set_compare(txn, m_properties, compare_string); - result = mdb_drop(txn, m_hf_starting_heights, 1); - if (result) - throw0(DB_ERROR(lmdb_error("Failed to drop m_hf_starting_heights: ", result).c_str())); + if (!(mdb_flags & MDB_RDONLY)) + { + result = mdb_drop(txn, m_hf_starting_heights, 1); + if (result) + throw0(DB_ERROR(lmdb_error("Failed to drop m_hf_starting_heights: ", result).c_str())); + } // get and keep current height MDB_stat db_stats; -- cgit v1.2.3