DOC PREVIEW
Berkeley COMPSCI 186 - Storing Data: Disks and Files

This preview shows page 1-2 out of 7 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 7 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 7 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 7 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

1Storing Data: Disks and FilesLecture 3(R&G Chapter 9)“Yea, from the table of my memoryI’ll wipe away all trivial fond records.”-- Shakespeare, HamletReview• Aren’t Databases Great?• Relational model• SQLDisks, Memory, and FilesQuery Optimizationand ExecutionRelational OperatorsFiles and Access MethodsBuffer ManagementDisk Space ManagementDBThe BIG picture…Disks and Files• DBMS stores information on disks.– In an electronic world, disks are a mechanicalanachronism!• This has major implications for DBMS design!– READ: transfer data from disk to main memory (RAM).– WRITE: transfer data from RAM to disk.– Both are high-cost operations, relative to in-memoryoperations, so must be planned carefully!Why Not Store Everything in Main Memory?•Costs too much. For $1000, Dell will sell youeither 2 GB of RAM or 180 GB of disk today.•Main memory is volatile. We want data to besaved between runs. (Obviously!)• Typical storage hierarchy:– Main memory (RAM) for currently used data.– Disk for the main database (secondary storage).– Tapes for archiving older versions of the data(tertiary storage)Disks• Secondary storage device of choice.• Main advantage over tapes: random access vs.sequential.• Data is stored and retrieved in units called diskblocks or pages.• Unlike RAM, time to retrieve a disk block variesdepending upon location on disk.– Therefore, relative placement of blocks on diskhas major impact on DBMS performance!2Components of a DiskPlatters The platters spin (say, 120 rps).Spindle The arm assembly is movedin or out to position a headon a desired track. Tracksunder heads make a cylinder(imaginary!).Disk headArm movementArm assemblyOnly one headreads/writes at anyone time.TracksSectorv Block size is a multipleof sector size (which is fixed).Accessing a Disk Page• Time to access (read/write) a disk block:–seek time (moving arms to position disk head on track)–rotational delay (waiting for block to rotate under head)–transfer time (actually moving data to/from disk surface)• Seek time and rotational delay dominate.– Seek time varies between about 0.3 and 10msec– Rotational delay varies from 0 to 6msec– Transfer rate around .008msec per 8K block• Key to lower I/O cost: reduce seek/rotationdelays! Hardware vs. software solutions?Arranging Pages on Disk• `Next’ block concept:– blocks on same track, followed by– blocks on same cylinder, followed by– blocks on adjacent cylinder• Blocks in a file should be arranged sequentiallyon disk (by `next’), to minimize seek androtational delay.• For a sequential scan, pre-fetching severalpages at a time is a big win!Disk Space Management• Lowest layer of DBMS software manages space on disk(using OS file system or not?).• Higher levels call upon this layer to:– allocate/de-allocate a page– read/write a page• Best if a request for a sequence of pages is satisfied bypages stored sequentially on disk!– Responsibility of disk space manager.– Higher levels don’t know how this is done, or how free space ismanaged.– Though they may assume sequential access for files!• Hence disk space manager should do a decent job.ContextQuery Optimizationand ExecutionRelational OperatorsFiles and Access MethodsBuffer ManagementDisk Space ManagementDBBuffer Management in a DBMS•Data must be in RAM for DBMS to operate on it!•Buffer Mgr hides the fact that not all data is in RAMDBMAIN MEMORYDISKdisk pagefree framePage Requests from Higher LevelsBUFFER POOLchoice of frame dictatedby replacement policy3When a Page is Requested ...• Buffer pool information table contains:<frame#, pageid, pin_count, dirty>• If requested page is not in pool:– Choose a frame for replacement.Only “un-pinned” pages are candidates!– If frame is “dirty”, write it to disk– Read requested page into 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!More on Buffer Management• Requestor of page must eventually unpin it, and indicatewhether page has been modified:–dirty bit is used for this.• Page in pool may be requested many times,– a pin count is used.– To pin a page, pin_count++– A page is a candidate for replacement iff pin count == 0(“unpinned”)• CC & recovery may entail additional I/O when a frame ischosen for replacement.–Write-Ahead Log protocol; more later!Buffer Replacement Policy• Frame is chosen for replacement by areplacement policy:– Least-recently-used (LRU), MRU, Clock, etc.• Policy can have big impact on # of I/O’s;depends on the access pattern.LRU Replacement Policy•Least Recently Used (LRU)– for each page in buffer pool, keep track of time whenlast unpinned– replace the frame which has the oldest (earliest) time– very common policy: intuitive and simple• Works well for repeated accesses to popular pages• Problems?•Problem: Sequential flooding– LRU + repeated sequential scans.– # buffer frames < # pages in file means each pagerequest causes an I/O.– Idea: MRU better in this scenario? We’ll see in HW1!“Clock” Replacement Policy• An approximation of LRU• Arrange frames into a cycle, store onereference bit per frame– Can think of this as the 2nd chance bit• When pin count reduces to 0, turn on ref. bit• When replacement necessarydo for each page in cycle {if (pincount == 0 && ref bit is on)turn off ref bit;else if (pincount == 0 && ref bit is off)choose this page for replacement;} until a page is chosen; Questions:How like LRU?Problems?A(1)B(p)C(1)D(1)DBMS vs. OS File System OS does disk space & buffer mgmt: why not letOS manage these tasks?• Some limitations, e.g., files can’t span disks.• Buffer management in DBMS requires ability to:– pin a page in buffer pool, force a page to disk &order writes (important for implementing CC &recovery)– adjust replacement policy, and pre-fetch pages basedon access patterns in typical DB operations.4ContextQuery Optimizationand ExecutionRelational OperatorsFiles and Access MethodsBuffer ManagementDisk Space ManagementDBFiles of Records• Blocks interface for I/O, but…• Higher levels of DBMS operate on records, andfiles of records.• FILE: A collection of pages, each containing acollection of records. Must support:– insert/delete/modify record– fetch a particular record (specified using record id)– scan all records (possibly with some


View Full Document

Berkeley COMPSCI 186 - Storing Data: Disks and Files

Documents in this Course
Load more
Download Storing Data: Disks and Files
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Storing Data: Disks and Files and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Storing Data: Disks and Files 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?