HW4: Buffer Manager

Download Report

Transcript HW4: Buffer Manager

HW4: Buffer Manager
Instructors: Winston Hsu, Hao-Hua Chu
Fall 2010
Buffer Management in a DBMS
Page Requests from Higher Levels
BUFFER POOL
disk page
free frame
MAIN MEMORY
DISK
DB
choice of frame dictated
by replacement policy
• Data must be in RAM for DBMS to operate on it!
• Buffer Mgr hides the fact that not all data is in RAM
Buffer Manager
• Simple Buffer Manager Structure
– Pages in the buffer pool is not ordered in any way
– Hash table to figure out what frame a given disk page
occupies
– Love/Hate buffer replace algorithm
• Operations
–
–
–
–
bring a disk page into the buffer pool and pin it
unpin a page in the buffer pool
allocate/de-allocate pages on disk
flush/flush all buffer page(s) into the disk page
Buffer Manager Memory Structure
Buffer Page Description
FrameDesc
pageNo
dirtyFlag
pin_count
numbuf
Buffer Pool
Page
Buffer Hash Table
pageNo
frameNo
*next
……
HTSIZE
……
Love/Hate Replacement
• upper level user hints the buffer manager that
the page is loved or hated.
• Replace hated pages first, then loved pages.
• MRU list for the hated pages, LRU list for the
loved pages
• “ Love conquers hate “
Functions(in buf.h and buf.C)
• BufMgr
– Initializes buffer manager: create buffer pool,
buffer pool description, hash table….etc.
• pinPage, unpinPage, newPage, freePage,
flushPage, flushAllPages
– Use Minibase API
• Your own functions (if needed)
– For hash table and replacement policy
Minibase APIs
• Page
– Status MINIBASE_DB->read_page(PageId pageno, Page* pageptr)
– Status MINIBASE_DB->write_page(PageId pageno, Page* pageptr)
– Status MINIBASE_DB->allocate_page(PageId& start_page_num, int
run_size=1)
– Status MINIBASE_DB->deallocate_page(PageId start_page_num, int
run_size=1)
• Errors handling
status = MINIBASE_DB->write_page(pageid, &bufPool[i]);
if (status != OK) {
// status: OK or FAIL
// your own error message
}
(See ErrProc.sample for more information)
Get Started
•
•
•
•
•
Read the PDF for detail description.
Group assignment (at most 2 people/group)
Download BufMgr for source code.
Read README.first before you start.
Post your questions on ptt.cc / CSIE_DBMS.
• Minibase homepage and Google