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

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

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 6 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 6 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 6 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,PCConnection will sell you either– ~7GB of RAM– ~30GB of flash– ~2.5 TB of disk•Main memory is volatile. We want datato be saved between runs. (Obviously!)The Storage HierarchySource: Operating Systems Concepts 5th Edition–Main memory (RAM) forcurrently used data.–Disk for the main database(secondary storage).–Tapes for archiving olderversions of the data (tertiarystorage).Smaller, FasterBigger, Slower2Jim Gray’s Storage Latency Analogy:How Far Away is the Data?RegistersOn Chip CacheOn Board CacheMemory Disk1210100Tape /Optical Robot109106SacramentoThis Lecture HallThis RoomMy Head10 min1.5 hr2 Years1 minPluto2,000 YearsAndromedaDisks• Secondary storage device of choice.• Main advantage over tapes: random accessvs. sequential.• Data is stored and retrieved in units calleddisk blocks or pages.• Unlike RAM, time to retrieve a disk blockvaries depending upon location on disk.– Therefore, relative placement of blocks on diskhas major impact on DBMS performance!Components 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.TracksSector 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 4msec– Transfer rate around .08msec 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 arrangedsequentially on disk (by `next’), to minimizeseek and rotational delay.• For a sequential scan, pre-fetching severalpages at a time is a big win!Disk Space Management• Lowest layer of DBMS software manages spaceon 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 issatisfied by pages stored sequentially on disk!– Responsibility of disk space manager.– Higher levels don’t know how this is done, or howfree space is managed.– Though they may make performance assumptions!• Hence disk space manager should do a decent job.3ContextQuery 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 inRAMDBMAIN MEMORYDISKdisk pagefree framePage Requests from Higher LevelsBUFFER POOLchoice of frame dictatedby replacement policyWhen 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 indicate whether page has beenmodified:–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 pincount == 0 (“unpinned”)• CC & recovery may entail additional I/O whena frame is chosen 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 # ofI/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!4“Clock” Replacement Policy• An approximation of LRU• Arrange frames into a cycle, store one reference bitper 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.ContextQuery Optimizationand ExecutionRelational OperatorsFiles and Access MethodsBuffer ManagementDisk Space ManagementDBFiles of Records•


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?