aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRiccardo Spagni <ric@spagni.net>2016-08-26 20:39:21 +0200
committerRiccardo Spagni <ric@spagni.net>2016-08-26 20:39:21 +0200
commita569b264bc4d4ca1a07c2eadcc24b5ab75fd0c84 (patch)
tree76506826cabab4e255d6163bd1339a6f01ce98d8 /src
parentMerge pull request #989 (diff)
parentdb_lmdb: do not try to modify the database in read only mode (diff)
downloadmonero-a569b264bc4d4ca1a07c2eadcc24b5ab75fd0c84.tar.xz
Merge pull request #991
f88029e db_lmdb: do not try to modify the database in read only mode (moneromooo-monero)
Diffstat (limited to 'src')
-rw-r--r--src/blockchain_db/lmdb/db_lmdb.cpp16
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;