/* Name: ShutDown BufferPool * Behavior:Would shutdown an existing buffer pool. * Version: 1.0.0 */ RC shutdownBufferPool(BM_BufferPool *const bm) { RC ret=RC_WRITE_FAILED; int i ,*pgnums, *fixounts; bool ispinned=FALSE; Buffer_page_Dtl *pg_dtl; BufferPool_Node *bufnode; char *frame; int currentaccessed; // pthread_mutex_lock(&work_mutex_shutdown);//1st Incoming thread hold a lock. fixounts=getFixCounts(bm); pgnums=getFrameContents(bm); for(i=0 ; i < bm->numPages ; i++) { if(fixounts[i] > 0) { ispinned=TRUE;//Condition to check for pinned pages before shut down. } } free(fixounts); if(ispinned==FALSE) { ret=RC_OK; bufnode=search_data(BP_StNode_ptr,bm);//Get the active buffer pool from collection of pools. currentaccessed=getfilebeingused(BP_StNode_ptr,bm->pageFile);//Check if the same pool is being shared. if(bufnode!=NULL) { pg_dtl=bufnode->buffer_page_dtl; if(pg_dtl!=NULL) for(i=0;i<bm->numPages;i++) { frame=pg_dtl[i].pageframes; if(pg_dtl[i].isdirty==TRUE) { ret=writeBlock(pg_dtl[i].pagenums,bm->mgmtData,frame)==RC_OK?RC_OK:RC_WRITE_FAILED;//Write the content with dirty to disk. } currentaccessed == 1 ?free(frame):' '; } currentaccessed == 1 ?free(pg_dtl):' '; pg_dtl=NULL; delete_node(&BP_StNode_ptr,bm); } currentaccessed == 1 ?closePageFile(bm->mgmtData):' '; currentaccessed == 1 ?free(bm->mgmtData):' '; } // pthread_mutex_unlock(&work_mutex_shutdown);//1st Incoming thread release a lock. free(pgnums); return ret; }
char *sprintPoolContent (BM_BufferPool *const bm) { PageNumber *frameContent; bool *dirty; int *fixCount; int i; char *message; int pos = 0; message = (char *) malloc(256 + (22 * bm->numPages)); frameContent = getFrameContents(bm); dirty = getDirtyFlags(bm); fixCount = getFixCounts(bm); for (i = 0; i < bm->numPages; i++) pos += sprintf(message + pos, "%s[%i%s%i]", ((i == 0) ? "" : ",") , frameContent[i], (dirty[i] ? "x": " "), fixCount[i]); return message; }
// external functions void printPoolContent (BM_BufferPool *const bm) { PageNumber *frameContent; bool *dirty; int *fixCount; int i; frameContent = getFrameContents(bm); dirty = getDirtyFlags(bm); fixCount = getFixCounts(bm); printf("{"); printStrat(bm); printf(" %i}: ", bm->numPages); for (i = 0; i < bm->numPages; i++) printf("%s[%i%s%i]", ((i == 0) ? "" : ",") , frameContent[i], (dirty[i] ? "x": " "), fixCount[i]); printf("\n"); }