1 / 23

Storing Data: Disks and Files

Storing Data: Disks and Files. Chapter 3. “ Yea, from the table of my memory I’ll wipe away all trivial fond records.” -- Shakespeare, Hamlet. Contents. 1 Disk Storage Devices 2 Files of Records 3 Operations on Files 4 Unordered Files 5 Ordered Files 6 Hashed Files

damienh
Download Presentation

Storing Data: Disks and Files

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Storing Data: Disks and Files Chapter 3 “Yea, from the table of my memory I’ll wipe away all trivial fond records.” -- Shakespeare, Hamlet

  2. Contents 1 Disk Storage Devices 2 Files of Records 3 Operations on Files 4 Unordered Files 5 Ordered Files 6 Hashed Files 6.1 Static External Hashing 6.2 Dynamic and Extendible Hashing Techniques

  3. Disk Storage Devices • Preferred secondary storage device for high storage capacity and low cost. • Data stored as magnetized areas on magnetic disk surfaces. • A disk pack contains several magnetic disks connected to a rotating spindle.

  4. Disk Storage Devices • Disks are divided into concentric circular tracks on each disk surface. • Track capacities vary typically from 4 to 50 Kbytes.

  5. Why Not Store Everything in Main Memory? • Costs too much. $1000 will buy you either 500MB of RAM or 30GB of disk today. • Main memory is volatile. We want data to be saved 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).

  6. Why Not Store Everything in Main Memory? • Note: Some DBMS systems DO keep everything in RAM, “Main Memory Databases” • Limited applications, but 10x faster

  7. Disks • Secondary storage device of choice. • Main advantage over tapes: random access vs.sequential. • Data is stored and retrieved in units called disk blocks or pages. • Unlike RAM, time to retrieve a disk page varies depending upon location on disk. • Therefore, relative placement of pages on disk has major impact on DBMS performance!

  8. Tracks Arm movement Arm assembly Components of a Disk Spindle Disk head The platters spin (say, 7200rpm). The arm assembly is moved in or out to position a head on a desired track. Tracks under heads make a cylinder(imaginary!). Sector Platters Only one head reads/writes at any one time. • Block size is a multiple of sector size (which is fixed).

  9. Disk Block Address • A physical disk block address consists of • a surface number, • track number , and • (within surface) • block number. • (within track) • (s,t,b)

  10. 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) • Command overhead(the time it takes for the disk drive’s microprocessor and electronics to process and handle an I/O request) Key to lower I/O cost: reduce seek/rotation delays! Hardware vs. software solutions?

  11. Accessing a Disk Page • Seek time and rotational delay dominate. • Seek time varies from about 1 to 20msec(typical 10ms without locality of access, 1/3*10ms with locality) • Rotational delay varies from 0 to 10msec(5.6ms for 5,400rpm) • Transfer rate is about 1msec per 4KB page(5Mbytes/sec) • Command overhead 0.5ms

  12. Typical average time to read a 4-Kbyte disk I/O • Without locality access • Overhead + seek + latency + transfer 0.5 ms + 10 ms + 5.6ms + 0.8ms = 16.9 ms • With locality access 0.3 + 1/3 *10 + 5.6 + 0.8 =10.2ms • 5.6ms is for 5,400rpm ½ * (1/5400) * 60 * 1000 ms

  13. 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 sequentially on disk (by `next’), to minimize seek and rotational delay. • For a sequential scan, pre-fetchingseveral pages at a time is a big win!

  14. Disk Space Management • Lowest layer of DBMS software manages space on disk. • Higher levels call upon this layer to: • allocate/de-allocate a page • read/write a page • Request for a sequence of pages must be satisfied by allocating the pages sequentially on disk! Higher levels don’t need to know how this is done, or how free space is managed.

  15. DB Buffer Management in a DBMS Page Requests from Higher Levels • Data must be in RAM for DBMS to operate on it! • Table of <frame#, pageid> pairs is maintained. BUFFER POOL disk page free frame MAIN MEMORY DISK choice of frame dictated by replacement policy

  16. When a Page is Requested ... • If requested page is not in pool: • Choose a frame for replacement • If frame is “dirty”, write it to disk • Read requested page into chosen frame • Pin the page and return its address.

  17. More on Buffer Management • Page in pool may be requested many times, • a pin count is used. A page is a candidate for replacement iff pin count = 0 (“unpinned”) • CC & recovery may entail additional I/O when a frame is chosen for replacement. (Write-Ahead Log protocol; more later.)

  18. DBMS vs. OS File System OS does disk space & buffer mgmt: why not let OS 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 based on access patterns in typical DB operations.

  19. Record Formats: Fixed Length • Information about field types same for all records in a file; stored in systemcatalogs. • Finding i’th field done via arithmetic. F3 F4 F1 F2 L3 L4 L1 L2 Address = B+L1+L2 Base address (B)

  20. Page Formats: Fixed Length Records Slot 1 Slot 1 Slot 2 Slot 2 • Record id = <page id, slot #>. In first alternative, moving records for free space management changes rid; may not be acceptable. Free Space . . . . . . Slot N Slot N Slot M . . . N 1 1 1 M 0 M ... 3 2 1 number of slots number of records PACKED UNPACKED, BITMAP

  21. Page Formats: Variable Length Records Page i • Can move records on page without changing rid; so, attractive for fixed-length records too. Rid = (i,2) Rid = (i,N) Rid = (i,1) Length = 24 N Pointer to start of free space 16 24 20 Offset of record from start of data area N . . . 2 1 # slots SLOT DIRECTORY

  22. Files of Records • Page or block is OK when doing I/O, but higher levels of DBMS operate on records, and files of records. • FILE: A collection of pages, each containing a collection of records. Must support: • insert/delete/modify record • read a particular record (specified using record id) • scan all records (possibly with some conditions on the records to be retrieved)

More Related