SwatDB
|
#include <bm_policies.h>
Public Member Functions | |
Clock (Frame *frame_table) | |
Clock constructor. Initializes pointer to buffer manager's frame_table, creates the free list, sets clock_hand, rep_calls, and avg_frames_checked to 0, and sets all ref_bits to false. | |
~Clock () | |
FrameId | replace () |
Method that implements core replacement policy functionality of the clock replacement policy. | |
void | pin (FrameId frame_id) |
Frame is being pinned with pin count going from 0 to 1. Clock policy has nothing to do here, but an empty method must exist for BufferManager to call. | |
void | unpin (FrameId frame_id) |
Frame is being unpinned with pin count going from 1 to 0. Set the ref_bit associated with this frame_id to true. | |
void | getRepStats (struct BufferState::ReplacementStats *rep_stats) |
Updates the struct of replacement policy statistics within the buffer state struct. Adds the replacement type, number of calls to the replacement policy, average frames checked by each call to policy, the ref_bit count and clock_hand, and new page calls. | |
void | freeFrame (FrameId frame_id) |
The frame is invalidated in the buffer manager, and is added to the free list of frames in the replacement policy. Ref_bit associated with this frame is set to false. | |
void | printFrame (FrameId frame_id) |
THIS METHOD IS FOR DEBUGGING ONLY. Prints Frame state, including pin count and ref_bit. | |
void | printStats () |
Prints clock_hand, average frames checked, replacement calls, how many frames have ref_bit set. | |
Public Member Functions inherited from ReplacementPolicy | |
virtual | ~ReplacementPolicy () |
Empty Destructor. | |
void | printFrame (FrameId frame_id) |
THIS METHOD IS FOR DEBUGGING ONLY. Prints Frame state relevant to the replacement policy of a given FrameId, including pin count and ref_bit for Clock Replacement. | |
void | advanceCalls () |
Increment new_page_calls by 1. Called in both allocatePage and getPage in BufferManager. | |
Private Member Functions | |
void | _advanceClock () |
Increments the clock hand according to the clock replacement policy. | |
RepType | _getType () |
Derived class from pure virtual function that returns replacement policy type specific to this derived class. | |
Private Attributes | |
std::uint32_t | clock_hand |
bool | ref_table [BUF_SIZE] |
Additional Inherited Members | |
Protected Member Functions inherited from ReplacementPolicy | |
void | _createFree () |
Creates a free list for the buffer pool by checking each frame in the buffer pool and checking if it is valid. Used in constructor of each replacement policy. | |
Protected Attributes inherited from ReplacementPolicy | |
Frame * | frame_table |
std::queue< FrameId > | free |
std::uint64_t | rep_calls |
double | avg_frames_checked |
std::uint64_t | new_page_calls |
SwatDB Clock Class. Clock is a derived class of ReplacementPolicy that manages the buffer replacement policy of the DBMS. The Clock algorithm is an approximation of least recently used with less overhead. Chooses a page for replacement using a clock hand, which loops the buffer frames in a circular order. Each frame has an associated reference bit, which is turned on when the pin count goes to zero.
Clock::Clock | ( | Frame * | frame_table | ) |
Clock constructor. Initializes pointer to buffer manager's frame_table, creates the free list, sets clock_hand, rep_calls, and avg_frames_checked to 0, and sets all ref_bits to false.
Frame | *frame_table, pointer to frame_table array of BufferManager. |
Clock::~Clock | ( | ) |
Empty Destructor.
|
private |
Increments the clock hand according to the clock replacement policy.
|
privatevirtual |
Derived class from pure virtual function that returns replacement policy type specific to this derived class.
Implements ReplacementPolicy.
|
virtual |
The frame is invalidated in the buffer manager, and is added to the free list of frames in the replacement policy. Ref_bit associated with this frame is set to false.
FrameId | frame_id of the frame being set invalid. |
Reimplemented from ReplacementPolicy.
|
virtual |
Updates the struct of replacement policy statistics within the buffer state struct. Adds the replacement type, number of calls to the replacement policy, average frames checked by each call to policy, the ref_bit count and clock_hand, and new page calls.
Pointer | to the ReplacementStats struct member of BufferState struct. |
Reimplemented from ReplacementPolicy.
|
virtual |
Frame is being pinned with pin count going from 0 to 1. Clock policy has nothing to do here, but an empty method must exist for BufferManager to call.
FrameId | frame_id of the frame being unpinned. |
Implements ReplacementPolicy.
|
virtual |
Prints clock_hand, average frames checked, replacement calls, how many frames have ref_bit set.
Implements ReplacementPolicy.
|
virtual |
Method that implements core replacement policy functionality of the clock replacement policy.
InsufficientSpaceBufMgr | if all pages in the buffer pool are pinned. |
Implements ReplacementPolicy.
|
virtual |
Frame is being unpinned with pin count going from 1 to 0. Set the ref_bit associated with this frame_id to true.
FrameId | frame_id of the frame being unpinned. |
Implements ReplacementPolicy.
|
private |
|
private |
Parallel array to the frame_table which stores the ref_bits of each frame.