SwatDB
Public Member Functions | Friends | List of all members
HeapFile Class Reference

#include <heapfile.h>

Inheritance diagram for HeapFile:
Inheritance graph
[legend]
Collaboration diagram for HeapFile:
Collaboration graph
[legend]

Public Member Functions

 HeapFile (Catalog *catalog, BufferManager *buf_mgr, Schema *schema)
 Constructor for HeapFile class. More...
 
 ~HeapFile ()
 HeapFile destructor. More...
 
void createHeader ()
 Allocates and initializes the header Page of the file. More...
 
void flushHeader ()
 Flushes header Page to disk. More...
 
RecordId insertRecord (Record record)
 Inserts a Record into the HeapFile. More...
 
void getRecord (RecordId record_id, Record *record)
 Sets the record_data of the given Record pointer to the data corresponding to the given RecordId. More...
 
void updateRecord (RecordId record_id, Record record)
 Updates the record data in the HeapFile identified by the given RecordId to the data in the provided Record. More...
 
void deleteRecord (RecordId record_id)
 Deletes the Record identified by the given RecordId. More...
 
HeapFileHeader getHeader ()
 THIS METHOD IS FOR DEBUGGING ONLY. Returns the current HeapFileHeader.
 
- Public Member Functions inherited from File
 File (Catalog *catalog, BufferManager *buf_mgr, Schema *schema)
 Constructor. Initializes common state associated with every file, including catalog, buf_mgr, and schema. More...
 
virtual ~File ()
 Destructor. Data members are cleaned up, but none of the dynamically allocated data members are not deleted. The underlying Unix file is not deleted.
 
FileId getMyFid ()
 Returns the FileId of the File. More...
 
SchemagetSchema ()
 Returns the schema of the File. More...
 
PageId getHeaderId ()
 Returns Header PageId. More...
 

Friends

class HeapFileScanner
 

Additional Inherited Members

- Protected Member Functions inherited from File
void _setMyFid (FileId file_id)
 Sets the file_id and the schema fields of this File. More...
 
- Protected Attributes inherited from File
FileId file_id
 
Catalogcatalog
 
BufferManagerbuf_mgr
 
Schemaschema
 
PageId header_id
 

Detailed Description

SwatDB HeapFile Class. Represents heap file in the system. It consists of doubly linked list of HeapPage and is an unsorted collection of records. Provides various methods, including inserting, modifying and retrieving records.

Constructor & Destructor Documentation

◆ HeapFile()

HeapFile::HeapFile ( Catalog catalog,
BufferManager buf_mgr,
Schema schema 
)

Constructor for HeapFile class.

Precondition
A valid Catalog pointer and BufferManager pointer are provided as inputs.
Postcondition
HeapFile object is constructed. Catalog and BufferManager data members are set to the provided inputs. Other values are initialized after construction.
Parameters
catalogPointer to the SwatDB Catalog object.
buf_mgrPointer to the SwatDB BufferManager object.
schemaPointer to this file's Schema.

◆ ~HeapFile()

HeapFile::~HeapFile ( )
inline

HeapFile destructor.

Precondition
None.
Postcondition
The HeapFile object is destroyed. The file on disk is not removed.

Member Function Documentation

◆ createHeader()

void HeapFile::createHeader ( )
virtual

Allocates and initializes the header Page of the file.

Precondition
There is sufficient space for a Page in buffer pool. The file with the corresponding FileId is already created.
Postcondition
A Page is allocated and the header_id field is initialized to the PageId of the allcated Page. The free and full fields are initialized to INVALID_PAGE_NUM and free_size and full_size are initialized to 0.
Exceptions
InsufficientSpaceBufMgrIf there is not enough space in the bufferpool.

Implements File.

◆ deleteRecord()

void HeapFile::deleteRecord ( RecordId  record_id)

Deletes the Record identified by the given RecordId.

