SwatDB
|
#include <bm_policies.h>
Public Member Functions | |
LRU (Frame *frame_table) | |
LRU constructor. Initializes pointer to buffer manager's frame_table, creates the free list, sets queue, rep_calls, and avg_frames_checked to 0. | |
~LRU () | |
FrameId | replace () |
Method that implements the Least Recently Used (LRU) replacement policy functionality. | |
void | pin (FrameId frame_id) |
Frame is being pinned with pin count going from 0 to 1. Frame id is removed from queue. | |
void | unpin (FrameId frame_id) |
Frame is being unpinned with pin count going from 1 to 0. Frame id is added to the bottom of the queue. | |
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. frame_id is also removed from the queue. | |
void | printStats () |
Prints replacement calls, average frames checked when pinning, and max and average size of queue. | |
Public Member Functions inherited from ReplacementPolicy | |
virtual | ~ReplacementPolicy () |
Empty Destructor. | |
virtual 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, number of calls to getPage or allocatePage average frames checked by each call to policy, and the ref_bit count and clock_hand, which is irrelevant unless the policy is Clock Replacement. | |
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 | |
RepType | _getType () |
Derived class from pure virtual function that returns replacement policy type specific to this derived class. | |
Private Attributes | |
std::list< FrameId > | queue |
int | remove_calls |
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 LRU Class. LRU is a derived class of ReplacementPolicy that manages the buffer replacement policy of the DBMS. The Least Recently Used (LRU) algorithm keeps a queue of unpinned pages, choosing the least recently unpinned page for replacement. It is a generally good policy, but it has more overhead than other policies.
LRU::LRU | ( | Frame * | frame_table | ) |
LRU constructor. Initializes pointer to buffer manager's frame_table, creates the free list, sets queue, rep_calls, and avg_frames_checked to 0.
Frame | *frame_table, pointer to frame_table array of BufferManager. |
LRU::~LRU | ( | ) |
Empty Destructor.
|
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. frame_id is also removed from the queue.
FrameId | frame_id of the frame being set invalid. |
Reimplemented from ReplacementPolicy.
|
virtual |
Frame is being pinned with pin count going from 0 to 1. Frame id is removed from queue.
FrameId | frame_id of the frame being unpinned. |
Implements ReplacementPolicy.
|
virtual |
Prints replacement calls, average frames checked when pinning, and max and average size of queue.
Implements ReplacementPolicy.
|
virtual |
Method that implements the Least Recently Used (LRU) replacement policy functionality.
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. Frame id is added to the bottom of the queue.
FrameId | frame_id of the frame being unpinned. |
Implements ReplacementPolicy.
|
private |
List that is used like a queue that holds all unpinned frames.
|
private |
Number of times frame has to be removed from stack. Used for calculating avg_frames_checked.