forked from lthn/blockchain
libmdbx set as an option for command line parameter(--db-engine)
This commit is contained in:
parent
d809bbdb20
commit
1ade55eb17
20 changed files with 90 additions and 51 deletions
|
|
@ -214,12 +214,11 @@ 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()
|
||||
set(DISABLE_MDBX FALSE CACHE BOOL "Exclude mdbx from build(need for a first time)")
|
||||
if(NOT DISABLE_MDBX)
|
||||
add_definitions(-DENABLED_ENGINE_MDBX)
|
||||
endif()
|
||||
|
||||
|
||||
add_subdirectory(contrib)
|
||||
add_subdirectory(src)
|
||||
|
|
|
|||
|
|
@ -7,9 +7,12 @@ add_subdirectory(db)
|
|||
add_subdirectory(ethereum)
|
||||
|
||||
|
||||
set_property(TARGET upnpc-static PROPERTY FOLDER "contrib/miniupnp")
|
||||
set_property(TARGET libminiupnpc-static PROPERTY FOLDER "contrib")
|
||||
set_property(TARGET zlibstatic PROPERTY FOLDER "contrib")
|
||||
set_property(TARGET ${DB_ENGINE} PROPERTY FOLDER "contrib")
|
||||
set_property(TARGET mdbx PROPERTY FOLDER "contrib")
|
||||
set_property(TARGET lmdb PROPERTY FOLDER "contrib")
|
||||
set_property(TARGET upnpc-static mdbx_chk mdbx_copy mdbx_dump mdbx_load mdbx_stat minigzip ntdll_extra_target zlib example PROPERTY FOLDER "unused")
|
||||
|
||||
|
||||
if(MSVC)
|
||||
set_property(TARGET upnpc-static APPEND_STRING PROPERTY COMPILE_FLAGS " /wd4244 /wd4267")
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
|
||||
if (DB_ENGINE STREQUAL "lmdb")
|
||||
message("DB ENGINE: lmdb")
|
||||
add_subdirectory(liblmdb)
|
||||
if(MSVC)
|
||||
|
|
@ -8,8 +7,7 @@ if (DB_ENGINE STREQUAL "lmdb")
|
|||
# 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()
|
||||
|
||||
if(NOT DISABLE_MDBX)
|
||||
message("DB ENGINE: mdbx")
|
||||
add_subdirectory(libmdbx)
|
||||
endif()
|
||||
|
|
|
|||
|
|
@ -116,7 +116,7 @@ add_library(wallet ${WALLET})
|
|||
add_dependencies(wallet version ${PCH_LIB_NAME})
|
||||
ENABLE_SHARED_PCH(WALLET)
|
||||
|
||||
target_link_libraries(currency_core ${DB_ENGINE})
|
||||
target_link_libraries(currency_core lmdb mdbx)
|
||||
|
||||
add_executable(daemon ${DAEMON} ${P2P} ${CURRENCY_PROTOCOL})
|
||||
add_dependencies(daemon version)
|
||||
|
|
|
|||
|
|
@ -30,4 +30,5 @@ namespace command_line
|
|||
const arg_descriptor<bool> arg_disable_stop_if_time_out_of_sync = { "disable-stop-if-time-out-of-sync", "Do not stop the daemon if serious time synchronization problem is detected", false, true };
|
||||
const arg_descriptor<bool> arg_disable_stop_on_low_free_space = { "disable-stop-on-low-free-space", "Do not stop the daemon if free space at data dir is critically low", false, true };
|
||||
const arg_descriptor<bool> arg_enable_offers_service = { "enable-offers-service", "Enables marketplace feature", false, false};
|
||||
const arg_descriptor<std::string> arg_db_engine = { "db-engine", "Specify database engine for storage. May be \"lmdb\"(default) or \"mdbx\"", ARG_DB_ENGINE_LMDB, false };
|
||||
}
|
||||
|
|
|
|||
|
|
@ -172,6 +172,9 @@ namespace command_line
|
|||
return get_arg<bool, false>(vm, arg);
|
||||
}
|
||||
|
||||
#define ARG_DB_ENGINE_LMDB "lmdb"
|
||||
#define ARG_DB_ENGINE_MDBX "mdbx"
|
||||
|
||||
|
||||
extern const arg_descriptor<bool> arg_help;
|
||||
extern const arg_descriptor<bool> arg_version;
|
||||
|
|
@ -188,4 +191,5 @@ namespace command_line
|
|||
extern const arg_descriptor<bool> arg_disable_stop_if_time_out_of_sync;
|
||||
extern const arg_descriptor<bool> arg_disable_stop_on_low_free_space;
|
||||
extern const arg_descriptor<bool> arg_enable_offers_service;
|
||||
extern const arg_descriptor<std::string> arg_db_engine;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -95,7 +95,7 @@ namespace tools
|
|||
{
|
||||
close();
|
||||
}
|
||||
|
||||
void reset_backend(std::shared_ptr<i_db_backend> backend) { m_backend = backend; }
|
||||
performance_data& get_performance_data_for_handle(container_handle h) const { return m_performance_data_map[h]; }
|
||||
performance_data& get_performance_data_global() const { return m_gperformance_data; }
|
||||
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@ namespace tools
|
|||
virtual bool clear(container_handle h) = 0;
|
||||
virtual bool enumerate(container_handle h, i_db_callback* pcb)=0;
|
||||
virtual bool get_stat_info(stat_info& si) = 0;
|
||||
virtual const char* name()=0;
|
||||
virtual ~i_db_backend(){};
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,8 +3,6 @@
|
|||
// 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"
|
||||
|
|
@ -381,9 +379,12 @@ namespace tools
|
|||
}
|
||||
return true;
|
||||
}
|
||||
const char* lmdb_db_backend::name()
|
||||
{
|
||||
return "lmdb";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#undef LOG_DEFAULT_CHANNEL
|
||||
#define LOG_DEFAULT_CHANNEL NULL
|
||||
#endif
|
||||
|
|
@ -4,7 +4,6 @@
|
|||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#pragma once
|
||||
#ifdef DB_ENGINE_LMDB
|
||||
|
||||
#include <thread>
|
||||
|
||||
|
|
@ -55,6 +54,7 @@ namespace tools
|
|||
bool set(container_handle h, const char* k, size_t s, const char* v, size_t vs);
|
||||
bool enumerate(container_handle h, i_db_callback* pcb);
|
||||
bool get_stat_info(tools::db::stat_info& si);
|
||||
const char* name();
|
||||
//-------------------------------------------------------------------------------------
|
||||
bool have_tx();
|
||||
MDB_txn* get_current_tx();
|
||||
|
|
@ -62,4 +62,3 @@ namespace tools
|
|||
};
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
@ -2,9 +2,7 @@
|
|||
// Copyright (c) 2014-2018 The Louisdor Project
|
||||
// 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
|
||||
|
||||
#ifdef ENABLED_ENGINE_MDBX
|
||||
#include "db_backend_mdbx.h"
|
||||
#include "misc_language.h"
|
||||
#include "string_coding.h"
|
||||
|
|
@ -392,10 +390,13 @@ namespace tools
|
|||
}
|
||||
return true;
|
||||
}
|
||||
const char* mdbx_db_backend::name()
|
||||
{
|
||||
return "mdbx";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#undef LOG_DEFAULT_CHANNEL
|
||||
#define LOG_DEFAULT_CHANNEL NULL
|
||||
|
||||
#endif
|
||||
|
|
@ -4,9 +4,7 @@
|
|||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef DB_ENGINE_MDBX
|
||||
|
||||
#ifdef ENABLED_ENGINE_MDBX
|
||||
#include <thread>
|
||||
|
||||
#include "include_base_utils.h"
|
||||
|
|
@ -56,6 +54,7 @@ namespace tools
|
|||
bool set(container_handle h, const char* k, size_t s, const char* v, size_t vs);
|
||||
bool enumerate(container_handle h, i_db_callback* pcb);
|
||||
bool get_stat_info(tools::db::stat_info& si);
|
||||
const char* name();
|
||||
//-------------------------------------------------------------------------------------
|
||||
bool have_tx();
|
||||
MDBX_txn* get_current_tx();
|
||||
|
|
@ -64,5 +63,4 @@ namespace tools
|
|||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -7,15 +7,35 @@
|
|||
|
||||
#include "db_backend_lmdb.h"
|
||||
#include "db_backend_mdbx.h"
|
||||
#include "common/command_line.h"
|
||||
#include "common/db_abstract_accessor.h"
|
||||
|
||||
namespace tools
|
||||
{
|
||||
namespace db
|
||||
{
|
||||
#ifdef DB_ENGINE_LMDB
|
||||
typedef lmdb_db_backend default_db_backend;
|
||||
#elif DB_ENGINE_MDBX
|
||||
typedef mdbx_db_backend default_db_backend;
|
||||
#endif
|
||||
inline
|
||||
bool select_db_engine_from_arg(const boost::program_options::variables_map& vm, tools::db::basic_db_accessor& rdb)
|
||||
{
|
||||
if (command_line::get_arg(vm, command_line::arg_db_engine) == ARG_DB_ENGINE_LMDB)
|
||||
{
|
||||
rdb.reset_backend(std::shared_ptr<tools::db::i_db_backend>(new tools::db::lmdb_db_backend));
|
||||
}
|
||||
else if (command_line::get_arg(vm, command_line::arg_db_engine) == ARG_DB_ENGINE_MDBX)
|
||||
{
|
||||
#ifdef ENABLED_ENGINE_MDBX
|
||||
rdb.reset_backend(std::shared_ptr<tools::db::i_db_backend>(new tools::db::mdbx_db_backend));
|
||||
#else
|
||||
LOG_PRINT_L0(" DB ENGINE: " << ARG_DB_ENGINE_MDBX << " is not suported by this build(see DISABLE_MDBX cmake option), STOPPING");
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_PRINT_RED_L0(" UNKNOWN DB ENGINE: " << command_line::get_arg(vm, command_line::arg_db_engine) << ", STOPPING");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -69,7 +69,7 @@ using namespace currency;
|
|||
#endif
|
||||
#define BLOCK_POS_STRICT_SEQUENCE_LIMIT 20
|
||||
|
||||
|
||||
#define CURRENCY_BLOCKCHAINDATA_FOLDERNAME_SUFFIX "_v1"
|
||||
|
||||
DISABLE_VS_WARNINGS(4267)
|
||||
|
||||
|
|
@ -80,7 +80,7 @@ namespace
|
|||
}
|
||||
|
||||
//------------------------------------------------------------------
|
||||
blockchain_storage::blockchain_storage(tx_memory_pool& tx_pool) :m_db(std::shared_ptr<tools::db::i_db_backend>(new tools::db::default_db_backend), m_rw_lock),
|
||||
blockchain_storage::blockchain_storage(tx_memory_pool& tx_pool) :m_db(nullptr, m_rw_lock),
|
||||
m_db_blocks(m_db),
|
||||
m_db_blocks_index(m_db),
|
||||
m_db_transactions(m_db),
|
||||
|
|
@ -206,7 +206,13 @@ bool blockchain_storage::validate_instance(const std::string& path)
|
|||
bool blockchain_storage::init(const std::string& config_folder, const boost::program_options::variables_map& vm)
|
||||
{
|
||||
// CRITICAL_REGION_LOCAL(m_read_lock);
|
||||
|
||||
if (!select_db_engine_from_arg(vm, m_db))
|
||||
{
|
||||
LOG_PRINT_RED_L0("Failed to select db engine");
|
||||
return false;
|
||||
}
|
||||
LOG_PRINT_L0("DB ENGINE USED BY CORE: " << m_db.get_backend()->name());
|
||||
|
||||
if (!validate_instance(config_folder))
|
||||
{
|
||||
LOG_ERROR("Failed to initialize instance");
|
||||
|
|
@ -229,8 +235,8 @@ bool blockchain_storage::init(const std::string& config_folder, const boost::pro
|
|||
LOG_PRINT_YELLOW("Removing old DB in " << old_db_folder_path << "...", LOG_LEVEL_0);
|
||||
boost::filesystem::remove_all(epee::string_encoding::utf8_to_wstring(old_db_folder_path));
|
||||
}
|
||||
|
||||
const std::string db_folder_path = m_config_folder + "/" CURRENCY_BLOCKCHAINDATA_FOLDERNAME;
|
||||
;
|
||||
const std::string db_folder_path = m_config_folder + ("/" CURRENCY_BLOCKCHAINDATA_FOLDERNAME_PREFIX) + m_db.get_backend()->name() + CURRENCY_BLOCKCHAINDATA_FOLDERNAME_SUFFIX;
|
||||
LOG_PRINT_L0("Loading blockchain from " << db_folder_path);
|
||||
|
||||
bool db_opened_okay = false;
|
||||
|
|
|
|||
|
|
@ -190,14 +190,9 @@
|
|||
#define CURRENCY_POOLDATA_FOLDERNAME_OLD "poolstate"
|
||||
#define CURRENCY_BLOCKCHAINDATA_FOLDERNAME_OLD "blockchain"
|
||||
|
||||
#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 CURRENCY_POOLDATA_FOLDERNAME_PREFIX "poolstate_"
|
||||
#define CURRENCY_BLOCKCHAINDATA_FOLDERNAME_PREFIX "blockchain_"
|
||||
|
||||
#define P2P_NET_DATA_FILENAME "p2pstate.bin"
|
||||
#define MINER_CONFIG_FILENAME "miner_conf.json"
|
||||
|
|
|
|||
|
|
@ -142,7 +142,7 @@ namespace currency
|
|||
uint64_t available_space = 0;
|
||||
CHECK_AND_ASSERT_MES(!check_if_free_space_critically_low(&available_space), false, "free space in data folder is critically low: " << std::fixed << available_space / (1024 * 1024) << " MB");
|
||||
|
||||
r = m_mempool.init(m_config_folder);
|
||||
r = m_mempool.init(m_config_folder, vm);
|
||||
CHECK_AND_ASSERT_MES(r, false, "Failed to initialize memory pool");
|
||||
|
||||
r = m_blockchain_storage.init(m_config_folder, vm);
|
||||
|
|
|
|||
|
|
@ -32,6 +32,8 @@ DISABLE_VS_WARNINGS(4244 4345 4503) //'boost::foreach_detail_::or_' : decorated
|
|||
#define TRANSACTION_POOL_OPTIONS_ID_STORAGE_MAJOR_COMPATIBILITY_VERSION 92 // DON'T CHANGE THIS, if you need to resync db! Change TRANSACTION_POOL_MAJOR_COMPATIBILITY_VERSION instead!
|
||||
#define TRANSACTION_POOL_MAJOR_COMPATIBILITY_VERSION BLOCKCHAIN_STORAGE_MAJOR_COMPATIBILITY_VERSION + 1
|
||||
|
||||
#define CURRENCY_POOLDATA_FOLDERNAME_SUFFIX "_v1"
|
||||
|
||||
#undef LOG_DEFAULT_CHANNEL
|
||||
#define LOG_DEFAULT_CHANNEL "tx_pool"
|
||||
ENABLE_CHANNEL_BY_DEFAULT("tx_pool");
|
||||
|
|
@ -42,7 +44,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<tools::db::i_db_backend>(new tools::db::default_db_backend), m_dummy_rw_lock),
|
||||
m_db(nullptr, m_dummy_rw_lock),
|
||||
m_db_transactions(m_db),
|
||||
m_db_black_tx_list(m_db),
|
||||
m_db_solo_options(m_db),
|
||||
|
|
@ -1116,8 +1118,15 @@ namespace currency
|
|||
m_db.commit_transaction();
|
||||
}
|
||||
//---------------------------------------------------------------------------------
|
||||
bool tx_memory_pool::init(const std::string& config_folder)
|
||||
bool tx_memory_pool::init(const std::string& config_folder, const boost::program_options::variables_map& vm)
|
||||
{
|
||||
if (!select_db_engine_from_arg(vm, m_db))
|
||||
{
|
||||
LOG_PRINT_RED_L0("Failed to select db engine");
|
||||
return false;
|
||||
}
|
||||
LOG_PRINT_L0("DB ENGINE USED BY POOL: " << m_db.get_backend()->name());
|
||||
|
||||
m_config_folder = config_folder;
|
||||
|
||||
uint64_t cache_size_l1 = CACHE_SIZE;
|
||||
|
|
@ -1131,7 +1140,8 @@ namespace currency
|
|||
boost::filesystem::remove_all(epee::string_encoding::utf8_to_wstring(old_db_folder_path));
|
||||
}
|
||||
|
||||
const std::string db_folder_path = m_config_folder + "/" CURRENCY_POOLDATA_FOLDERNAME;
|
||||
const std::string db_folder_path = m_config_folder + ("/" CURRENCY_POOLDATA_FOLDERNAME_PREFIX) + m_db.get_backend()->name() + CURRENCY_POOLDATA_FOLDERNAME_SUFFIX;
|
||||
|
||||
LOG_PRINT_L0("Loading blockchain from " << db_folder_path << "...");
|
||||
|
||||
bool db_opened_okay = false;
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ using namespace epee;
|
|||
#include "math_helper.h"
|
||||
|
||||
#include "common/db_abstract_accessor.h"
|
||||
#include "common/command_line.h"
|
||||
|
||||
#include "currency_format_utils.h"
|
||||
#include "verification_context.h"
|
||||
|
|
@ -114,7 +115,7 @@ namespace currency
|
|||
void clear();
|
||||
|
||||
// load/store operations
|
||||
bool init(const std::string& config_folder);
|
||||
bool init(const std::string& config_folder, const boost::program_options::variables_map& vm);
|
||||
bool deinit();
|
||||
bool fill_block_template(block &bl, bool pos, size_t median_size, const boost::multiprecision::uint128_t& already_generated_coins, size_t &total_size, uint64_t &fee, uint64_t height);
|
||||
bool get_transactions(std::list<transaction>& txs) const;
|
||||
|
|
|
|||
|
|
@ -147,6 +147,7 @@ int main(int argc, char* argv[])
|
|||
command_line::add_arg(desc_cmd_sett, command_line::arg_disable_stop_if_time_out_of_sync);
|
||||
command_line::add_arg(desc_cmd_sett, command_line::arg_disable_stop_on_low_free_space);
|
||||
command_line::add_arg(desc_cmd_sett, command_line::arg_enable_offers_service);
|
||||
command_line::add_arg(desc_cmd_sett, command_line::arg_db_engine);
|
||||
|
||||
|
||||
arg_market_disable.default_value = true;
|
||||
|
|
|
|||
|
|
@ -120,6 +120,7 @@ bool daemon_backend::init(int argc, char* argv[], view::i_view* pview_handler)
|
|||
command_line::add_arg(desc_cmd_sett, command_line::arg_log_level);
|
||||
command_line::add_arg(desc_cmd_sett, command_line::arg_console);
|
||||
command_line::add_arg(desc_cmd_sett, command_line::arg_show_details);
|
||||
command_line::add_arg(desc_cmd_sett, command_line::arg_db_engine);
|
||||
command_line::add_arg(desc_cmd_sett, arg_alloc_win_console);
|
||||
command_line::add_arg(desc_cmd_sett, arg_html_folder);
|
||||
command_line::add_arg(desc_cmd_sett, arg_xcode_stub);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue