Database Systems Storage and Disks Fusheng Wang Department of Biomedical Informatics Department of...

39
Database Systems Storage and Disks Fusheng Wang Department of Biomedical Informatics Department of Mathematics and Computer Science Emory University

Transcript of Database Systems Storage and Disks Fusheng Wang Department of Biomedical Informatics Department of...

Page 1: Database Systems Storage and Disks Fusheng Wang Department of Biomedical Informatics Department of Mathematics and Computer Science Emory University.

Data

base

Syst

em

s

Storage and Disks

Fusheng Wang

Department of Biomedical InformaticsDepartment of Mathematics and Computer Science

Emory University

Page 2: Database Systems Storage and Disks Fusheng Wang Department of Biomedical Informatics Department of Mathematics and Computer Science Emory University.

Data

base

Syst

em

s

The Systems Side of Databases

1. Data Organization: physical storage strategies to support efficient updates, retrieval

2. Data retrieval: auxiliary data structures to enable efficient retrieval. Techniques for processing queries to ensure efficient retrieval

3. Data Integrity: techniques for implementing Xtions, to ensure safe concurrent access to data. Ensuring data is safe in the presence of system crashes.

Page 3: Database Systems Storage and Disks Fusheng Wang Department of Biomedical Informatics Department of Mathematics and Computer Science Emory University.

Data

base

Syst

em

s

Data Organization

Key points:1. Storage Media

• “Memory hierarchy”• Efficient/reliable transfer of data between disks and

main memory– Hardware techniques (RAID disks)– Software techniques (Buffer mgmt)

2. Storage strategies for relations-file organization• Representation of tuples on disks• Storage of tuples in pages, clustering

Page 4: Database Systems Storage and Disks Fusheng Wang Department of Biomedical Informatics Department of Mathematics and Computer Science Emory University.

Data

base

Syst

em

s

DB2 Architecture Overview

Page 5: Database Systems Storage and Disks Fusheng Wang Department of Biomedical Informatics Department of Mathematics and Computer Science Emory University.

Data

base

Syst

em

s

An Example Query Process (in DB2)

Page 6: Database Systems Storage and Disks Fusheng Wang Department of Biomedical Informatics Department of Mathematics and Computer Science Emory University.

Data

base

Syst

em

s

CPU

M C

TypicalComputer

SecondaryStorage

......

Page 7: Database Systems Storage and Disks Fusheng Wang Department of Biomedical Informatics Department of Mathematics and Computer Science Emory University.

Data

base

Syst

em

s

Storage HierarchyH

ighe

r sp

eed

Low

er p

rice

V

NV

Page 8: Database Systems Storage and Disks Fusheng Wang Department of Biomedical Informatics Department of Mathematics and Computer Science Emory University.

Data

base

Syst

em

s

Storage Media: Cache and Main Memory• Cache – fastest and most costly form of

storage; volatile; managed by the computer system hardware.

• Main memory:– fast access (10s to 100s of nanoseconds; 1

nanosecond = 10–9 seconds)– generally too small (or too expensive) to store the

entire database– Volatile — contents of main memory are usually lost

if a power failure or system crash occurs.– But… CPU operates only on data in main memory

Page 9: Database Systems Storage and Disks Fusheng Wang Department of Biomedical Informatics Department of Mathematics and Computer Science Emory University.

Data

base

Syst

em

s

Storage Media: Flash Memory– Data survives power failure– Data can be written at a location only once, but

location can be erased and written to again • Can support only a limited number (10K – 1M) of

write/erase cycles.• Erasing of memory has to be done to an entire bank of

memory

– Reads are roughly as fast as main memory– But writes are slow (few microseconds), erase is

slower– Widely used in embedded devices such as digital

cameras, phones, and USB keys

Page 10: Database Systems Storage and Disks Fusheng Wang Department of Biomedical Informatics Department of Mathematics and Computer Science Emory University.

Data

base

Syst

em

s

Storage Media: Disk

• Disk– Primary medium for the long-term storage of data;

typically stores entire database.– random-access – possible to read data on disk in any

order, unlike magnetic tape– Non-volatile: data survive a power failure or a system

crash, disk failure less likely than them

• New technology: Solid State Disks and Flash disks

Page 11: Database Systems Storage and Disks Fusheng Wang Department of Biomedical Informatics Department of Mathematics and Computer Science Emory University.

Data

base

Syst

em

s

Storage Media: Players

• Optical storage – non-volatile, data is read optically from a spinning

