diff options
author | moneromooo-monero <moneromooo-monero@users.noreply.github.com> | 2016-08-26 19:33:25 +0100 |
---|---|---|
committer | moneromooo-monero <moneromooo-monero@users.noreply.github.com> | 2016-08-26 19:33:25 +0100 |
commit | f88029e72afa2b53455568209be1001c1bf36769 (patch) | |
tree | f5ffdea8f072cf06aec38e81ec9621f168a9c80d /src/blockchain_db/lmdb/db_lmdb.cpp | |
parent | Merge pull request #963 (diff) | |
download | monero-f88029e72afa2b53455568209be1001c1bf36769.tar.xz |
db_lmdb: do not try to modify the database in read only mode
Diffstat (limited to '')
-rw-r--r-- | src/blockchain_db/lmdb/db_lmdb.cpp | 16 |
1 files changed, 12 insertions, 4 deletions
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; |