bool *getDirtyFlags (BM_BufferPool *const bm) { int i; bool *dirtyFlags = malloc(sizeof(bool) * bm->numPages); resetPages(); for(i = 0; i < bm->numPages; i++){ dirtyFlags[i] = pages->isMark; if(i < bm->numPages-1) pages = pages->nextPage; } resetPages(); return dirtyFlags; }
int *getFixCounts (BM_BufferPool *const bm) { int i; int *fixCounts = malloc(sizeof(int) * bm->numPages); resetPages(); for(i = 0; i < bm->numPages; i++){ fixCounts[i] = pages->fixCount; if(i < bm->numPages-1) pages = pages->nextPage; } resetPages(); return fixCounts; }
RC shutdownBufferPool (BM_BufferPool *const bm) { SM_FileHandle fh; RC code = openPageFile(bm->pageFile, &fh); if (code != RC_OK) return code; resetPages(); int i = 0; for(i = 0; i < bm->numPages; i++){ if (pages->isMark && pages->fixCount > 0){ code = writeBlock(pages->pageNum, &fh, pages->pageData); if(code != RC_OK) return code; metaData.numWriteIO++; } pages->isMark = false; pages->pageData = malloc(PAGE_SIZE); strcpy(pages->pageData, ""); pages->pageNum = -1; pages->fixCount = 0; pages->repStrat = -1; if(i < bm->numPages-1){ pages = pages->nextPage; } } closePageFile(&fh); return RC_OK; }
PageNumber *getFrameContents (BM_BufferPool *const bm) { PageNumber *frames = malloc(sizeof(int)* bm->numPages); int i; resetPages(); for(i = 0; i < bm->numPages; i++){ if(pages->pageNum > -1){ frames[i] = pages->pageNum; }else{ frames[i] = -1; } if(i < bm->numPages-1) pages = pages->nextPage; } resetPages(); return frames; }
NavBarOptionsDialog::NavBarOptionsDialog(QWidget *parent) : QDialog(parent) { setupUi(this); connect(upButton, SIGNAL(clicked()), SLOT(movePageUp())); connect(downButton, SIGNAL(clicked()), SLOT(movePageDown())); connect(resetButton, SIGNAL(clicked()), SLOT(resetPages())); connect(buttonBox, SIGNAL(accepted()), SLOT(accept())); connect(buttonBox, SIGNAL(rejected()), SLOT(reject())); connect(pageListWidget, SIGNAL(currentRowChanged(int)), SLOT(onCurrentRowChanged(int))); }
void navPages(BM_BufferPool *const bm, int index){ resetPages(); int i; for(i = 0; i < bm->numPages; i++){ if(i == index){ break; } if(i < bm->numPages-1){ pages = pages->nextPage; } } }
RC unpinPage (BM_BufferPool *const bm, BM_PageHandle *const page) { resetPages(); int i; for (i = 0; i < bm->numPages; i++) { if (pages->pageNum == page->pageNum) { break; } if(i < bm->numPages-1){ pages = pages->nextPage; } } if(pages->isMark){ forcePage(bm, page); } pages->fixCount--; resetPages(); return RC_OK; }
RC forceFlushPool (BM_BufferPool *const bm) { int i = 0; resetPages(); SM_FileHandle fh; RC code = openPageFile(bm->pageFile, &fh); if (code != RC_OK) return code; for(i = 0; i < bm->numPages; i++){ if (pages->isMark && pages->pageNum > -1){ pages->isMark = false; } if(i < bm->numPages-1){ pages = pages->nextPage; } } resetPages(); closePageFile(&fh); return RC_OK; }
RC markDirty (BM_BufferPool *const bm, BM_PageHandle *const page) { resetPages(); int i; for (i = 0; i < bm->numPages; i++) { if (pages->pageNum > -1 && pages->pageNum == page->pageNum) { break; } if(i < bm->numPages-1){ pages = pages->nextPage; } } pages->isMark = true; metaData.totalNumOfDirtyPages = metaData.totalNumOfDirtyPages++; return RC_OK; }
RC initBufferPool (BM_BufferPool *const bm, const char *const pageFileName, const int numPages, ReplacementStrategy strategy, void *stratData) { SM_FileHandle fh; /*RC code = openPageFile((char*)pageFileName, &fh); if(code != RC_OK){ return code; } closePageFile(&fh); */ int i = 0; ThePage_t *temp; pages = (ThePage_t*) malloc(sizeof(ThePage_t)); for(i = 0; i < numPages; i++){ pages->isMark = false; pages->pageData = malloc(PAGE_SIZE); strcpy(pages->pageData, ""); pages->pageNum = -1; pages->fixCount = 0; pages->repStrat = -1; pages->nextPage = (ThePage_t*)malloc(sizeof(ThePage_t)); if(i == 0) pages->prevPage = NULL; else pages->prevPage = temp; temp = pages; if(i < numPages-1){ pages->nextPage = (ThePage_t*) malloc(sizeof(ThePage_t)); temp = pages; pages = pages->nextPage; } } resetPages(); metaData.numReadIO = 0; metaData.numWriteIO = 0; metaData.totalRepStrat = 0; metaData.totalNumOfDirtyPages = 0; bm->pageFile = (char*)pageFileName; bm->numPages = numPages; bm->strategy = strategy; bm->mgmtData = stratData; return RC_OK; }
RC pinPage (BM_BufferPool *const bm, BM_PageHandle *const page, const PageNumber pageNum) { int i; resetPages(); int spotFound = -1; for(i = 0; i < bm->numPages; i++){ if(pages->pageNum == -1){ spotFound = i; break; } if(pages->pageNum == pageNum){ spotFound = i; break; } if(i < bm->numPages-1){ pages = pages->nextPage; } } int min = 999999; if (spotFound == -1) { resetPages(); for (i = 0; i < bm->numPages; i++) { if (pages->fixCount == 0 && pages->repStrat < min) { min = pages->repStrat; spotFound = i; } if(i < bm->numPages-1){ pages = pages->nextPage; } } } resetPages(); for(i = 0; i < bm->numPages; i++){ if(i == spotFound) break; if(i < bm->numPages-1){ pages = pages->nextPage; } } SM_FileHandle fH; openPageFile(bm->pageFile, &fH); if(pages->pageNum == pageNum){ if(bm->strategy == RS_LRU) pages->repStrat = ++(metaData.totalRepStrat); pages->fixCount++; page->pageNum = pageNum; strcpy(page->data, pages->pageData); }else { page->data = malloc(PAGE_SIZE); page->pageNum = pageNum; readBlock(pageNum, &fH, page->data); metaData.numReadIO++; pages->pageNum = pageNum; pages->fixCount = 1; pages->repStrat = ++(metaData.totalRepStrat); pages->isMark = false; } closePageFile(&fH); return RC_OK; }