Скачать презентацию Storing Data Disks and Files Chapter 3 Yea Скачать презентацию Storing Data Disks and Files Chapter 3 Yea

b0b7fdcba7cdef44089287d65483fc78.ppt

  • Количество слайдов: 23

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

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

Disk Storage Devices § § § Preferred secondary storage device for high storage capacity 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. Introduction to Database Systems 3

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

Why Not Store Everything in Main Memory? § § § Costs too much. $1000 Why Not Store Everything in Main Memory? § § § Costs too much. $1000 will buy you either 500 MB of RAM or 30 GB 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). Introduction to Database Systems 5

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

Disks § § Secondary storage device of choice. Main advantage over tapes: random access 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! Introduction to Database Systems 7

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

Introduction to Database Systems 9 Introduction to Database Systems 9

Disk Block Address § A physical disk block address consists of – a surface 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) Introduction to Database Systems 10

Accessing a Disk Page § Time to access (read/write) a disk block: – – 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? Introduction to Database Systems 11

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

Typical average time to read a 4 Kbyte disk I/O § Without locality access Typical average time to read a 4 Kbyte disk I/O § Without locality access – Overhead + seek + latency + transfer 0. 5 ms + 10 ms + 5. 6 ms + 0. 8 ms = 16. 9 ms § With locality access 0. 3 + 1/3 *10 + 5. 6 + 0. 8 =10. 2 ms § 5. 6 ms is for 5, 400 rpm ½ * (1/5400) * 60 * 1000 ms Introduction to Database Systems 13

Arranging Pages on Disk § `Next’ block concept: – blocks on same track, followed 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-fetching several pages at a time is a big win! Introduction to Database Systems 14

Disk Space Management § § Lowest layer of DBMS software manages space on disk. 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. Introduction to Database Systems 15

Buffer Management in a DBMS Page Requests from Higher Levels BUFFER POOL disk page 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! Table of pairs is maintained. Introduction to Database Systems 16

When a Page is Requested. . . § If requested page is not in 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. Introduction to Database Systems 17

More on Buffer Management § Page in pool may be requested many times, – 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. ) Introduction to Database Systems 18

DBMS vs. OS File System OS does disk space & buffer mgmt: why not 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. Introduction to Database Systems 19

Record Formats: Fixed Length F 1 F 2 F 3 F 4 L 1 Record Formats: Fixed Length F 1 F 2 F 3 F 4 L 1 L 2 L 3 L 4 Base address (B) § § Address = B+L 1+L 2 Information about field types same for all records in a file; stored in system catalogs. Finding i’th field done via arithmetic. Introduction to Database Systems 20

Page Formats: Fixed Length Records Slot 1 Slot 2 Free Space . . . Page Formats: Fixed Length Records Slot 1 Slot 2 Free Space . . . Slot N Slot M 1. . . 0 1 1 M N PACKED number of records M. . . 3 2 1 UNPACKED, BITMAP number of slots * Record id = . In first alternative, moving records for free space management changes rid; may not be acceptable. Introduction to Database Systems 21

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

Files of Records § § Page or block is OK when doing I/O, but 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) Introduction to Database Systems 23