Skip to content

Commit

Permalink
Improve transaction lock details (facebook#5193)
Browse files Browse the repository at this point in the history
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: facebook#5193

Differential Revision: D14934536

Pulled By: maysamyabandeh

fbshipit-source-id: f7b49812bb4b6029eef9d131e7cd56260df5b28e
  • Loading branch information
jsteemann authored and facebook-github-bot committed Apr 15, 2019
1 parent 29111e9 commit 8295d36
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
5 changes: 2 additions & 3 deletions utilities/transactions/transaction_lock_mgr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,7 @@ void TransactionLockMgr::AddColumnFamily(uint32_t column_family_id) {

if (lock_maps_.find(column_family_id) == lock_maps_.end()) {
lock_maps_.emplace(column_family_id,
std::shared_ptr<LockMap>(
new LockMap(default_num_stripes_, mutex_factory_)));
std::make_shared<LockMap>(default_num_stripes_, mutex_factory_));
} else {
// column_family already exists in lock map
assert(false);
Expand Down Expand Up @@ -450,7 +449,7 @@ bool TransactionLockMgr::IncrementWaiters(
std::lock_guard<std::mutex> lock(wait_txn_map_mutex_);
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) {
if (rev_wait_txn_map_.Contains(wait_id)) {
Expand Down
3 changes: 2 additions & 1 deletion utilities/transactions/transaction_lock_mgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <chrono>
#include <string>
#include <unordered_map>
#include <memory>
#include <utility>
#include <vector>

Expand Down Expand Up @@ -44,8 +45,8 @@ struct DeadlockInfoBuffer {
struct TrackedTrxInfo {
autovector<TransactionID> m_neighbors;
uint32_t m_cf_id;
std::string m_waiting_key;
bool m_exclusive;
std::string m_waiting_key;
};

class Slice;
Expand Down

0 comments on commit 8295d36

Please sign in to comment.