forked from lthn/blockchain
db: added close_container() to backend, call it at basic_key_value_accessor::deinit(), added "override" keyword
This commit is contained in:
parent
1586f53e85
commit
79dd5dab04
6 changed files with 60 additions and 31 deletions
|
|
@ -584,10 +584,13 @@ namespace tools
|
|||
m_explicit_set_profiler.m_name = "";
|
||||
m_commit_profiler.m_name = "";
|
||||
#endif
|
||||
bool r = true;
|
||||
if (m_h)
|
||||
r = bdb.get_backend()->close_container(m_h);
|
||||
m_h = AUTO_VAL_INIT(m_h);
|
||||
size_cache = 0;
|
||||
size_cache_valid = false;
|
||||
return true;
|
||||
return r;
|
||||
}
|
||||
|
||||
template<class t_cb>
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@ namespace tools
|
|||
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 close_container(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;
|
||||
|
|
|
|||
|
|
@ -59,7 +59,6 @@ namespace tools
|
|||
|
||||
bool lmdb_db_backend::open_container(const std::string& name, container_handle& h)
|
||||
{
|
||||
|
||||
MDB_dbi dbi = AUTO_VAL_INIT(dbi);
|
||||
begin_transaction();
|
||||
int res = mdb_dbi_open(get_current_tx(), name.c_str(), MDB_CREATE, &dbi);
|
||||
|
|
@ -69,6 +68,18 @@ namespace tools
|
|||
return true;
|
||||
}
|
||||
|
||||
bool lmdb_db_backend::close_container(container_handle& h)
|
||||
{
|
||||
static const container_handle null_handle = AUTO_VAL_INIT(null_handle);
|
||||
CHECK_AND_ASSERT_MES(h != null_handle, false, "close_container is called for null container handle");
|
||||
MDB_dbi dbi = static_cast<MDB_dbi>(h);
|
||||
begin_transaction();
|
||||
mdb_dbi_close(m_penv, dbi);
|
||||
commit_transaction();
|
||||
h = null_handle;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool lmdb_db_backend::close()
|
||||
{
|
||||
{
|
||||
|
|
|
|||
|
|
@ -41,20 +41,21 @@ namespace tools
|
|||
~lmdb_db_backend();
|
||||
|
||||
//----------------- i_db_backend -----------------------------------------------------
|
||||
bool close();
|
||||
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_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);
|
||||
bool clear(container_handle h);
|
||||
uint64_t size(container_handle h);
|
||||
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 close() override;
|
||||
bool begin_transaction(bool read_only = false) override;
|
||||
bool commit_transaction() override;
|
||||
void abort_transaction() override;
|
||||
bool open(const std::string& path, uint64_t cache_sz = CACHE_SIZE) override;
|
||||
bool open_container(const std::string& name, container_handle& h) override;
|
||||
bool close_container(container_handle& h) override;
|
||||
bool erase(container_handle h, const char* k, size_t s) override;
|
||||
bool get(container_handle h, const char* k, size_t s, std::string& res_buff) override;
|
||||
bool clear(container_handle h) override;
|
||||
uint64_t size(container_handle h) override;
|
||||
bool set(container_handle h, const char* k, size_t s, const char* v, size_t vs) override;
|
||||
bool enumerate(container_handle h, i_db_callback* pcb) override;
|
||||
bool get_stat_info(tools::db::stat_info& si) override;
|
||||
const char* name() override;
|
||||
//-------------------------------------------------------------------------------------
|
||||
bool have_tx();
|
||||
MDB_txn* get_current_tx();
|
||||
|
|
|
|||
|
|
@ -66,7 +66,6 @@ namespace tools
|
|||
|
||||
bool mdbx_db_backend::open_container(const std::string& name, container_handle& h)
|
||||
{
|
||||
|
||||
MDBX_dbi dbi = AUTO_VAL_INIT(dbi);
|
||||
begin_transaction();
|
||||
int res = mdbx_dbi_open(get_current_tx(), name.c_str(), MDBX_CREATE, &dbi);
|
||||
|
|
@ -76,6 +75,19 @@ namespace tools
|
|||
return true;
|
||||
}
|
||||
|
||||
bool mdbx_db_backend::close_container(container_handle& h)
|
||||
{
|
||||
static const container_handle null_handle = AUTO_VAL_INIT(null_handle);
|
||||
CHECK_AND_ASSERT_MES(h != null_handle, false, "close_container is called for null container handle");
|
||||
|
||||
MDBX_dbi dbi = static_cast<MDBX_dbi>(h);
|
||||
begin_transaction();
|
||||
mdbx_dbi_close(m_penv, dbi);
|
||||
commit_transaction();
|
||||
h = null_handle;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool mdbx_db_backend::close()
|
||||
{
|
||||
{
|
||||
|
|
|
|||
|
|
@ -41,20 +41,21 @@ namespace tools
|
|||
~mdbx_db_backend();
|
||||
|
||||
//----------------- i_db_backend -----------------------------------------------------
|
||||
bool close();
|
||||
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_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);
|
||||
bool clear(container_handle h);
|
||||
uint64_t size(container_handle h);
|
||||
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 close() override;
|
||||
bool begin_transaction(bool read_only = false) override;
|
||||
bool commit_transaction() override;
|
||||
void abort_transaction() override;
|
||||
bool open(const std::string& path, uint64_t cache_sz = CACHE_SIZE) override;
|
||||
bool open_container(const std::string& name, container_handle& h) override;
|
||||
bool close_container(container_handle& h) override;
|
||||
bool erase(container_handle h, const char* k, size_t s) override;
|
||||
bool get(container_handle h, const char* k, size_t s, std::string& res_buff) override;
|
||||
bool clear(container_handle h) override;
|
||||
uint64_t size(container_handle h) override;
|
||||
bool set(container_handle h, const char* k, size_t s, const char* v, size_t vs) override;
|
||||
bool enumerate(container_handle h, i_db_callback* pcb) override;
|
||||
bool get_stat_info(tools::db::stat_info& si) override;
|
||||
const char* name() override;
|
||||
//-------------------------------------------------------------------------------------
|
||||
bool have_tx();
|
||||
MDBX_txn* get_current_tx();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue