diff options
author | Howard Chu <hyc@symas.com> | 2017-08-19 15:27:13 +0100 |
---|---|---|
committer | Howard Chu <hyc@symas.com> | 2017-08-19 18:11:38 +0100 |
commit | 4c7f8ac04f8693c321f4143e61e7511f200cab1d (patch) | |
tree | 2acc8e82b7969f4ae486fdc7a60cdb5ad21073e1 /src/blockchain_db | |
parent | Merge pull request #2303 (diff) | |
download | monero-4c7f8ac04f8693c321f4143e61e7511f200cab1d.tar.xz |
DB cleanup
Hide LMDB-specific stuff behind blockchain_db.h. Nobody besides blockchain_db.cpp
should ever be including DB-specific headers any more.
Diffstat (limited to '')
-rw-r--r-- | src/blockchain_db/blockchain_db.cpp | 16 | ||||
-rw-r--r-- | src/blockchain_db/blockchain_db.h | 7 | ||||
-rw-r--r-- | src/blockchain_db/lmdb/db_lmdb.cpp | 12 |
3 files changed, 34 insertions, 1 deletions
diff --git a/src/blockchain_db/blockchain_db.cpp b/src/blockchain_db/blockchain_db.cpp index a6774a25c..c7ca533ef 100644 --- a/src/blockchain_db/blockchain_db.cpp +++ b/src/blockchain_db/blockchain_db.cpp @@ -33,6 +33,11 @@ #include "profile_tools.h" #include "ringct/rctOps.h" +#include "lmdb/db_lmdb.h" +#ifdef BERKELEY_DB +#include "berkeleydb/db_bdb.h" +#endif + #undef MONERO_DEFAULT_LOG_CATEGORY #define MONERO_DEFAULT_LOG_CATEGORY "blockchain.db" @@ -41,6 +46,17 @@ using epee::string_tools::pod_to_hex; namespace cryptonote { +BlockchainDB *new_db(const std::string& db_type) +{ + if (db_type == "lmdb") + return new BlockchainLMDB(); +#if defined(BERKELEY_DB) + if (db_type == "berkeley") + return new BlockchainBDB(); +#endif + return NULL; +} + void BlockchainDB::pop_block() { block blk; diff --git a/src/blockchain_db/blockchain_db.h b/src/blockchain_db/blockchain_db.h index 27e63801d..3efb8c3c3 100644 --- a/src/blockchain_db/blockchain_db.h +++ b/src/blockchain_db/blockchain_db.h @@ -145,6 +145,12 @@ struct txpool_tx_meta_t uint8_t padding[77]; // till 192 bytes }; +#define DBF_SAFE 1 +#define DBF_FAST 2 +#define DBF_FASTEST 4 +#define DBF_RDONLY 8 +#define DBF_SALVAGE 0x10 + /*********************************** * Exception Definitions ***********************************/ @@ -1491,6 +1497,7 @@ public: }; // class BlockchainDB +BlockchainDB *new_db(const std::string& db_type); } // namespace cryptonote diff --git a/src/blockchain_db/lmdb/db_lmdb.cpp b/src/blockchain_db/lmdb/db_lmdb.cpp index 4441c7578..a756c04c6 100644 --- a/src/blockchain_db/lmdb/db_lmdb.cpp +++ b/src/blockchain_db/lmdb/db_lmdb.cpp @@ -1083,9 +1083,10 @@ BlockchainLMDB::BlockchainLMDB(bool batch_transactions) m_hardfork = nullptr; } -void BlockchainLMDB::open(const std::string& filename, const int mdb_flags) +void BlockchainLMDB::open(const std::string& filename, const int db_flags) { int result; + int mdb_flags = MDB_NORDAHEAD; LOG_PRINT_L3("BlockchainLMDB::" << __func__); @@ -1124,6 +1125,15 @@ void BlockchainLMDB::open(const std::string& filename, const int mdb_flags) size_t mapsize = DEFAULT_MAPSIZE; + if (db_flags & DBF_FAST) + mdb_flags |= MDB_NOSYNC; + if (db_flags & DBF_FASTEST) + mdb_flags |= MDB_NOSYNC | MDB_WRITEMAP | MDB_MAPASYNC; + if (db_flags & DBF_RDONLY) + mdb_flags = MDB_RDONLY; + if (db_flags & DBF_SALVAGE) + mdb_flags |= MDB_PREVSNAPSHOT; + if (auto result = mdb_env_open(m_env, filename.c_str(), mdb_flags, 0644)) throw0(DB_ERROR(lmdb_error("Failed to open lmdb environment: ", result).c_str())); |