From 015b68a2bea655f957ee3279b76a62604d6096f7 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Sun, 13 Dec 2015 11:08:59 +0000 Subject: db_bdb: create all needed directories, not just the leaf one --- src/blockchain_db/berkeleydb/db_bdb.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/blockchain_db') diff --git a/src/blockchain_db/berkeleydb/db_bdb.cpp b/src/blockchain_db/berkeleydb/db_bdb.cpp index ce355ccde..f30e156c1 100644 --- a/src/blockchain_db/berkeleydb/db_bdb.cpp +++ b/src/blockchain_db/berkeleydb/db_bdb.cpp @@ -759,7 +759,7 @@ void BlockchainBDB::open(const std::string& filename, const int db_flags) } else { - if (!boost::filesystem::create_directory(direc)) + if (!boost::filesystem::create_directories(direc)) throw0(DB_OPEN_FAILURE(std::string("Failed to create directory ").append(filename).c_str())); } -- cgit v1.2.3 From 14945576335a3e5aa292a4af61d37e9ef88e7858 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Sun, 13 Dec 2015 11:09:43 +0000 Subject: db_lmdb: create all needed directories, not just the leaf one --- src/blockchain_db/lmdb/db_lmdb.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/blockchain_db') diff --git a/src/blockchain_db/lmdb/db_lmdb.cpp b/src/blockchain_db/lmdb/db_lmdb.cpp index de8066123..2bddcc6f5 100644 --- a/src/blockchain_db/lmdb/db_lmdb.cpp +++ b/src/blockchain_db/lmdb/db_lmdb.cpp @@ -943,7 +943,7 @@ void BlockchainLMDB::open(const std::string& filename, const int mdb_flags) } else { - if (!boost::filesystem::create_directory(direc)) + if (!boost::filesystem::create_directories(direc)) throw0(DB_OPEN_FAILURE(std::string("Failed to create directory ").append(filename).c_str())); } -- cgit v1.2.3 From 4833f4f96f4aa97cc01c672a71e76a32caf9efa0 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Sun, 13 Dec 2015 11:12:00 +0000 Subject: db_bdb: implement BlockchainBDB::reset It is needed by the core tests --- src/blockchain_db/berkeleydb/db_bdb.cpp | 41 ++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) (limited to 'src/blockchain_db') diff --git a/src/blockchain_db/berkeleydb/db_bdb.cpp b/src/blockchain_db/berkeleydb/db_bdb.cpp index f30e156c1..07cb622a7 100644 --- a/src/blockchain_db/berkeleydb/db_bdb.cpp +++ b/src/blockchain_db/berkeleydb/db_bdb.cpp @@ -1042,7 +1042,46 @@ void BlockchainBDB::sync() void BlockchainBDB::reset() { LOG_PRINT_L3("BlockchainBDB::" << __func__); - // TODO: this + check_open(); + + bdb_txn_safe txn; + if (m_env->txn_begin(NULL, txn, 0)) + throw0(DB_ERROR("Failed to create a transaction for the db")); + m_write_txn = &txn; + try + { + uint32_t count; + + m_blocks->truncate(*m_write_txn, &count, 0); + m_block_heights->truncate(*m_write_txn, &count, 0); + m_block_hashes->truncate(*m_write_txn, &count, 0); + m_block_timestamps->truncate(*m_write_txn, &count, 0); + m_block_sizes->truncate(*m_write_txn, &count, 0); + m_block_diffs->truncate(*m_write_txn, &count, 0); + m_block_coins->truncate(*m_write_txn, &count, 0); + + m_txs->truncate(*m_write_txn, &count, 0); + m_tx_unlocks->truncate(*m_write_txn, &count, 0); + m_tx_heights->truncate(*m_write_txn, &count, 0); + m_tx_outputs->truncate(*m_write_txn, &count, 0); + + m_output_txs->truncate(*m_write_txn, &count, 0); + m_output_indices->truncate(*m_write_txn, &count, 0); + m_output_amounts->truncate(*m_write_txn, &count, 0); + m_output_keys->truncate(*m_write_txn, &count, 0); + + m_spent_keys->truncate(*m_write_txn, &count, 0); + + m_hf_starting_heights->truncate(*m_write_txn, &count, 0); + m_hf_versions->truncate(*m_write_txn, &count, 0); + + m_properties->truncate(*m_write_txn, &count, 0); + } + catch (const std::exception& e) + { + throw0(DB_ERROR(std::string("Failed to reset database: ").append(e.what()).c_str())); + } + m_write_txn = NULL; } std::vector BlockchainBDB::get_filenames() const -- cgit v1.2.3 From 8af913a3d183b9f30106caaedba007c055ad945e Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Sun, 13 Dec 2015 11:12:34 +0000 Subject: db_lmdb: implement BlockchainLMDB::reset It is needed by the core tests --- src/blockchain_db/lmdb/db_lmdb.cpp | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'src/blockchain_db') diff --git a/src/blockchain_db/lmdb/db_lmdb.cpp b/src/blockchain_db/lmdb/db_lmdb.cpp index 2bddcc6f5..62f1b39f1 100644 --- a/src/blockchain_db/lmdb/db_lmdb.cpp +++ b/src/blockchain_db/lmdb/db_lmdb.cpp @@ -1159,7 +1159,33 @@ void BlockchainLMDB::sync() void BlockchainLMDB::reset() { LOG_PRINT_L3("BlockchainLMDB::" << __func__); - // TODO: this + check_open(); + + mdb_txn_safe txn; + if (mdb_txn_begin(m_env, NULL, 0, txn)) + throw0(DB_ERROR("Failed to create a transaction for the db")); + mdb_drop(txn, m_blocks, 0); + mdb_drop(txn, m_block_timestamps, 0); + mdb_drop(txn, m_block_heights, 0); + mdb_drop(txn, m_block_hashes, 0); + mdb_drop(txn, m_block_sizes, 0); + mdb_drop(txn, m_block_diffs, 0); + mdb_drop(txn, m_block_coins, 0); + mdb_drop(txn, m_txs, 0); + mdb_drop(txn, m_tx_unlocks, 0); + mdb_drop(txn, m_tx_heights, 0); + mdb_drop(txn, m_tx_outputs, 0); + mdb_drop(txn, m_output_txs, 0); + mdb_drop(txn, m_output_indices, 0); + mdb_drop(txn, m_output_amounts, 0); + mdb_drop(txn, m_output_keys, 0); + mdb_drop(txn, m_spent_keys, 0); + mdb_drop(txn, m_hf_starting_heights, 0); + mdb_drop(txn, m_hf_versions, 0); + mdb_drop(txn, m_properties, 0); + txn.commit(); + m_height = 0; + m_num_outputs = 0; } std::vector BlockchainLMDB::get_filenames() const -- cgit v1.2.3