Presentation is loading. Please wait.

Presentation is loading. Please wait.

Project Implementation of Buffer Management

Similar presentations


Presentation on theme: "Project Implementation of Buffer Management"— Presentation transcript:

1 Project Implementation of Buffer Management
CSED421: Database Systems Labs

2 Buffer Management DBMS is..
A gigantic software package combining all these modules! Query Optimization and Execution Relational Operator Evaluator Files and Access Methods Buffer Management Disk Space Management DBMS Buffer Management

3 The Overview of BufMgr Software layer responsible for bringing pages from disk to main memory as needed

4 Frame Information The frame has two variables.
pin_count: the number of current users of the page dirty: indicate if the page has been modified. Initially, the pin_count for every frame is set to 0, and the dirty bits are turned off.

5 When a Page is Requsted If a requested page is not in pool
Choose a frame for replacement. If frame is dirty, write it to disk. Read the requested page into a chosen frame. Pin the page, and return its address If requests can be predicted, e.g., sequential scans, pages can be pre-fetched several pages at a time.

6 Buffer Replacement Policy
Frame is chosen for replacement by a replacement policy: Least-recently-used (LRU), clock replacement, First-in-first-out (FIFO), most recently used (MRU) Policy can have big impact on # of I/Os; depends on the access pattern.

7 Clock Replacement Algorithm
Simple implementation “Clock” had points to next page to replace If R=0, replace the page. If R=1, set R=0 and advance the clock hand. Continue until the page with R=0 is found. This may involve going all the way around the clock.

8 Source codes 8 cpp files main.cpp, test.cpp, db.cpp, bmtest.cpp, db.cpp, page.cpp, bufmgr.cpp, clockreplacementpolicy.cpp Only need to put more source codes for two files. You may add some source codes to the other files.

9 Source codes Status UnpinPage( PageID pid, Bool dirty=FALSE );
class BufMgr { public: BufMgr( int bufsize ); ~BufMgr(); Status PinPage( PageID pid, Page*& page, Bool emptyPage=FALSE ); Status UnpinPage( PageID pid, Bool dirty=FALSE ); Status NewPage( PageID& pid, Page*& firstpage,int howmany=1 ); Status FreePage( PageID pid ); Status FlushPage( PageID pid ); Status FlushAllPages(); Status ResetStat(); Status PrintStat(); unsigned int GetNumOfBuffers(); unsigned int GetNumOfUnpinnedBuffers(); private: int mNumOfBuffers; // buffer size Frame* mBufferPool; // data structure that represents all the frames in the buffer pool HashTable<PageID> mLookupTable; // data structure that enables fast lookup for pids std::queue<int> mFreeList; // queue of free pages in the buffer pool ReplacementPolicy* mPolicy; // pointer to the replacement policy currently being used int mNumPinRequests; // variable to store no. of requests int mNumPinMisses; // variable to store no. of pin page misses int mNumDirtyWrites; // variable to store no. of dirty page writes };

10 Source codes class ClockReplacementPolicy : public ReplacementPolicy {
ClockReplacementPolicy( Frame* bufPool, int poolSize ); ~ClockReplacementPolicy(); // destructor that must deallocate storage for reference virtual int GetFrame(); virtual void UpdateFrame( int index ); private: int mCurrent; // represents which buffer frame is currently considered for replacement bool * mReference; // data structure that stores the reference bits for each frame };

11 Results

12 Source codes Visual studio 2005 환경 Lab 2010 홈페이지에서 다운로드
질문 및 답변은 Lab 게시판을 참고 Textbook pp 참고

13 Submission & Deadline 제출 제출기한 소스코드 보고서 (10장 이내)
두 개의 파일 이외에 다른 코드 수정 시 수정한 이유와 파일 수정에 대해 서술할 것. 보고서 (10장 이내) 각 구현한 함수에 대한 간략한 서술 구현한 replacement policy에 대한 설명 Test 결과에 대한 설명 및 분석 제출기한 2010년 5월 21일 금요일 PM 18:00 공학 2동 306호 늦게 제출시 패널티 있음.

14 Q&A Enjoy getting your hands dirty!!


Download ppt "Project Implementation of Buffer Management"

Similar presentations


Ads by Google