Zero  0.1.0
Public Member Functions | Static Private Member Functions | Private Attributes | List of all members
RawXctLockHashMap Class Reference

A hashmap for lock entries in transaction's private memory. More...

#include <lock_raw.h>

Public Member Functions

 RawXctLockHashMap ()
 
 ~RawXctLockHashMap ()
 
okvl_mode get_granted_mode (uint32_t lock_id) const
 Returns the lock granted to this transaction for the given lock ID. More...
 
void reset ()
 
void push_front (RawLock *link)
 
void remove (RawLock *link)
 

Static Private Member Functions

static uint32_t _bucket_id (uint32_t lock_id)
 

Private Attributes

RawLock_buckets [RAW_XCT_LOCK_HASHMAP_SIZE]
 

Detailed Description

A hashmap for lock entries in transaction's private memory.

Overview

This auxiliary data structure is to efficiently check what locks the transaction has already acquired. Because this is a transaction-private data structure and there is no multi-threads-per-transaction feature, we don't need any synchronization to access this. It uses no spinlock/mutex and is preferrable especially in multi-socket environment.

Multi-thread safety

get_granted_mode(), the method used from lock_m::lock(), has a precondition that says it must be called from the transaction's thread. The precondition is important because we don't take latch in get_granted_mode() nor return a copied lock mode (returns reference). As "this" is the only thread that might change granted mode of the lock entry or change the bucket's linked list, this is safe.

History

In original Shore-MT, there was only linked list. So, in order to check if a transaction already has some lock, we had to query the public lock table, entering critical sections. Further, Shore-MT had a feature to run a single transaction on multi-threads. There was no truly "private" memory back then for this reason. We found this causes an issue in NUMA environment, and made this private hashmap.

Performance Comparison

As of 20140213, with and without this improvement, TPCC on 4-socket machine is as follows: BEFORE=12027 TPS, AFTER=13764 TPS.

Note
yes, it's a copy-paste from XctLockHashMap, but this would be the only implementation.

Constructor & Destructor Documentation

§ RawXctLockHashMap()

RawXctLockHashMap::RawXctLockHashMap ( )

§ ~RawXctLockHashMap()

RawXctLockHashMap::~RawXctLockHashMap ( )

Member Function Documentation

§ _bucket_id()

static uint32_t RawXctLockHashMap::_bucket_id ( uint32_t  lock_id)
inlinestaticprivate

Returns the bucket index for the lock.

§ get_granted_mode()

okvl_mode RawXctLockHashMap::get_granted_mode ( uint32_t  lock_id) const

Returns the lock granted to this transaction for the given lock ID.

Parameters
[in]lock_ididentifier of the lock entry
Returns
the lock mode this transaction has for the lock. ALL_N_GAP_N if not any.
Precondition
the current thread is the only thread running the transaction of this hashmap

§ push_front()

void RawXctLockHashMap::push_front ( RawLock link)

Add a new entry to this hashmap.

§ remove()

void RawXctLockHashMap::remove ( RawLock link)

Removes the entry from this hashmap.

§ reset()

void RawXctLockHashMap::reset ( )

Clears hash buckets.

Member Data Documentation

§ _buckets

RawLock* RawXctLockHashMap::_buckets[RAW_XCT_LOCK_HASHMAP_SIZE]
private

Hash buckets. In each bucket, we have a doubly-linked list of xct_lock_entry_t.


The documentation for this class was generated from the following files: