SwatDB
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | Private Attributes | List of all members
MRU Class Reference

#include <bm_policies.h>

Inheritance diagram for MRU:
Inheritance graph
[legend]
Collaboration diagram for MRU:
Collaboration graph
[legend]

Public Member Functions

 MRU (Frame *frame_table)
 MRU constructor. Initializes pointer to buffer manager's frame_table, creates the free list, sets stack, rep_calls, and avg_frames_checked to 0.
 
 ~MRU ()
 
FrameId replace ()
 Method that implements the Most Recently Used (MRU) 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 stack.
 
void unpin (FrameId frame_id)
 Frame is being unpinned with pin count going from 1 to 0. Frame id is added to the top of the stack.
 
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 stack.
 
void printStats ()
 Prints replacement calls, average frames checked when pinning, and max and average size of stack.
 
- 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< FrameIdstack
 
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
Frameframe_table
 
std::queue< FrameIdfree
 
std::uint64_t rep_calls
 
double avg_frames_checked
 
std::uint64_t new_page_calls
 

Detailed Description

SwatDB MRU Class. MRU is a derived class of ReplacementPolicy that manages the buffer replacement policy of the DBMS. The Most Recently Used (MRU) algorithm keeps a stack of unpinned pages, choosing the most recently unpinned page for replacement. It is well suited for sequential scans, but it has more overhead than other policies.

Constructor & Destructor Documentation

◆ MRU()

MRU::MRU ( Frame frame_table)

MRU constructor. Initializes pointer to buffer manager's frame_table, creates the free list, sets stack, rep_calls, and avg_frames_checked to 0.

Precondition
BufferManager constructor is being called, frame_table parameter points to an initialized frame_table object.
Postcondition
A MRU object will be initialized with member variables initialized.
Parameters
Frame*frame_table, pointer to frame_table array of BufferManager.

◆ ~MRU()

MRU::~MRU ( )

Empty Destructor.

Member Function Documentation

◆ _getType()

RepType MRU::_getType ( )
privatevirtual

Derived class from pure virtual function that returns replacement policy type specific to this derived class.

Returns
RepType MruT.

Implements ReplacementPolicy.

◆ freeFrame()

void MRU::freeFrame ( FrameId  frame_id)
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 stack.

Precondition
A page in the buffer pool has been deallocated.
Postcondition
frame_id is added to the free list and removed from the stack.
Parameters
FrameIdframe_id of the frame being set invalid.

Reimplemented from ReplacementPolicy.

◆ pin()

void MRU::pin ( FrameId  frame_id)
virtual

Frame is being pinned with pin count going from 0 to 1. Frame id is removed from stack.

Precondition
A page in the buffer pool has been unpinned from pin count 1 to 0.
Postcondition
Frame id is removed from stack.
Parameters
FrameIdframe_id of the frame being unpinned.

Implements ReplacementPolicy.

◆ printStats()

void MRU::printStats ( )
virtual

Prints replacement calls, average frames checked when pinning, and max and average size of stack.

Implements ReplacementPolicy.

◆ replace()

FrameId MRU::replace ( )
virtual

Method that implements the Most Recently Used (MRU) replacement policy functionality.

Precondition
The replacement policy has been invoked. The buffer manager is attempting to add a frame to the buffer pool. The buffer map is locked.
Postcondition
If there is a free (invalid) frame, that FrameID is chosen for replacement and is returned. Else, the most recently unpinned frame is chosen and taken off the stack. If all pages are pinned, an exception is thrown.
Returns
FrameID of the frame that is eligible for replacement in the buffer pool.
Exceptions
InsufficientSpaceBufMgrif all pages in the buffer pool are pinned.

Implements ReplacementPolicy.

◆ unpin()

void MRU::unpin ( FrameId  frame_id)
virtual

Frame is being unpinned with pin count going from 1 to 0. Frame id is added to the top of the stack.

Precondition
A page in the buffer pool has been unpinned from pin count 1 to 0.
Postcondition
Frame id is added to the top of the stack.
Parameters
FrameIdframe_id of the frame being unpinned.

Implements ReplacementPolicy.

Member Data Documentation

◆ remove_calls

int MRU::remove_calls
private

Number of times frame has to be removed from stack. Used for calculating avg_frames_checked.

◆ stack

std::list<FrameId> MRU::stack
private

List that is used like a stack that holds all unpinned frames.


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