18 #ifndef FOEDUS_THREAD_THREAD_HPP_
19 #define FOEDUS_THREAD_THREAD_HPP_
111 return reinterpret_cast<P*
>(
resolve(ptr));
117 return reinterpret_cast<P*
>(
resolve(offset));
205 bool tolerate_null_pointer,
207 bool take_ptr_set_snapshot,
211 uint16_t index_in_parent);
237 bool tolerate_null_pointer,
238 bool take_ptr_set_snapshot,
241 const uint16_t* index_in_parents,
242 bool* followed_snapshots,
263 const uint16_t* index_in_parents,
394 : context_(context), offsets_(offsets), count_(0) {}
415 return offsets_[index];
426 #endif // FOEDUS_THREAD_THREAD_HPP_
friend std::ostream & operator<<(std::ostream &o, const Thread &v)
const memory::GlobalVolatilePageResolver & get_global_volatile_page_resolver() const
Returns the page resolver to convert page ID to page pointer.
xct::Xct & get_current_xct()
Returns the transaction that is currently running on this thread.
ErrorCode find_or_read_a_snapshot_page(storage::SnapshotPagePointer page_id, storage::Page **out)
Find the given page in snapshot cache, reading it if not found.
ErrorStack initialize() override
Acquires resources in this object, usually called right after constructor.
ThreadGlobalOrdinal get_thread_global_ordinal() const
ErrorCode install_a_volatile_page(storage::DualPagePointer *pointer, storage::Page **installed_page)
Installs a volatile page to the given dual pointer as a copy of the snapshot page.
Represents a pointer to another page (usually a child page).
ErrorCode find_or_read_snapshot_pages_batch(uint16_t batch_size, const storage::SnapshotPagePointer *page_ids, storage::Page **out)
Batched version of find_or_read_a_snapshot_page().
memory::NumaCoreMemory * get_thread_memory() const
Returns the private memory repository of this thread.
ErrorCode follow_page_pointers_for_write_batch(uint16_t batch_size, storage::VolatilePageInit page_initializer, storage::DualPagePointer **pointers, storage::Page **parents, const uint16_t *index_in_parents, storage::Page **out)
Batched version of follow_page_pointer with will_modify==true and tolerate_null_pointer==true.
uint64_t get_snapshot_cache_misses() const
[statistics] count of cache misses in snapshot caches
Definitions of IDs in this package and a few related constant values.
A thread-local log buffer.
The pure-virtual interface to initialize/uninitialize non-trivial resources.
Forward declarations of classes in log manager package.
ErrorCode sysxct_batch_page_locks(xct::SysxctWorkspace *sysxct_workspace, uint32_t lock_count, storage::Page **pages)
Takes a bunch of page locks for a sysxct running under this thread.
ErrorCode cll_try_or_acquire_single_lock(xct::LockListPosition pos)
Methods related to Current Lock List (CLL) These are the only interface in Thread to lock records...
Root package of FOEDUS (Fast Optimistic Engine for Data Unification Services).
ErrorCode sysxct_batch_record_locks(xct::SysxctWorkspace *sysxct_workspace, storage::VolatilePagePointer page_id, uint32_t lock_count, xct::RwLockableXctId **locks)
Takes a bunch of locks in the same page for a sysxct running under this thread.
ErrorCode sysxct_record_lock(xct::SysxctWorkspace *sysxct_workspace, storage::VolatilePagePointer page_id, xct::RwLockableXctId *lock)
Takes a lock for a sysxct running under this thread.
Represents one thread running on one NUMA core.
uint32_t PagePoolOffset
Offset in PagePool that compactly represents the page address (unlike 8 bytes pointer).
Typedefs of ID types used in thread package.
void collect_retired_volatile_page(storage::VolatilePagePointer ptr)
Keeps the specified volatile page as retired as of the current epoch.
xct::McsRwExtendedBlock * get_mcs_rw_extended_blocks()
bool is_initialized() const override
Returns whether the object has been already initialized or not.
memory::NumaNodeMemory * get_node_memory() const
Returns the node-shared memory repository of the NUMA node this thread belongs to.
Forward declarations of classes in transaction package.
ThreadId get_thread_id() const
Represents a pointer to a volatile page with modification count for preventing ABA.
Represents a user transaction.
Forward declarations of classes in root package.
Brings error stacktrace information as return value of functions.
Reader-writer (RW) MCS lock classes.
ErrorCode follow_page_pointer(storage::VolatilePageInit page_initializer, bool tolerate_null_pointer, bool will_modify, bool take_ptr_set_snapshot, storage::DualPagePointer *pointer, storage::Page **page, const storage::Page *parent, uint16_t index_in_parent)
A general method to follow (read) a page pointer.
Max size for find_or_read_snapshot_pages_batch() etc.
void cll_release_all_locks_at_and_after(xct::UniversalLockId address)
same as mcs_release_all_current_locks_after(address - 1)
~GrabFreeVolatilePagesScope()
void cll_giveup_all_locks_at_and_after(xct::UniversalLockId address)
Engine * get_engine() const
storage::Page * resolve_newpage(storage::VolatilePagePointer ptr) const
Shorthand for get_global_volatile_page_resolver.resolve_offset_newpage()
Epoch * get_in_commit_epoch_address()
Currently we don't have sysxct_release_locks() etc.
Repository of memories dynamically acquired within one CPU core (thread).
ThreadPimpl * get_pimpl() const
Returns the pimpl of this object.
ErrorCode grab(uint32_t count)
If this thread doesn't have enough free pages, no page is obtained, returning kErrorCodeMemoryNoFreeP...
uintptr_t UniversalLockId
Universally ordered identifier of each lock.
The MCS reader-writer lock variant of LockableXctId.
storage::Page * resolve(storage::VolatilePagePointer ptr) const
Shorthand for get_global_volatile_page_resolver.resolve_offset()
log::ThreadLogBuffer & get_thread_log_buffer()
Returns the private log buffer for this thread.
P * resolve_newpage_cast(memory::PagePoolOffset offset) const
A functor representing the logic in a system transaction via virtual-function.
void dispatch(uint32_t index)
Call this when the page is placed somewhere.
P * resolve_newpage_cast(storage::VolatilePagePointer ptr) const
Forward declarations of classes in storage package.
Definitions of IDs in this package and a few related constant values.
bool is_running_xct() const
Returns if this thread is running an active transaction.
ErrorCode sysxct_page_lock(xct::SysxctWorkspace *sysxct_workspace, storage::Page *page)
Takes a page lock in the same page for a sysxct running under this thread.
#define CXX11_FINAL
Used in public headers in place of "final" of C++11.
uint32_t LockListPosition
Index in a lock-list, either RLL or CLL.
uint64_t SnapshotPagePointer
Page ID of a snapshot page.
void cll_release_all_locks()
Pre-allocated MCS block for extended version of RW-locks.
ErrorCode follow_page_pointers_for_read_batch(uint16_t batch_size, storage::VolatilePageInit page_initializer, bool tolerate_null_pointer, bool take_ptr_set_snapshot, storage::DualPagePointer **pointers, storage::Page **parents, const uint16_t *index_in_parents, bool *followed_snapshots, storage::Page **out)
Batched version of follow_page_pointer with will_modify==false.
Database engine object that holds all resources and provides APIs.
Repository of memories dynamically acquired and shared within one NUMA node (socket).
Just a marker to denote that the memory region represents a data page.
void cll_release_all_locks_after(xct::UniversalLockId address)
Release all locks in CLL of this thread whose addresses are canonically ordered before the parameter...
void cll_giveup_all_locks_after(xct::UniversalLockId address)
This gives-up locks in CLL that are not yet taken.
P * resolve_cast(memory::PagePoolOffset offset) const
ThreadGroupId decompose_numa_node(ThreadId global_id)
Extracts NUMA node ID from the given globally unique ID of Thread (core).
P * resolve_cast(storage::VolatilePagePointer ptr) const
resolve() plus reinterpret_cast
void reset_snapshot_cache_counts() const
[statistics] resets the above two
bool is_hot_page(const storage::Page *page) const
const memory::LocalPageResolver & get_local_volatile_page_resolver() const
Returns page resolver to convert only local page ID to page pointer.
uint64_t get_snapshot_cache_hits() const
[statistics] count of cache hits in snapshot caches
Forward declarations of classes in memory package.
#define CXX11_OVERRIDE
Used in public headers in place of "override" of C++11.
void release()
Idempotent.
uint16_t ThreadGlobalOrdinal
Typedef for a globally and contiguously numbered ID of thread.
#define CXX11_FUNC_DELETE
Used in public headers in place of " = delete" of C++11.
uint16_t ThreadId
Typedef for a global ID of Thread (core), which is unique across NUMA nodes.
xct::McsRwSimpleBlock * get_mcs_rw_simple_blocks()
Unconditionally takes MCS lock on the given mcs_lock.
ThreadGroupId get_numa_node() const
assorted::UniformRandom & get_lock_rnd()
void(* VolatilePageInit)(const VolatilePageInitArguments &args)
A function pointer to initialize a volatile page.
ErrorStack uninitialize() override
An idempotent method to release all resources of this object, if any.
#define ASSERT_ND(x)
A warning-free wrapper macro of assert() that has no performance effect in release mode even when 'x'...
ErrorCode run_nested_sysxct(xct::SysxctFunctor *functor, uint32_t max_retries=0)
Methods related to System transactions (sysxct) nested under this thread.
Forward declarations of classes in thread package.
uint8_t ThreadGroupId
Typedef for an ID of ThreadGroup (NUMA node).
Obtains multiple free volatile pages at once and releases them automatically when this object gets ou...
GrabFreeVolatilePagesScope(Thread *context, memory::PagePoolOffset *offsets)
ErrorCode
Enum of error codes defined in error_code.xmacro.
ErrorCode read_snapshot_pages(storage::SnapshotPagePointer page_id_begin, uint32_t page_count, storage::Page *buffer)
Read contiguous pages in one shot.
Per-thread reused work memory for system transactions.
const UniversalLockId kNullUniversalLockId
This never points to a valid lock, and also evaluates less than any vaild alocks. ...
ErrorCode cll_try_or_acquire_multiple_locks(xct::LockListPosition upto_pos)
Acquire multiple locks up to the given position in canonical order.
ErrorCode read_a_snapshot_page(storage::SnapshotPagePointer page_id, storage::Page *buffer)
Read a snapshot page using the thread-local file descriptor set.
uint32_t get_count() const