Storage and File Structure
Storage and File Structure
Storage and File Structure
Overview of Physical Storage Media Magnetic Disks RAID Tertiary Storage Storage Access File Organization Organization of Records in Files Data-Dictionary Storage
Storage Hierarchy
NOTE: Diagram is schematic, and simplifies the structure of actual disk drives
Magnetic Disks
Read-write head Positioned very close to the platter surface (almost touching it) 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. Sector size typically 512 bytes Typical sectors per track: 500 (on inner tracks) to 1000 (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
Disk Controller
Disk controller interfaces between the computer system and the disk drive hardware.
Disk Subsystem
Access time the time it takes from when a read or write request is issued to when data transfer begins. Consists of: Seek time time it takes to reposition the arm over the correct track. Average seek time is 1/2 the worst case seek time. Would be 1/3 if all tracks had the same number of sectors, and we ignore the time to start and stop arm movement 4 to 10 milliseconds on typical disks Rotational latency time it takes for the sector to be accessed to appear under the head. Average latency is 1/2 of the worst case latency. 4 to 11 milliseconds on typical disks (5400 to 15000 r.p.m.)
RAID: Redundant Arrays of Independent Disks disk organization techniques that manage a large numbers of disks, providing a view of a single disk of high capacity and high speed by using multiple disks in parallel, and high reliability by storing data redundantly, so that data can be recovered even if a disk fails The chance that some disk out of a set of N disks will fail is much higher than the chance that a specific single disk will fail. E.g., a system with 100 disks, each with MTTF of 100,000 hours (approx. 11 years), will have a system MTTF of 1000 hours (approx. 41 days)
RAID
1. Load balance multiple small accesses to increase throughput 2. Parallelize large accesses to reduce response time. Improve transfer rate by striping data across multiple disks. Bit-level striping split the bits of each byte across multiple disks But seek/access time worse than for a single disk Bit level striping is not used much any more Block-level striping with n disks, block i of a file goes to disk (i mod n) + 1 Requests for different blocks can run in parallel if the blocks reside on different disks A request for a long sequence of blocks can utilize all disks in parallel
RAID Levels RAID organizations, or RAID levels, have differing cost, performance and
reliability characteristics RAID Level 0: Block striping; non-redundant. Used in high-performance applications where data lost is not critical. RAID Level 1: Mirrored disks with block striping Offers best write performance. Popular for applications such as storing log files in a database system.
RAID Level 2: Memory-Style Error-Correcting-Codes (ECC) with bit striping. RAID Level 3: Bit-Interleaved Parity
a single parity bit is enough for error correction, not just detection When writing data, corresponding parity bits must also be computed and written to a parity bit disk To recover data in a damaged disk, compute XOR of bits from other disks (including parity bit disk)
Factors in choosing RAID level Monetary cost Performance: Number of I/O operations per second, and bandwidth during normal operation Performance during failure Performance during rebuild of failed disk Including time taken to rebuild failed disk
RAID 0 is used only when data safety is not important E.g. data can be recovered quickly from other sources Level 2 and 4 never used since they are subsumed by 3 and 5 Level 3 is not used since bit-striping forces single block reads to access all disks, wasting disk arm movement Level 6 is rarely used since levels 1 and 5 offer adequate safety for most applications So competition is mainly between 1 and 5
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
Hardware Issues
Software RAID: RAID implementations done entirely in software, with no special hardware support Hardware RAID: RAID implementations with special hardware Use non-volatile RAM to record writes that are being executed Beware: power failure during write can result in corrupted disk E.g. failure after writing one block but before writing the second in a mirrored system Such corrupted data must be detected when power is restored Recovery from corruption is similar to recovery from failed disk NV-RAM helps to efficiently detected potentially corrupted blocks Otherwise all blocks of disk must be read and compared with mirror/parity block
Compact disk-read only memory (CD-ROM) Seek time about 100 msec (optical read head is heavier and slower) Higher latency (3000 RPM) and lower data-transfer rates (3-6 MB/s) compared to magnetic disks Digital Video Disk (DVD) DVD-5 holds 4.7 GB , variants up to 17 GB Slow seek time, for same reasons as CD-ROM Record once versions (CD-R and DVD-R)
Optical Disks
Magnetic Tapes
Hold large volumes of data and provide high transfer rates
Few GB for DAT (Digital Audio Tape) format, 10-40 GB with DLT (Digital Linear Tape) format, 100 400 GB+ with Ultrium format, and 330 GB with Ampex helical scan format Transfer rates from few to 10s of MB/s Tapes are cheap, but cost of drives is very high
Very slow access time in comparison to magnetic disks and optical disks
limited to sequential access. Some formats (Accelis) provide faster seek (10s of seconds) at cost of lower capacity
Used mainly for backup, for storage of infrequently used information, and as an off-line medium for transferring information from one system to another. Tape jukeboxes used for very large capacity storage
(terabyte (1012 bytes) to petabye (1015 bytes)
Storage Access
A database file is partitioned into fixed-length storage units called blocks. Blocks are units of both storage allocation and data transfer. Database system seeks to minimize the number of block transfers between the disk and memory. We can reduce the number of disk accesses by keeping as many blocks as possible in main memory. Buffer portion of main memory available to store copies of disk blocks. Buffer manager subsystem responsible for allocating buffer space in main memory.
Buffer Manager
Programs call on the buffer manager when they need a block from disk. Buffer manager does the following: If the block is already in the buffer, return the address of the block in main memory 1. If the block is not in the buffer 1. Allocate space in the buffer for the block 1. Replacing (throwing out) some other block, if required, to make space for the new block. 2. 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. 2. Read the block from the disk to the buffer, and return the address of the block in main memory to requester.
Buffer-Replacement Policies
Most operating systems replace the block least recently used (LRU strategy) Idea behind LRU use past pattern of block references as a predictor of future references Queries have well-defined access patterns (such as sequential scans), and a database system can use the information in a users query to predict future references LRU can be a bad strategy for certain access patterns involving repeated scans of data
e.g. when computing the join of 2 relations r and s by a nested loops for each tuple tr of r do for each tuple ts of s do if the tuples tr and ts match
Mixed strategy with hints on replacement strategy provided by the query optimizer is preferable
File Organization
The database is stored as a collection of files. Each file is a sequence of records. A record is a sequence of fields. One approach: assume record size is fixed each file has records of one particular type only different files are used for different relations This case is easiest to implement; will consider variable length records later.
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 Modification: do not allow records to cross block boundaries Deletion of record i: alternatives: move records i + 1, . . ., n to i, . . . , n 1 move record n to i do not move records, but link all free records on a free list
Store the address of the first deleted record in the file header. Use this first record to store the address of the second deleted record, and so on Can think of these stored addresses as pointers since they point to the location of a record. More space efficient representation: reuse space for normal attributes of free records to store pointers. (No pointers stored in in-use records.)
Free Lists
Variable-Length Records
Variable-length records arise in database systems in several ways: Storage of multiple record types in a file. Record types that allow variable lengths for one or more fields. Record types that allow repeating fields (used in some older data models).
Slotted page header contains: number of record entries end of free space in the block location and size of each record Records can be moved around within a page to keep them contiguous with no empty space between them; entry in the header must be updated. Pointers should not point directly to record instead they should point to the entry for the record in header.
good for queries involving depositor customer, and for queries involving one single customer and his accounts bad for queries involving only customer
Relation_metadata = (relation_name, number_of_attributes, storage_organization, location) Attribute_metadata = (relation_name, attribute_name, domain_type, position, length) User_metadata = (user_name, encrypted_password, group) Index_metadata = (relation_name, index_name, index_type, index_attributes) View_metadata = (view_name, definition)
Extra Slides
Records with fixed length fields are easy to represent Similar to records (structs) in programming languages Extensions to represent null values E.g. a bitmap indicating which attributes are null Variable length fields can be represented by a pair (offset, length) offset: the location within the record, length: field length. All fields start at predefined location, but extra indirection required for variable length fields
Record Representation
A-102
10
400
000
Perryridge
Figure 11.4
Byte string representation Attach an end-of-record () control character to the end of each record Difficulty with deletion Difficulty with growth
Fixed-Length Representation
Reserved space can use fixed-length records of a known maximum length; unused space in shorter records filled with a null or end-of-record symbol.