void BufMgr::flushFile(const File* file) { for(FrameId i = 0; i < numBufs; i++){ BufDesc* temp = &(bufDescTable[i]); if (temp->file == file){ if(temp->pinCnt > 0){ throw PagePinnedException(file->filename(), temp->pageNo, temp->frameNo); } if(temp->valid == false){ temp->pinCnt = 0; throw BadBufferException(temp->frameNo, temp->dirty, temp->valid, temp->refbit); } // (a) if (temp->dirty){ temp->file -> writePage(bufPool[i]); // flushes the page to disk temp->dirty = false; // sets dirty bit to false } //(b) try{ hashTable->remove(file, bufDescTable[i].pageNo); } catch(HashNotFoundException e){ return; } //(c) temp->Clear(); // clears frame //bufDescTable[i].valid = false; //bufDescTable[i].pinCnt = 0; } } }
/* * This method deletes a particular page from file. * * params: File* file, const PageId PageNo */ void BufMgr::disposePage(File* file, const PageId PageNo) { // Should we delete page if pincount is not zero? currently do not check pincount try{ FrameId frame = -1; // find if the page is in the buffer pool hashTable->lookup(file, PageNo, frame); // page is within the hashtable BufDesc* bufDesc = &(bufDescTable[frame]); /*if(bufDesc->pinCnt>0) { throw PagePinnedException("abc", PageNo, frame); }*/ // Clear the frame bufDesc->Clear(); // delete from buffer pool hashTable->remove(file, PageNo); } // Page is not in the buffer pool catch(HashNotFoundException) { } file->deletePage(PageNo); }
//Flushes out all dirty pages and deallocates the buffer pool and the BufDesc table. BufMgr::~BufMgr() { BufDesc* bufdesc; File * tmpfile; Page * frame; for (std::uint32_t i = 0; i < numBufs; i++) { bufdesc = &(bufDescTable[i]); if(bufdesc->valid && bufdesc->dirty) { //write frame from buffer onto disk tmpfile = bufdesc->file; frame = &(bufPool[bufdesc->frameNo]); tmpfile->writePage(*frame); } //clear entry from BufDesc bufdesc->Clear(); } //deallocate BufDesc table delete [] &bufDescTable; //deallocates BufferPool for(std::uint32_t i = 0; i < numBufs; i++) { //guess there is no harm in leaving old information in pool } delete [] &bufPool; }