Chapter 17 Disk Storage, Basic File Structures, and Hashing Disk Storage Devices
Chapter 17 Disk Storage, Basic File Structures, and Hashing Disk Storage Devices
A read-write head moves to the track that contains the block to be transferred.
1
o Disk rotation moves the block under the read-write head for reading or writing.
A physical disk block (hardware) address consists of:
o a cylinder number (imaginary collection of tracks of same radius from all recorded
surfaces), the track number or surface number (within the cylinder), and block number
(within track).
Reading or writing a disk block is time consuming because of the seek time s and rotational delay
(latency) rd.
Double buffering can be used to speed up the transfer of contiguous disk blocks.
Double Buffering
Records
Fixed and variable length records
Records contain fields which have values of a particular type
o E.g., amount, date, time, age
Fields themselves may be fixed length or variable length
Variable length fields can be mixed into one record:
o Separator characters or length fields are needed so that the record can be “parsed.”
2
Blocking
Blocking:
o Refers to storing a number of records in one block on the disk.
Blocking factor (bfr) refers to the number of records per block.
There may be empty space in a block if an integral number of records do not fit in one block.
Spanned Records:
o Refers to records that exceed the size of one or more blocks and hence span a number of
blocks.
Files of Records
A file is a sequence of records, where each record is a collection of data values (or data items).
A file descriptor (or file header) includes information that describes the file, such as the field
names and their data types, and the addresses of the file blocks on disk.
Records are stored on disk blocks.
The blocking factor bfr for a file is the (average) number of file records stored in a disk block.
A file can have fixed-length records or variable-length records.
File records can be unspanned or spanned
Unspanned: no record can span two blocks
Spanned: a record can be stored in more than one block
The physical disk blocks that are allocated to hold the records of a file can be contiguous,
linked, or indexed.
3
In a file of fixed-length records, all records have the same format. Usually, unspanned
blocking is used with such files.
Files of variable-length records require additional information to be stored in each record,
such as separator characters and field types.
Usually spanned blocking is used with such files.
Operation on Files
Typical file operations include:
o OPEN: Readies the file for access, and associates a pointer that will refer to a current file
record at each point in time.
o FIND: Searches for the first file record that satisfies a certain condition, and makes it the
current file record.
o FINDNEXT: Searches for the next file record (from the current record) that satisfies a
certain condition, and makes it the current file record.
o READ: Reads the current file record into a program variable.
o INSERT: Inserts a new record into the file & makes it the current file record.
o DELETE: Removes the current file record from the file, usually by marking the record to
indicate that it is no longer valid.
o MODIFY: Changes the values of some fields of the current file record.
o CLOSE: Terminates access to the file.
o REORGANIZE: Reorganizes the file records.
For example, the records marked deleted are physically removed from the file or
a new organization of the file records is created.
o READ_ORDERED: Read the file blocks in order of a specific field of the file.
Unordered Files
Also called a heap or a pile file.
New records are inserted at the end of the file.
A linear search through the file records is necessary to search for a record.
This requires reading and searching half the file blocks on the average, and is hence quite
expensive.
Record insertion is quite efficient.
Reading the records in order of a particular field requires sorting the file records.
Ordered Files
4
Also called a sequential file.
File records are kept sorted by the values of an ordering field.
Insertion is expensive: records must be inserted in the correct order.
o It is common to keep a separate unordered overflow (or transaction) file for new records
to improve insertion efficiency; this is periodically merged with the main ordered file.
A binary search can be used to search for a record on its ordering field value.
o This requires reading and searching log2 of the file blocks on the average, an
improvement over linear search.
Reading the records in order of the ordering field is quite efficient.
5
6
Hashed Files
Internal Hashing
Hash table
o The use of an array of records
o Simple hash function: h(K) = K mod M
7
Hashed Files in External Hashing
8
To reduce overflow records, a hash file is typically kept 70-80% full.
The hash function h should distribute the records uniformly among the buckets
o Otherwise, search time will be increased because many overflow records will exist.
Main disadvantages of static external hashing:
o Fixed number of buckets M is a problem if the number of records in the file grows or
shrinks.
o Ordered access on the hash key (order preserving hashing) is quite inefficient (requires
sorting the records).
The directories can be stored on disk, and they expand or shrink dynamically.
o Directory entries point to the disk blocks that contain the stored records.
9
An insertion in a disk block that is full causes the block to split into two blocks and the records
are redistributed among the two blocks.
o The directory is updated appropriately.
Dynamic and extendible hashing does not require an overflow area.
Linear hashing does require an overflow area but does not use a directory.
o Blocks are split in linear order as the file expands.
10