BadgerDB
 All Classes Namespaces Functions Variables Typedefs Friends
Public Member Functions | Public Attributes
badgerdb::BufMgr Class Reference

The central class which manages the buffer pool including frame allocation and deallocation to pages in the file. More...

#include <buffer.h>

List of all members.

Public Member Functions

 BufMgr (std::uint32_t bufs)
 ~BufMgr ()
void readPage (File *file, const PageId PageNo, Page *&page)
void unPinPage (File *file, const PageId PageNo, const bool dirty)
void allocPage (File *file, PageId &PageNo, Page *&page)
void flushFile (const File *file)
void disposePage (File *file, const PageId PageNo)
void printSelf ()
BufStatsgetBufStats ()
void clearBufStats ()

Public Attributes

PagebufPool

Detailed Description

The central class which manages the buffer pool including frame allocation and deallocation to pages in the file.

Definition at line 160 of file buffer.h.


Constructor & Destructor Documentation

badgerdb::BufMgr::BufMgr ( std::uint32_t  bufs)

Constructor of BufMgr class

Definition at line 19 of file buffer.cpp.

  : numBufs(bufs) {
  bufDescTable = new BufDesc[bufs];

  for (FrameId i = 0; i < bufs; i++) 
  {
    bufDescTable[i].frameNo = i;
    bufDescTable[i].valid = false;
  }

  bufPool = new Page[bufs];

  int htsize = ((((int) (bufs * 1.2))*2)/2)+1;
  hashTable = new BufHashTbl (htsize);  // allocate the buffer hash table

  clockHand = bufs - 1;
}

Destructor of BufMgr class

Definition at line 38 of file buffer.cpp.

                {
}

Member Function Documentation

void badgerdb::BufMgr::allocPage ( File file,
PageId PageNo,
Page *&  page 
)

Allocates a new, empty page in the file and returns the Page object. The newly allocated page is also assigned a frame in the buffer pool.

Parameters:
fileFile object
PageNoPage number. The number assigned to the page in the file is returned via this reference.
pageReference to page pointer. The newly allocated in-memory Page object is returned via this reference.

Definition at line 64 of file buffer.cpp.

{
}

Clear buffer pool usage statistics

Definition at line 284 of file buffer.h.

  {
    bufStats.clear();
  }
void badgerdb::BufMgr::disposePage ( File file,
const PageId  PageNo 
)

Delete page from file and also from buffer pool if present. Since the page is entirely deleted from file, its unnecessary to see if the page is dirty.

Parameters:
fileFile object
PageNoPage number
void badgerdb::BufMgr::flushFile ( const File file)

Writes out all dirty pages of the file to disk. All the frames assigned to the file need to be unpinned from buffer pool before this function can be successfully called. Otherwise Error returned.

Parameters:
fileFile object
Exceptions:
PagePinnedExceptionIf any page of the file is pinned in the buffer pool
BadBufferExceptionIf any frame allocated to the file is found to be invalid

Definition at line 60 of file buffer.cpp.

{
}

Get buffer pool usage statistics

Definition at line 276 of file buffer.h.

  {
    return bufStats;
  }
void badgerdb::BufMgr::printSelf ( void  )

Print member variable values.

Definition at line 68 of file buffer.cpp.

{
  BufDesc* tmpbuf;
  int validFrames = 0;
  
  for (std::uint32_t i = 0; i < numBufs; i++)
  {
    tmpbuf = &(bufDescTable[i]);
    std::cout << "FrameNo:" << i << " ";
    tmpbuf->Print();

    if (tmpbuf->valid == true)
      validFrames++;
  }

  std::cout << "Total Number of Valid Frames:" << validFrames << "\n";
}
void badgerdb::BufMgr::readPage ( File file,
const PageId  PageNo,
Page *&  page 
)

Reads the given page from the file into a frame and returns the pointer to page. If the requested page is already present in the buffer pool pointer to that frame is returned otherwise a new frame is allocated from the buffer pool for reading the page.

Parameters:
fileFile object
PageNoPage number in the file to be read
pageReference to page pointer. Used to fetch the Page object in which requested page from file is read in.

Definition at line 51 of file buffer.cpp.

{
}
void badgerdb::BufMgr::unPinPage ( File file,
const PageId  PageNo,
const bool  dirty 
)

Unpin a page from memory since it is no longer required for it to remain in memory.

Parameters:
fileFile object
PageNoPage number
dirtyTrue if the page to be unpinned needs to be marked dirty
Exceptions:
PageNotPinnedExceptionIf the page is not already pinned

Definition at line 56 of file buffer.cpp.

{
}

Member Data Documentation

Actual buffer pool from which frames are allocated

Definition at line 205 of file buffer.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Functions Variables Typedefs Friends