diff options
author | Howard Chu <hyc@symas.com> | 2016-01-07 13:23:12 +0000 |
---|---|---|
committer | Howard Chu <hyc@symas.com> | 2016-02-17 04:05:29 +0000 |
commit | f2faf8cdd9efd3ff044d3f67d5cae62addfec679 (patch) | |
tree | ef8ad896adc89caef582e71af17073e53e834f0d /src/blockchain_db | |
parent | Use cursors in write txns (diff) | |
download | monero-f2faf8cdd9efd3ff044d3f67d5cae62addfec679.tar.xz |
Use MDB_APPEND mode where possible
When keys are contiguous and monotonically increasing, this gets
denser page utilization (doesn't leave padding in page splits).
Can't be used for keys that are inserted in random order (e.g. hashes)
In total this only saves around 1.5% of space compared to original
DB code. The previous patch accounted for 0.8% savings on its own;
the blocks tables just aren't that big.
Diffstat (limited to 'src/blockchain_db')
-rw-r--r-- | src/blockchain_db/lmdb/db_lmdb.cpp | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/src/blockchain_db/lmdb/db_lmdb.cpp b/src/blockchain_db/lmdb/db_lmdb.cpp index 2017ccb43..805b56ef4 100644 --- a/src/blockchain_db/lmdb/db_lmdb.cpp +++ b/src/blockchain_db/lmdb/db_lmdb.cpp @@ -707,7 +707,7 @@ void BlockchainLMDB::add_output(const crypto::hash& tx_hash, const tx_out& tx_ou MDB_val_copy<uint64_t> k(m_num_outputs); MDB_val_copy<crypto::hash> v(tx_hash); - result = mdb_cursor_put(m_cur_output_txs, &k, &v, 0); + result = mdb_cursor_put(m_cur_output_txs, &k, &v, MDB_APPEND); if (result) throw0(DB_ERROR(std::string("Failed to add output tx hash to db transaction: ").append(mdb_strerror(result)).c_str())); result = mdb_cursor_put(m_cur_tx_outputs, &v, &k, 0); @@ -715,7 +715,7 @@ void BlockchainLMDB::add_output(const crypto::hash& tx_hash, const tx_out& tx_ou throw0(DB_ERROR(std::string("Failed to add <tx hash, global output index> to db transaction: ").append(mdb_strerror(result)).c_str())); MDB_val_copy<uint64_t> val_local_index(local_index); - result = mdb_cursor_put(m_cur_output_indices, &k, &val_local_index, 0); + result = mdb_cursor_put(m_cur_output_indices, &k, &val_local_index, MDB_APPEND); if (result) throw0(DB_ERROR(std::string("Failed to add tx output index to db transaction: ").append(mdb_strerror(result)).c_str())); @@ -733,7 +733,7 @@ void BlockchainLMDB::add_output(const crypto::hash& tx_hash, const tx_out& tx_ou MDB_val_copy<output_data_t> data(od); //MDB_val_copy<crypto::public_key> val_pubkey(boost::get<txout_to_key>(tx_output.target).key); - if (mdb_cursor_put(m_cur_output_keys, &k, &data, 0)) + if (mdb_cursor_put(m_cur_output_keys, &k, &data, MDB_APPEND)) throw0(DB_ERROR("Failed to add output pubkey to db transaction")); } else @@ -2615,7 +2615,7 @@ void BlockchainLMDB::set_hard_fork_starting_height(uint8_t version, uint64_t hei MDB_val_copy<uint8_t> val_key(version); MDB_val_copy<uint64_t> val_value(height); - if (auto result = mdb_put(*txn_ptr, m_hf_starting_heights, &val_key, &val_value, 0)) + if (auto result = mdb_put(*txn_ptr, m_hf_starting_heights, &val_key, &val_value, MDB_APPEND)) throw1(DB_ERROR(std::string("Error adding hard fork starting height to db transaction: ").append(mdb_strerror(result)).c_str())); TXN_BLOCK_POSTFIX_SUCCESS(); @@ -2650,7 +2650,11 @@ void BlockchainLMDB::set_hard_fork_version(uint64_t height, uint8_t version) MDB_val_copy<uint64_t> val_key(height); MDB_val_copy<uint8_t> val_value(version); - if (auto result = mdb_put(*txn_ptr, m_hf_versions, &val_key, &val_value, 0)) + int result; + result = mdb_put(*txn_ptr, m_hf_versions, &val_key, &val_value, MDB_APPEND); + if (result == MDB_KEYEXIST) + result = mdb_put(*txn_ptr, m_hf_versions, &val_key, &val_value, 0); + if (result) throw1(DB_ERROR(std::string("Error adding hard fork version to db transaction: ").append(mdb_strerror(result)).c_str())); TXN_BLOCK_POSTFIX_SUCCESS(); |