disk using a laser – CD-ROM (640 MB) and DVD (4.7 to 17 GB) most

popular forms– Write-one, read-many (WORM) optical disks used

for archival storage (CD-R and DVD-R)– Multiple write versions also available (CD-RW,

DVD-RW, and DVD-RAM)– Reads and writes are slower than with magnetic

disk • Tapes

– Sequential access (very slow)– Cheap, high capacity

Page 12: Database Systems Storage and Disks Fusheng Wang Department of Biomedical Informatics Department of Mathematics and Computer Science Emory University.

Data

base

Syst

em

s

Memory Hierarchy

• primary storage: Fastest media but volatile (cache, main memory)

• secondary storage: next level in hierarchy, non-volatile, moderately fast access time– also called on-line storage – E.g. flash memory, magnetic disks

• tertiary storage: lowest level in hierarchy, non-volatile, slow access time– also called off-line storage – E.g. magnetic tape, optical storage

Page 13: Database Systems Storage and Disks Fusheng Wang Department of Biomedical Informatics Department of Mathematics and Computer Science Emory University.

Data

base

Syst

em

s

Memory Hierarchy: Data Transfers

• Data transfers– cache – mm : OS/hardware controlled

– mm – disk : <- reads, -> writes controlled by DBMS

– disk – CD-Rom or DVD

– disk – Tapes

Backups (off-line)

Page 14: Database Systems Storage and Disks Fusheng Wang Department of Biomedical Informatics Department of Mathematics and Computer Science Emory University.

Data

base

Syst

em

s

Main memory Disk Data Transfers Concerns

1. Efficiency (speed)can be improved by... a. improving raw data transfer speed

b. avoiding untimely data transfer c. avoiding unnecessary data transfer

2. Safety (reliability, availability) can be improved by... a. storing data redundantly

Page 15: Database Systems Storage and Disks Fusheng Wang Department of Biomedical Informatics Department of Mathematics and Computer Science Emory University.

Data

base

Syst

em

s

Main memory Disk Data Transfers

Achieving efficiency:1. Improve Raw data Transfer speed

1. Faster Disks2. Parallelization (RAID)

2. Avoiding untimely data transfers 1. Disk scheduling 2. Batching3. Avoiding unnecessary data transfers 1. Buffer Management 2. Good file organization

Page 16: Database Systems Storage and Disks Fusheng Wang Department of Biomedical Informatics Department of Mathematics and Computer Science Emory University.

Data

base

Syst

em

s

Hard Disk Mechanism

http://www.youtube.com/watch?v=Bh80aaygIXghttp://www.youtube.com/watch?v=4iaxOUYalJU

Page 17: Database Systems Storage and Disks Fusheng Wang Department of Biomedical Informatics Department of Mathematics and Computer Science Emory University.

Data

base

Syst

em

s

• Read-write head – Positioned very close to the platter surface– Reads or writes magnetically encoded information

• Surface of platter divided into circular tracks– Over 50K-100K tracks per platter on typical hard disks

• Each track is divided into sectors (blocks)– The smallest unit of data that can be read or written– Sector size typically 512 bytes (2048 bytes for DVD/CD-ROM)– Typical sectors per track: 500 to 1000 (on inner tracks) to

1000 to 2000 (on outer tracks)• To read/write a sector

– disk arm swings to position head on right track– platter spins continually; data is read/written as sector passes

under head• Head-disk assemblies

– multiple disk platters on a single spindle (1 to 5 usually)– one head per platter, mounted on a common arm

• Cylinder i consists of ith track of all the platters

Hard Disk

Page 18: Database Systems Storage and Disks Fusheng Wang Department of Biomedical Informatics Department of Mathematics and Computer Science Emory University.

Data

base

Syst

em

s

“Typical” ValuesDiameter: 1 inch 15 inchesCylinders: 100 2000Surfaces: 1 or 2(Tracks/cyl) 2 (floppies) 30Sector Size: 512B 50KCapacity: 360 KB (old floppy)

1.5 TB

Page 19: Database Systems Storage and Disks Fusheng Wang Department of Biomedical Informatics Department of Mathematics and Computer Science Emory University.

Data

base

Syst

em

s

Performance Measures of Disks• Access time – consists of:

– Seek time – time it takes to reposition the arm over the correct track

Average: 4ms (high end), 9ms(desktop), 12ms (mobile drives)– (Rotational) latency time – time it takes for the

sector to be accessed to appear under the headAvg: 2ms(15k rpm), 3ms(10k rpm) 4.16ms(7200rpm)

• Data-transfer rate – the rate at which data can be retrieved from or stored to the disk.

Analogy to taking a bus:1. Seek time: time to get to bus stop2. Latency time; time spent waiting at bus stop3. Data transfer time: time spent riding the bus

Page 20: Database Systems Storage and Disks Fusheng Wang Department of Biomedical Informatics Department of Mathematics and Computer Science Emory University.

Data

base

Syst

em

s

Data Transfer Rate

• Data transfer rate (also called throughput): min(internal rate, external rate)– Internal rate: moving data between the disk surface

and the controller on the drive– External rate: moving data between the controller on

the drive and the host system– A typical 7200 RPM desktop HDD: 1030 Mbit/s– 12x blue-ray: 432Mbit/s– SATA interface: 2Gbits/s

Page 21: Database Systems Storage and Disks Fusheng Wang Department of Biomedical Informatics Department of Mathematics and Computer Science Emory University.

Data

base

Syst

em

s

Example

ST3120022A  : Barracuda 7200.7    Capacity:120 GB  Interface:  Ultra ATA/100    RPM: 7200 RPM   Seek time: 8.5 ms avg Latency time?:

Page 22: Database Systems Storage and Disks Fusheng Wang Department of Biomedical Informatics Department of Mathematics and Computer Science Emory University.

Data

base

Syst

em

s

Random vs sequential I/O

• Ex: 1 KB Block» Random I/O: 15 ms.» Sequential I/O: 1 ms.

Rule of Random I/O: ExpensiveThumb Sequential I/O: Much less ~10-20 times

Page 23: Database Systems Storage and Disks Fusheng Wang Department of Biomedical Informatics Department of Mathematics and Computer Science Emory University.

Data

base

Syst

em

s

Page 24: Database Systems Storage and Disks Fusheng Wang Department of Biomedical Informatics Department of Mathematics and Computer Science Emory University.

Data

base

Syst

em

s

Page 25: Database Systems Storage and Disks Fusheng Wang Department of Biomedical Informatics Department of Mathematics and Computer Science Emory University.

Data

base

Syst

em

s

Page 26: Database Systems Storage and Disks Fusheng Wang Department of Biomedical Informatics Department of Mathematics and Computer Science Emory University.

Data

base

Syst

em

s

Page 27: Database Systems Storage and Disks Fusheng Wang Department of Biomedical Informatics Department of Mathematics and Computer Science Emory University.

Data

base

Syst

em

s

Page 28: Database Systems Storage and Disks Fusheng Wang Department of Biomedical Informatics Department of Mathematics and Computer Science Emory University.

Data

base

Syst

em

s

Page 29: Database Systems Storage and Disks Fusheng Wang Department of Biomedical Informatics Department of Mathematics and Computer Science Emory University.

Data

base

Syst

em

s

Exercise: Disk Access Cost Estimation

• IBM U320 146GB hard drive has average seek time of 3.6ms, average rotation delay of 2ms for a half rotation (15K rpm), and a transfer rate of 320MB/sec. – 1.Estimate access time for a 4KB block

– 2.Estimate access time for a contiguous 64KB access

– 3. Estimate access time for 16 random 4KB-blocks

Page 30: Database Systems Storage and Disks Fusheng Wang Department of Biomedical Informatics Department of Mathematics and Computer Science Emory University.

Data

base

Syst

em

s

Performance Measures (Cont.)

• Mean time to failure (MTTF) – the average time the disk is expected to run continuously without any failure.– Typically 5 to 10 years– Probability of failure of new disks is quite low,

corresponding to a“theoretical MTTF” of 30,000 to 1,200,000 hours for a new disk

• E.g., an MTTF of 1,200,000 hours for a new disk means that given 1000 relatively new disks, on an average one will fail every 1200 hours

– MTTF decreases as disk ages

Page 31: Database Systems Storage and Disks Fusheng Wang Department of Biomedical Informatics Department of Mathematics and Computer Science Emory University.

Data

base

Syst

em

s

RAID: Redundant Arrays of Independent (Inexpensive) Disks • disk organization techniques that manage a large

numbers of disks, providing a view of a single disk• Idea: cheaper to have many small disks, than few

big disks• bonus: also advantageous for: 1. speed (efficiency) 2. reliability (safety)

Page 32: Database Systems Storage and Disks Fusheng Wang Department of Biomedical Informatics Department of Mathematics and Computer Science Emory University.

Data

base

Syst

em

s

