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

#include <bm_policies.h>

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

Public Member Functions

 ClockRandom (Frame *frame_table)
 Clock Random constructor. Initializes pointer to buffer manager's frame_table, creates the free list, sets rep_calls and avg_frames_checked to 0.
 
 ~ClockRandom ()
 
FrameId replace ()
 Method that implements the Clock Random replacement policy functionality.
 
void pin (FrameId frame_id)
 Frame is being pinned with pin count going from 0 to 1. Clock Random 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. Clock Random policy has nothing to do here, but an empty method must exist for BufferManager to call.
 
void printStats ()
 Prints average frames checked, replacement calls, summary stats on randomness.
 
- Public Member Functions inherited from ReplacementPolicy
virtual ~ReplacementPolicy ()
 Empty Destructor.
 
virtual void freeFrame (FrameId frame_id)
 Virtual method that implements any necessary update to replacement policy state following the deallocation of a page in the buffer pool. The frame is invalidated in the buffer manager, and is added to the free list of frames in the replacement policy. Some policies must implement additional functionality.
 
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

int times_chosen [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
Frameframe_table
 
std::queue< FrameIdfree
 
std::uint64_t rep_calls
 
double avg_frames_checked
 
std::uint64_t new_page_calls
 

Detailed Description

SwatDB Clock Random Class. Clock Random is a derived class of ReplacementPolicy that manages the buffer replacement policy of the DBMS. The random algorithm randomly generates a frame id to check if they are eligible for replacement. If not it iterates throught the buf pool starting from that point until it finds an eligible frame.

Constructor & Destructor Documentation

◆ ClockRandom()

ClockRandom::ClockRandom ( Frame frame_table)

Clock Random constructor. Initializes pointer to buffer manager's frame_table, creates the free list, sets 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 Clock Random policy object will be initialized with member variables initialized.
Parameters
Frame*frame_table, pointer to frame_table array of BufferManager.

◆ ~ClockRandom()

ClockRandom::~ClockRandom ( )

Empty Destructor.

Member Function Documentation

◆ _getType()

RepType ClockRandom::_getType ( )
privatevirtual

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

Returns
RepType ClockRandomT.

Implements ReplacementPolicy.

◆ pin()

void ClockRandom::pin ( FrameId  frame_id)
virtual

Frame is being pinned with pin count going from 0 to 1. Clock Random policy has nothing to do here, but an empty method must exist for BufferManager to call.

Precondition
A page in the buffer pool has been pinned, and the pin count of that frame has increased from 0 to 1.
Postcondition
Nothing.
Parameters
FrameIdframe_id of the frame being unpinned.

Implements ReplacementPolicy.

◆ printStats()

void ClockRandom::printStats ( )
virtual

Prints average frames checked, replacement calls, summary stats on randomness.

Implements ReplacementPolicy.

◆ replace()

FrameId ClockRandom::replace ( )
virtual

Method that implements the Clock Random 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, a random frame is selected and evaluated for eligibility. If it is pinned, iterate through buf pool starting from that point. 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 ClockRandom::unpin ( FrameId  frame_id)
virtual

Frame is being unpinned with pin count going from 1 to 0. Clock Random policy has nothing to do here, but an empty method must exist for BufferManager to call.

Precondition
A page in the buffer pool has been unpinned from pin count 1 to 0.
Postcondition
Nothing.
Parameters
FrameIdframe_id of the frame being unpinned.

Implements ReplacementPolicy.

Member Data Documentation

◆ times_chosen

int ClockRandom::times_chosen[BUF_SIZE]
private

Parallel array to frame_table that stores number of times each frame_id is chosen for replacement. Is useful for determining randomness.


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