Chapter 11: Storage and File Structure

31
Chapter 11: Storage and File Structure Hankz Hankui Zhuo

description

Chapter 11: Storage and File Structure. Hankz Hankui Zhuo. What factors we care about. Speed Cost Reliability data loss: power failure, or system crash physical failure. Classification of Physical Storage Media. volatile storage loses contents when power is switched off - PowerPoint PPT Presentation

Transcript of Chapter 11: Storage and File Structure

Page 1: Chapter 11: Storage and File Structure

Chapter 11: Storage and File Structure

Hankz Hankui Zhuo

Page 2: Chapter 11: Storage and File Structure

What factors we care about

• Speed• Cost• Reliability– data loss: power failure, or system crash– physical failure

Page 3: Chapter 11: Storage and File Structure

Classification of Physical Storage Media

• volatile storage– loses contents when power is switched off

• non-volatile storage – Contents persist even when power is switched off

Page 4: Chapter 11: Storage and File Structure

Physical Storage Media

• Cache– Fastest– Most costly– Volatile

• Main memory– Fast– Too small/expensive to store entire DB– Volatile

Page 5: Chapter 11: Storage and File Structure

Physical Storage Media

• Flash memory– Non-volatile– Reads roughly as fast as main memory– Writes/erases are slow– Cost similar to main memory– Widely used in embedded devices, e.g., digital

cameras

Page 6: Chapter 11: Storage and File Structure

Physical Storage Media

• Magnetic-disk– Stored on spinning disk– Primary medium for DB– Slower than main memory– Non-volatile– Large capacity

Page 7: Chapter 11: Storage and File Structure

Physical Storage Media

• Optical storage– non-volatile– Read from a spinning disk using a laser– Examples: DVD, CD-ROM– Slower than magnetic disk

Page 8: Chapter 11: Storage and File Structure

Physical Storage Media

• Tape storage– Non-volatile– Sequential-access– Much slower than disk– Storage costs much cheaper than disk, but drives

are expensive

Page 9: Chapter 11: Storage and File Structure

Storage Hierarchy

Page 10: Chapter 11: Storage and File Structure

Storage Hierarchy

Primary storage

Secondary storage

Tertiary storage

Page 11: Chapter 11: Storage and File Structure

Magnetic Hard Disk Mechanism

Page 12: Chapter 11: Storage and File Structure

Performance Measures of Disks

• Access time– Seek time • time it takes to reposition the arm over the correct

track. – Rotational latency• time it takes for the sector to be accessed to appear

under the head.

• Data-transfer rate– ?MB per second

Page 13: Chapter 11: Storage and File Structure

Performance Measures of Disks

• Mean time to failure (MTTF)– the average time the disk is expected to run

continuously without any failure.• Typically 3 to 5 years• MTTF decreases as disk ages

Page 14: Chapter 11: Storage and File Structure

Optimization of Disk-Block Access

• Block – a contiguous sequence of sectors from a single track – data is transferred in blocks – sizes range from 512 bytes to several kilobytes• Smaller blocks: more transfers from disk• Larger blocks: more space wasted due to partially filled

blocks• Typical block sizes today range from 4 to 16 kilobytes

Page 15: Chapter 11: Storage and File Structure

Optimization of Disk-Block Access

• Disk-arm-scheduling– order pending accesses to tracks, so that disk arm

movement is minimized– Elevator algorithm• Move in one direction• Process requests in that direction till no more requests

in that direction• Then reverse direction and repeat

Page 16: Chapter 11: Storage and File Structure

RAID: Redundant Arrays of Independent Disks

• Easy to fail when using lots of disks– Cause data loss

• Using redundancy– To avoid data loss

Page 17: Chapter 11: Storage and File Structure

Improvement of Reliability via Redundancy

• Redundancy– Store extra information: used to rebuild information

lost in a disk failure– E.g., mirroring• Duplicate every disk• Write on both disks• Read from either disk• If a disk fails, data is still available in the other

• Mean time to data loss depends on:– Mean time to failure, and – Mean time to repair

Page 18: Chapter 11: Storage and File Structure

Buffer Manager

Page 19: Chapter 11: Storage and File Structure

Buffer Manager

• Programs call on the buffer manager when they need a block from disk.1. If the block is already in the buffer, buffer

manager returns the address of the block in main memory

Page 20: Chapter 11: Storage and File Structure

Buffer Manager

2. If the block is not in the buffer, the buffer manager allocates space in the buffer for the block

A. Replacing (throwing out) some other block, if required, to make space for the new block.

B. Replaced block written back to disk only if it was modified since the most recent time that it was written to/fetched from the disk.

Page 21: Chapter 11: Storage and File Structure

Buffer-Replacement Policies

• Most operating systems replace the block least recently used (LRU strategy)

• You can design many policies to replace blocks– To minimize time cost of transferring data– E.g., statistical methods?

Page 22: Chapter 11: Storage and File Structure

File Organization

Page 23: Chapter 11: Storage and File Structure

File Organization

• Database is stored as – A collection of files– A file is a sequence of records– A record is a sequence of attributes

Page 24: Chapter 11: Storage and File Structure

Fixed-Length Records• Simple approach:– Store record i starting from byte n (i – 1), where

n is the size of each record.– Record access is simple but records may cross

blocks– Deletion of record i:• move records i + 1, . . ., m to i, . . . , m – 1, or• move record m to i• link all free records on a free list

Page 25: Chapter 11: Storage and File Structure

Free Lists

Page 26: Chapter 11: Storage and File Structure

Variable-Length Records

• More complicated than fixed-length records• Please refer to the text book

Page 27: Chapter 11: Storage and File Structure

Organization of Records in Files• Heap – a record can be placed anywhere in

the file where there is space• Sequential – store records in sequential order,

based on the value of the search key of each record

• Hashing – a hash function computed on some attribute of each record; the result specifies in which block of the file the record should be placed

Page 28: Chapter 11: Storage and File Structure

Sequential File Organization

• Suitable for applications that require sequential processing of the entire file

• The records in the file are ordered by a search-key

Page 29: Chapter 11: Storage and File Structure

Sequential File Organization• Deletion – use pointer chains• Insertion –locate the position where the

record is to be inserted– if there is free space insert there – if no free space, insert the record in an overflow block– In either case, pointer chain must be updated

Page 30: Chapter 11: Storage and File Structure

Sequential File Organization• For example:

• Need to reorganize the file from time to time to restore sequential order

Page 31: Chapter 11: Storage and File Structure

The end