Improvement in Performance via Parallelism

Choices:

D1 D2 D3 . . . . Dn

1. Distribute files (f1 D1, f2 D2, ....) or

2. Distribute parts of files (“striping”) block striping sector striping ...... bit striping

Page 33: Database Systems Storage and Disks Fusheng Wang Department of Biomedical Informatics Department of Mathematics and Computer Science Emory University.

Data

base

Syst

em

s

Parallelization

File distribution

+: Availability: Many files still available if a disk goes down

+: recovery requires fewer disks - : but still sequential read for each file

Striping +: improved ||’ism (speed) ( - : but a single disk failure catastrophic!)

Page 34: Database Systems Storage and Disks Fusheng Wang Department of Biomedical Informatics Department of Mathematics and Computer Science Emory University.

Data

base

Syst

em

s

Reliability:• Measure: MTTF• Striping reduces reliability: why?

Solution = RedundancyRedundancy: store data on more than 1 disk

E.g. “mirroring” (duplicate disks) (1 disk stored on 2)

logical disk

Improving Reliability

RAID (redundant array of independent disks): a storage technology that combines multiple disk drive components into a logical unit for the purposes of data redundancy and performance improvement

Page 35: Database Systems Storage and Disks Fusheng Wang Department of Biomedical Informatics Department of Mathematics and Computer Science Emory University.

Data

base

Syst

em

s

RAID Levels Schemes to provide redundancy at lower cost by using

disk striping combined with parity bits Different RAID organizations, or RAID levels, have differing cost,

performance and reliability characteristics

RAID Level 1: Mirrored disks with block striping Offers good write performance. Popular for applications such as storing log files in a database system.

RAID Level 0: Block striping; non-redundant. Used in high-performance applications where data loss is not critical.

Page 36: Database Systems Storage and Disks Fusheng Wang Department of Biomedical Informatics Department of Mathematics and Computer Science Emory University.

Data

base

Syst

em

s

Parity Bit

• A bit added to the end of a string of binary code that indicates whether the number of bits in the string with the value one is even or odd

• With 3 drives:

7 bits of data (count of 1 bits) 8 bits including parity (even)

0000000 0 00000000

1010001 3 10100011

Drive 1: 01101101Drive 2: 11010100

   01101101 XOR 11010100-------------------------Drive 3: 10111001

If drive 2 fails: 10111001 (1)XOR 01101101 (3)_____________        11010100 (2)

Page 37: Database Systems Storage and Disks Fusheng Wang Department of Biomedical Informatics Department of Mathematics and Computer Science Emory University.

Data

base

Syst

em

s

RAID Level 5• RAID Level 5: Block-Interleaved Distributed

Parity; partitions data and parity among all N + 1 disks, rather than storing data in N disks and parity in 1 disk.– e.g., with 4 disks, parity block for nth set of blocks

is stored on disk (n mod 4) + 1, with the data blocks stored on the other 4 disks.

Page 38: Database Systems Storage and Disks Fusheng Wang Department of Biomedical Informatics Department of Mathematics and Computer Science Emory University.

Data

base

Syst

em

s

RAID Levels (Cont.)

• Data is block interleaved – this allows us to get all our data from a single disk on a read (in case of a disk error, read all disks)• Block interleaving reduces throughput for a single request ( only a single disk is servicing the request), but improves task-level parallelism as other disk drives are free to service other requests• On a write, we access the disk that stores the data and the parity disk – parity information can be updated simply by checking if the new data differs from the old data• If we have a single disk for parity, multiple writes can not happen in parallel (as all writes must update parity info)• RAID 5 distributes the parity block to allow simultaneous writes

Page 39: Database Systems Storage and Disks Fusheng Wang Department of Biomedical Informatics Department of Mathematics and Computer Science Emory University.

Data

base

Syst

em

s

Choice of RAID Level• Level 1 provides much better write performance than level 5

– Level 5 requires at least 2 block reads and 2 block writes to write a single block, whereas Level 1 only requires 2 block writes

– Level 1 preferred for high update environments such as log disks

• Level 1 had higher storage cost than level 5– disk drive capacities increasing rapidly (50%/year) whereas

disk access times have decreased much less (x 3 in 10 years)

– I/O requirements have increased greatly, e.g. for Web servers

– When enough disks have been bought to satisfy required rate of I/O, they often have spare storage capacity

• so there is often no extra monetary cost for Level 1!• Level 5 is preferred for applications with low update rate, and

large amounts of data• Level 1 is preferred for all other applications