aboutsummaryrefslogtreecommitdiff
path: root/src/blockchain_db/berkeleydb/db_bdb.cpp
diff options
context:
space:
mode:
authorRiccardo Spagni <ric@spagni.net>2015-12-13 22:14:50 +0200
committerRiccardo Spagni <ric@spagni.net>2015-12-13 22:14:56 +0200
commitbdf738bc7ff996f95276fceb78c66c1aee19de08 (patch)
tree63f63c88aa91688ad9f9d394154471c038174d3a /src/blockchain_db/berkeleydb/db_bdb.cpp
parentMerge pull request #530 (diff)
parentcore_tests: fix ring_signature_1 tests (diff)
downloadmonero-bdf738bc7ff996f95276fceb78c66c1aee19de08.tar.xz
Merge pull request #531
cbded43 core_tests: fix ring_signature_1 tests (moneromooo-monero) c3d208f core_tests: bump default test fee to 0.02 monero (moneromooo-monero) 10da0a0 add a --fakechain argument for tests (moneromooo-monero) eee44e6 unit_tests: fix block reward test using post hard fork settings (moneromooo-monero) 595893f blockchain: log block (not chain) height in "BLOCK SUCCESFULLY ADDED" (moneromooo-monero) 2369968 blockchain: fix off by one in get_blocks (moneromooo-monero) 8af913a db_lmdb: implement BlockchainLMDB::reset (moneromooo-monero) 4833f4f db_bdb: implement BlockchainBDB::reset (moneromooo-monero) 18bf06e tx_pool: fix "minumim" typo in message (moneromooo-monero) 44f1267 tests: fix a typo in test name (moneromooo-monero) 1494557 db_lmdb: create all needed directories, not just the leaf one (moneromooo-monero) 015b68a db_bdb: create all needed directories, not just the leaf one (moneromooo-monero) f141869 tests: remove data-dir argument registration (moneromooo-monero)
Diffstat (limited to 'src/blockchain_db/berkeleydb/db_bdb.cpp')
-rw-r--r--src/blockchain_db/berkeleydb/db_bdb.cpp43
1 files changed, 41 insertions, 2 deletions
diff --git a/src/blockchain_db/berkeleydb/db_bdb.cpp b/src/blockchain_db/berkeleydb/db_bdb.cpp
index ce355ccde..07cb622a7 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()));
}
@@ -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<std::string> BlockchainBDB::get_filenames() const