diff --git a/src/common/db_abstract_accessor.h b/src/common/db_abstract_accessor.h index 1c86142c..9b84c9f8 100644 --- a/src/common/db_abstract_accessor.h +++ b/src/common/db_abstract_accessor.h @@ -241,9 +241,9 @@ namespace tools m_is_open = false; return m_backend->close(); } - bool open(const std::string& path, uint64_t cache_sz = CACHE_SIZE) + bool open(const std::string& path, uint64_t flags = 0) { - bool r = m_backend->open(path, cache_sz); + bool r = m_backend->open(path, flags); if(r) m_is_open = true; @@ -558,15 +558,30 @@ namespace tools bool init(const std::string& container_name) { #ifdef ENABLE_PROFILING - m_get_profiler.m_name = container_name +":get"; - m_set_profiler.m_name = container_name + ":set"; - m_explicit_get_profiler.m_name = container_name + ":explicit_get"; - m_explicit_set_profiler.m_name = container_name + ":explicit_set"; - m_commit_profiler.m_name = container_name + ":commit";; + m_get_profiler.m_name = container_name +":get"; + m_set_profiler.m_name = container_name + ":set"; + m_explicit_get_profiler.m_name = container_name + ":explicit_get"; + m_explicit_set_profiler.m_name = container_name + ":explicit_set"; + m_commit_profiler.m_name = container_name + ":commit"; #endif return bdb.get_backend()->open_container(container_name, m_h); } + bool deinit() + { +#ifdef ENABLE_PROFILING + m_get_profiler.m_name = ""; + m_set_profiler.m_name = ""; + m_explicit_get_profiler.m_name = ""; + m_explicit_set_profiler.m_name = ""; + m_commit_profiler.m_name = ""; +#endif + m_h = AUTO_VAL_INIT(m_h); + size_cache = 0; + size_cache_valid = false; + return true; + } + template void enumerate_keys(t_cb cb) const { diff --git a/src/common/db_backend_base.h b/src/common/db_backend_base.h index db566d86..e3187c82 100644 --- a/src/common/db_backend_base.h +++ b/src/common/db_backend_base.h @@ -1,17 +1,10 @@ -// Copyright (c) 2014-2018 Zano Project +// Copyright (c) 2014-2019 Zano Project // 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. #pragma once -#ifndef ENV32BIT -#define CACHE_SIZE uint64_t(uint64_t(1UL * 128UL) * 1024UL * 1024UL * 1024UL) -#else -#define CACHE_SIZE (1 * 1024UL * 1024UL * 1024UL) -#endif - - namespace tools { namespace db @@ -32,20 +25,20 @@ namespace tools struct i_db_backend { - virtual bool close()=0; + virtual bool close() = 0; virtual bool begin_transaction(bool read_only = false) = 0; - virtual bool commit_transaction()=0; - virtual void abort_transaction()=0; - virtual bool open(const std::string& path, uint64_t cache_sz = CACHE_SIZE) = 0; - virtual bool open_container(const std::string& name, container_handle& h)=0; + virtual bool commit_transaction() = 0; + virtual void abort_transaction() = 0; + virtual bool open(const std::string& path, uint64_t flags = 0) = 0; + virtual bool open_container(const std::string& name, container_handle& h) = 0; virtual bool erase(container_handle h, const char* k, size_t s) = 0; virtual uint64_t size(container_handle h) = 0; virtual bool get(container_handle h, const char* k, size_t s, std::string& res_buff) = 0; virtual bool set(container_handle h, const char* k, size_t s, const char* v, size_t vs) = 0; virtual bool clear(container_handle h) = 0; - virtual bool enumerate(container_handle h, i_db_callback* pcb)=0; + virtual bool enumerate(container_handle h, i_db_callback* pcb) = 0; virtual bool get_stat_info(stat_info& si) = 0; - virtual ~i_db_backend(){}; + virtual ~i_db_backend() {}; }; } -} \ No newline at end of file +} diff --git a/src/common/db_backend_lmdb.cpp b/src/common/db_backend_lmdb.cpp index 726b47a3..ceb46796 100644 --- a/src/common/db_backend_lmdb.cpp +++ b/src/common/db_backend_lmdb.cpp @@ -43,7 +43,7 @@ namespace tools NESTED_CATCH_ENTRY(__func__); } - bool lmdb_db_backend::open(const std::string& path_, uint64_t cache_sz) + bool lmdb_db_backend::open(const std::string& path_, uint64_t /* flags -- unused atm */) { int res = 0; res = mdb_env_create(&m_penv); @@ -60,23 +60,12 @@ namespace tools CHECK_AND_ASSERT_MES(tools::create_directories_if_necessary(m_path), false, "create_directories_if_necessary failed: " << m_path); + // TODO: convert flags to lmdb_flags (implement fast lmdb modes) unsigned int lmdb_flags = MDB_NORDAHEAD /*| MDB_NOSYNC | MDB_WRITEMAP | MDB_MAPASYNC*/; mdb_mode_t lmdb_mode = 0644; res = mdb_env_open(m_penv, m_path.c_str(), lmdb_flags, lmdb_mode); - if (res != MDB_SUCCESS) - { - // DB created with prev LMDB 0.9.18 cannot be opened due to huge map size set in env - // try to remove DB folder completely and re-open - boost::filesystem::remove_all(m_path); - CHECK_AND_ASSERT_MES(tools::create_directories_if_necessary(m_path), false, "create_directories_if_necessary failed: " << m_path); - res = mdb_env_create(&m_penv); - CHECK_AND_ASSERT_MESS_LMDB_DB(res, false, "Unable to mdb_env_create"); - res = mdb_env_set_maxdbs(m_penv, max_dbs); - CHECK_AND_ASSERT_MESS_LMDB_DB(res, false, "Unable to mdb_env_set_maxdbs"); - res = mdb_env_open(m_penv, m_path.c_str(), lmdb_flags, lmdb_mode); - CHECK_AND_ASSERT_MESS_LMDB_DB(res, false, "Unable to mdb_env_open, m_path=" << m_path); - } + CHECK_AND_ASSERT_MESS_LMDB_DB(res, false, "Unable to mdb_env_open, m_path=" << m_path); resize_if_needed(); diff --git a/src/common/db_backend_lmdb.h b/src/common/db_backend_lmdb.h index 987f61e1..84c441d3 100644 --- a/src/common/db_backend_lmdb.h +++ b/src/common/db_backend_lmdb.h @@ -52,7 +52,7 @@ namespace tools bool begin_transaction(bool read_only = false); bool commit_transaction(); void abort_transaction(); - bool open(const std::string& path, uint64_t cache_sz = CACHE_SIZE); + bool open(const std::string& path, uint64_t flags = 0); bool open_container(const std::string& name, container_handle& h); bool erase(container_handle h, const char* k, size_t s); bool get(container_handle h, const char* k, size_t s, std::string& res_buff);