Improve transaction lock details (#5193)

Summary:
This branch contains two small improvements:
* Create `LockMap` entries using `std::make_shared`. This saves one heap allocation per LockMap entry but also locates the control block and the LockMap object closely together in memory, which can help with caching
* Reorder the members of `TrackedTrxInfo`, so that the resulting struct uses less memory (at least on 64bit systems)
Pull Request resolved: https://github.com/facebook/rocksdb/pull/5193

Differential Revision: D14934536

Pulled By: maysamyabandeh

fbshipit-source-id: f7b49812bb4b6029eef9d131e7cd56260df5b28e
main
jsteemann 6 years ago committed by Facebook Github Bot
parent 29111e92b4
commit 8295d364e2
  1. 5
      utilities/transactions/transaction_lock_mgr.cc
  2. 3
      utilities/transactions/transaction_lock_mgr.h

@ -192,8 +192,7 @@ void TransactionLockMgr::AddColumnFamily(uint32_t column_family_id) {
if (lock_maps_.find(column_family_id) == lock_maps_.end()) { if (lock_maps_.find(column_family_id) == lock_maps_.end()) {
lock_maps_.emplace(column_family_id, lock_maps_.emplace(column_family_id,
std::shared_ptr<LockMap>( std::make_shared<LockMap>(default_num_stripes_, mutex_factory_));
new LockMap(default_num_stripes_, mutex_factory_)));
} else { } else {
// column_family already exists in lock map // column_family already exists in lock map
assert(false); assert(false);
@ -450,7 +449,7 @@ bool TransactionLockMgr::IncrementWaiters(
std::lock_guard<std::mutex> lock(wait_txn_map_mutex_); std::lock_guard<std::mutex> lock(wait_txn_map_mutex_);
assert(!wait_txn_map_.Contains(id)); assert(!wait_txn_map_.Contains(id));
wait_txn_map_.Insert(id, {wait_ids, cf_id, key, exclusive}); wait_txn_map_.Insert(id, {wait_ids, cf_id, exclusive, key});
for (auto wait_id : wait_ids) { for (auto wait_id : wait_ids) {
if (rev_wait_txn_map_.Contains(wait_id)) { if (rev_wait_txn_map_.Contains(wait_id)) {

@ -9,6 +9,7 @@
#include <chrono> #include <chrono>
#include <string> #include <string>
#include <unordered_map> #include <unordered_map>
#include <memory>
#include <utility> #include <utility>
#include <vector> #include <vector>
@ -44,8 +45,8 @@ struct DeadlockInfoBuffer {
struct TrackedTrxInfo { struct TrackedTrxInfo {
autovector<TransactionID> m_neighbors; autovector<TransactionID> m_neighbors;
uint32_t m_cf_id; uint32_t m_cf_id;
std::string m_waiting_key;
bool m_exclusive; bool m_exclusive;
std::string m_waiting_key;
}; };
class Slice; class Slice;

Loading…
Cancel
Save