Precondition
A valid RecordId is provided.
Postcondition
Deletes the Record identified by the given RecordId. If the Page was in the list of full pages, and it is no longer full after deletion, then the Page is moved to the list of free pages. If the Page is empy after deletion, it is completely removed from any list, released, and deallocated. The header Page is updated appropriately. All pages pinned during the operation are released at the end or before exception is thrown.
Parameters
record_idRecordId identifying the record data to be deleted.
Exceptions
InvalidSchemaHeapFileIf the given Record's Schema does not match that of the HeapFile(compare pointers).
InvalidPageIdBufMgrIf the PageNum of the given RecordId is not valid.
InvalidSlotIdHeapPageIf the SlotId of the given RecordId is not valid.

◆ flushHeader()

void HeapFile::flushHeader ( )
virtual

Flushes header Page to disk.

Precondition
There is sufficient space for the header Page in buffer pool. header_id is valid.
Postcondition
Header Page of the File is flushed to disk.
Exceptions
InsufficientSpaceBufMgrIf there is not enough space in the bufferpool for the header Page.
InvalidPageIdBufMgrIf the header_id of the File is not valid.

Implements File.

◆ getRecord()

void HeapFile::getRecord ( RecordId  record_id,
Record record 
)

Sets the record_data of the given Record pointer to the data corresponding to the given RecordId.

Precondition
A valid RecordId and a Record object pointer with a Schema matching that of the HeapFile.
Postcondition
The given Record pointer's data field is initialized to the data identified by the given RecordId. All pages pinned during the operation are released at the end or before exeption is thrown.
Parameters
record_idRecordId of the record_data to be retrieved.
recordRecord pointer to store the retrieved data.
Exceptions
InvalidSchemaHeapFileIf the given Record pointer's Schema does not match that of the HeapFile (compares pointers).
InvalidPageIdBufMgrIf the PageNum of the given RecordId is not valid.
InvalidSlotIdHeapPageIf the SlotId of the given RecordId is not valid.

◆ insertRecord()

RecordId HeapFile::insertRecord ( Record  record)

Inserts a Record into the HeapFile.

Precondition
A valid Record object with a Schema matching that of the HeapFile is provided as input. There is some Page into which the Record can be inserted.
Postcondition
The Record is inserted into some Page that belongs to the HeapFile. If there is enough space on some Page in the list of free pages, then the Record is inserted there. If there is not enough space on any Page in the list of free pages, then a new Page is allocated. The Record is inserted into this Page. If the the Page is full after inserting the Record, the Page is moved to the list of full pages. Otherwise, the Page is added to/remains in free list. The header Page is updated appropriately. All pages pinned during the operation are released at the end or before exeption is thrown.
Parameters
recordRecord to be inserted into the HeapFile.
Returns
RecordId RecordId of the inserted Record.
Exceptions
InvalidSchemaHeapFileIf the given Record's Schema does not match that of the HeapFile (compares pointers).
InsufficientSpaceHeapPageIf the given Record's data exceeds the MAXIMUM_RECORD_SIZE.
InsufficientSpaceHeapFileIf the number of pages (including the header) in the HeapFile exceeds MAX_PAGE_NUM.

◆ updateRecord()

void HeapFile::updateRecord ( RecordId  record_id,
Record  record 
)

Updates the record data in the HeapFile identified by the given RecordId to the data in the provided Record.

Precondition
A valid RecordId and a Record object with a Schema matching that of the HeapFile are provided as inputs. There is enough space in the HeapPage containing the Record identified by RecordId for the data in the provided record.
Postcondition
The Record data of the Record identified by the RecordId is replaced with the data of the provided Record. If the "full" state of the apge changes after the update, it is moved from one list to the other (free to full or full to free). The header Page is updated appropriately. All pages pinned during the operation are released at the end or before exeption is thrown.
Parameters
record_idRecordId identifying the record data to be updated.
recordRecord object containing data to overwrite the record data identified by the given RecordId.
Exceptions
InvalidSchemaHeapFileIf the given Record's Schema does not match that of the HeapFile (compares pointers).
InvalidPageIdBufMgrif the PageNum of the given RecordId is not valid.
InvalidSlotIdHeapPageif the SlotId of the given RecordId is not valid.
InsufficientSpaceHeapPageif there is not enough space for the updated record in the corresponding HeapPage.

The documentation for this class was generated from the following file: