Exemple #1
0
/*
 * Decrements the pinCnt of the frame containing (file, PageNo) 
 *
 * Throws HashNotFoundException when page is not in the buffer pool, 
 *        on the hashtable to get a frame number. 
 * params: File* file, const PageId pageNo, Page*& page
 */
void BufMgr::readPage(File* file, const PageId pageNo, Page*& page)
{
  FrameId frame = -1;
  // look up hashtable
  try{
    hashTable->lookup(file, pageNo, frame);
    // page is within the hashtable
    
    BufDesc* bufDesc = &(bufDescTable[frame]);
    bufDesc->refbit = true;
    bufDesc->pinCnt = bufDesc->pinCnt + 1;
    page = &(bufPool[frame]);
  } 
  // Page is not in the buffer pool
  catch(HashNotFoundException) {
	// calling this first to see if the page is valid
	file->readPage(pageNo);
	
	// Allocate frame
	FrameId frame = -1;
	allocBuf(frame);
	page = &(bufPool[frame]);
	*page = file->readPage(pageNo);
	
	// insert into hash table
	hashTable->insert(file, pageNo, frame);
	
	// call Set()
    BufDesc* bufDesc = &(bufDescTable[frame]);
    bufDesc->Set(file, pageNo);
  }
}
Exemple #2
0
/*
 * This method is to to allocate an empty page in the specified file.
 *
 * params: File* file, PageId &pageNo, Page*& page
 */
void BufMgr::allocPage(File* file, PageId &pageNo, Page*& page) 
{
  // get a new page and allocate frame
  Page newPage = file->allocatePage();
  pageNo = newPage.page_number();
  FrameId frame = -1;
  allocBuf(frame);
  page = &(bufPool[frame]);
  *page = file->readPage(pageNo);
  
  
  // insert into hash table
  hashTable->insert(file, pageNo, frame);
  
  // call Set()
  BufDesc* bufDesc = &(bufDescTable[frame]);
  bufDesc->Set(file, pageNo);
  
  //std::cout << "Allocated new page: " << frame << "\n";
}