From 84dfc6917aa70f0f5b5c6e616ab125b339a1fa82 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Sat, 31 Aug 2019 14:41:18 +0200 Subject: [PATCH] added cmake paramter to have mdbx as an option --- CMakeLists.txt | 8 +++++++- contrib/CMakeLists.txt | 4 +--- contrib/db/CMakeLists.txt | 21 ++++++++++++++------- src/CMakeLists.txt | 2 +- src/common/db_backend_lmdb.cpp | 3 +++ src/common/db_backend_lmdb.h | 3 +++ src/common/db_backend_mdbx.cpp | 5 +++++ src/common/db_backend_mdbx.h | 6 ++++++ src/currency_core/blockchain_storage.cpp | 5 ++--- src/currency_core/currency_config.h | 14 ++++++++++---- src/currency_core/tx_pool.cpp | 4 ++-- 11 files changed, 54 insertions(+), 21 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e0b9cb8c..5cd70463 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -215,7 +215,13 @@ else() endif() set(BUILD_TESTS FALSE CACHE BOOL "Build Zano tests") - +set(DB_ENGINE "lmdb" CACHE STRING "Select database engine") +if (DB_ENGINE STREQUAL "lmdb") + add_definitions(-DDB_ENGINE_LMDB) +elseif(DB_ENGINE STREQUAL "mdbx") + add_definitions(-DDB_ENGINE_MDBX) +endif() + add_subdirectory(contrib) add_subdirectory(src) diff --git a/contrib/CMakeLists.txt b/contrib/CMakeLists.txt index bcf3ed09..6c204adb 100644 --- a/contrib/CMakeLists.txt +++ b/contrib/CMakeLists.txt @@ -9,9 +9,7 @@ add_subdirectory(ethereum) set_property(TARGET upnpc-static PROPERTY FOLDER "contrib/miniupnp") set_property(TARGET zlibstatic PROPERTY FOLDER "contrib") -set_property(TARGET lmdb PROPERTY FOLDER "contrib") -set_property(TARGET mdbx PROPERTY FOLDER "contrib") - +set_property(TARGET ${DB_ENGINE} PROPERTY FOLDER "contrib") diff --git a/contrib/db/CMakeLists.txt b/contrib/db/CMakeLists.txt index 57961a93..a0638716 100644 --- a/contrib/db/CMakeLists.txt +++ b/contrib/db/CMakeLists.txt @@ -1,8 +1,15 @@ -add_subdirectory(liblmdb) -add_subdirectory(libmdbx) -if(MSVC) - target_compile_options(lmdb PRIVATE /wd4996 /wd4503 /wd4345 /wd4267 /wd4244 /wd4146 /wd4333 /wd4172) -else() - # Warnings as used by LMDB itself (LMDB_0.9.23) - target_compile_options(lmdb PRIVATE -Wall -Wno-unused-parameter -Wbad-function-cast -Wuninitialized) + +if (DB_ENGINE STREQUAL "lmdb") + message("DB ENGINE: lmdb") + add_subdirectory(liblmdb) + if(MSVC) + target_compile_options(lmdb PRIVATE /wd4996 /wd4503 /wd4345 /wd4267 /wd4244 /wd4146 /wd4333 /wd4172) + else() + # Warnings as used by LMDB itself (LMDB_0.9.23) + target_compile_options(lmdb PRIVATE -Wall -Wno-unused-parameter -Wbad-function-cast -Wuninitialized) + endif() +elseif(DB_ENGINE STREQUAL "mdbx") + message("DB ENGINE: mdbx") + add_subdirectory(libmdbx) endif() + diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 772a4535..1bc8e4d0 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -116,7 +116,7 @@ add_library(wallet ${WALLET}) add_dependencies(wallet version ${PCH_LIB_NAME}) ENABLE_SHARED_PCH(WALLET) -target_link_libraries(currency_core mdbx lmdb) +target_link_libraries(currency_core ${DB_ENGINE}) add_executable(daemon ${DAEMON} ${P2P} ${CURRENCY_PROTOCOL}) add_dependencies(daemon version) diff --git a/src/common/db_backend_lmdb.cpp b/src/common/db_backend_lmdb.cpp index fdb289ff..13dea1cd 100644 --- a/src/common/db_backend_lmdb.cpp +++ b/src/common/db_backend_lmdb.cpp @@ -3,6 +3,8 @@ // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +#ifdef DB_ENGINE_LMDB + #include "db_backend_lmdb.h" #include "misc_language.h" #include "string_coding.h" @@ -388,3 +390,4 @@ namespace tools #undef LOG_DEFAULT_CHANNEL #define LOG_DEFAULT_CHANNEL NULL +#endif \ No newline at end of file diff --git a/src/common/db_backend_lmdb.h b/src/common/db_backend_lmdb.h index 95c9d8a9..93effc98 100644 --- a/src/common/db_backend_lmdb.h +++ b/src/common/db_backend_lmdb.h @@ -4,6 +4,8 @@ // file COPYING or http://www.opensource.org/licenses/mit-license.php. #pragma once +#ifdef DB_ENGINE_LMDB + #include #include "include_base_utils.h" @@ -60,3 +62,4 @@ namespace tools }; } } +#endif \ No newline at end of file diff --git a/src/common/db_backend_mdbx.cpp b/src/common/db_backend_mdbx.cpp index 792d6f67..ebe80baa 100644 --- a/src/common/db_backend_mdbx.cpp +++ b/src/common/db_backend_mdbx.cpp @@ -3,12 +3,15 @@ // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +#ifdef DB_ENGINE_MDBX + #include "db_backend_mdbx.h" #include "misc_language.h" #include "string_coding.h" #include "profile_tools.h" #include "util.h" + #define BUF_SIZE 1024 #define CHECK_AND_ASSERT_MESS_MDBX_DB(rc, ret, mess) CHECK_AND_ASSERT_MES(res == MDBX_SUCCESS, ret, "[DB ERROR]:(" << rc << ")" << mdbx_strerror(rc) << ", [message]: " << mess); @@ -394,3 +397,5 @@ namespace tools #undef LOG_DEFAULT_CHANNEL #define LOG_DEFAULT_CHANNEL NULL + +#endif \ No newline at end of file diff --git a/src/common/db_backend_mdbx.h b/src/common/db_backend_mdbx.h index f60e4028..f2b603ae 100644 --- a/src/common/db_backend_mdbx.h +++ b/src/common/db_backend_mdbx.h @@ -4,6 +4,9 @@ // file COPYING or http://www.opensource.org/licenses/mit-license.php. #pragma once + +#ifdef DB_ENGINE_MDBX + #include #include "include_base_utils.h" @@ -58,5 +61,8 @@ namespace tools MDBX_txn* get_current_tx(); }; + } } + +#endif \ No newline at end of file diff --git a/src/currency_core/blockchain_storage.cpp b/src/currency_core/blockchain_storage.cpp index a7218a93..2d7994c6 100644 --- a/src/currency_core/blockchain_storage.cpp +++ b/src/currency_core/blockchain_storage.cpp @@ -14,8 +14,7 @@ #include "include_base_utils.h" -#include "common/db_backend_lmdb.h" -#include "common/db_backend_mdbx.h" +#include "common/db_backend_selector.h" #include "common/command_line.h" #include "blockchain_storage.h" @@ -81,7 +80,7 @@ namespace } //------------------------------------------------------------------ -blockchain_storage::blockchain_storage(tx_memory_pool& tx_pool) :m_db(std::shared_ptr(new tools::db::mdbx_db_backend), m_rw_lock), +blockchain_storage::blockchain_storage(tx_memory_pool& tx_pool) :m_db(std::shared_ptr(new tools::db::default_db_backend), m_rw_lock), m_db_blocks(m_db), m_db_blocks_index(m_db), m_db_transactions(m_db), diff --git a/src/currency_core/currency_config.h b/src/currency_core/currency_config.h index 10e32087..8488f44a 100644 --- a/src/currency_core/currency_config.h +++ b/src/currency_core/currency_config.h @@ -189,10 +189,16 @@ #define CURRENCY_POOLDATA_FOLDERNAME_OLD "poolstate" #define CURRENCY_BLOCKCHAINDATA_FOLDERNAME_OLD "blockchain" -//#define CURRENCY_POOLDATA_FOLDERNAME "poolstate_lmdb_v1" -//#define CURRENCY_BLOCKCHAINDATA_FOLDERNAME "blockchain_lmdb_v1" -#define CURRENCY_POOLDATA_FOLDERNAME "poolstate_mdbx_v1" -#define CURRENCY_BLOCKCHAINDATA_FOLDERNAME "blockchain_mdbx_v1" + +#ifdef DB_ENGINE_LMDB + #define CURRENCY_BLOCKCHAINDATA_DB_ENGINE_NAME "lmdb" +#elif DB_ENGINE_MDBX + #define CURRENCY_BLOCKCHAINDATA_DB_ENGINE_NAME "mdbx" +#endif + +#define CURRENCY_POOLDATA_FOLDERNAME "poolstate_" CURRENCY_BLOCKCHAINDATA_DB_ENGINE_NAME "_v1" +#define CURRENCY_BLOCKCHAINDATA_FOLDERNAME "blockchain_" CURRENCY_BLOCKCHAINDATA_DB_ENGINE_NAME "_v1" + #define P2P_NET_DATA_FILENAME "p2pstate.bin" #define MINER_CONFIG_FILENAME "miner_conf.json" #define GUI_SECURE_CONFIG_FILENAME "gui_secure_conf.bin" diff --git a/src/currency_core/tx_pool.cpp b/src/currency_core/tx_pool.cpp index 6803ac16..32fde76b 100644 --- a/src/currency_core/tx_pool.cpp +++ b/src/currency_core/tx_pool.cpp @@ -9,7 +9,7 @@ #include #include -#include "common/db_backend_lmdb.h" +#include "common/db_backend_selector.h" #include "tx_pool.h" #include "currency_boost_serialization.h" #include "currency_core/currency_config.h" @@ -42,7 +42,7 @@ namespace currency tx_memory_pool::tx_memory_pool(blockchain_storage& bchs, i_currency_protocol* pprotocol) : m_blockchain(bchs), m_pprotocol(pprotocol), - m_db(std::shared_ptr(new tools::db::lmdb_db_backend), m_dummy_rw_lock), + m_db(std::shared_ptr(new tools::db::default_db_backend), m_dummy_rw_lock), m_db_transactions(m_db), m_db_black_tx_list(m_db), m_db_solo_options(m_db),