SwatDB
Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
FileManager Class Reference

#include <filemgr.h>

Collaboration diagram for FileManager:
Collaboration graph
[legend]

Public Member Functions

 FileManager (Catalog *cat, BufferManager *buf_mgr, bool load=false)
 Creates SwatDB FileManager, the interface to the File layer. More...
 
 ~FileManager ()
 Destructor. More...
 
FileId createRelation (std::string name, Schema *schema, CatType type, std::string file_name)
 Creates a new Relation in the system. Adds an entry for the new file to the Catalog and creates the underlying storage for it with the DiskManager. More...
 
void removeRelation (std::string name)
 Deletes relation from the system and removes its underlying storage from the database. More...
 
void removeFile (FileId file_id)
 Deletes a File or Index from the system and removes its underlying storage from the database. More...
 
FilegetRelation (std::string name)
 Retuns File object identified by the relation name. More...
 
FilegetFile (FileId file_id)
 Retuns File object identified by the given FileId. More...
 

Protected Member Functions

void _removeAllFiles ()
 Removes all Files in the system and their underlying storage from the database. More...
 
void _closeAllFiles ()
 Flushes and closes all underlying files in the system, saving db state. More...
 

Private Member Functions

void _loadAllFiles ()
 Loads all Files listed in the Catalog. More...
 
void _loadFile (FileId fid)
 Loads an existing relation into the system, whose contents are already stored in a file on disk. More...
 

Private Attributes

Catalogcatalog
 
BufferManagerbuf_mgr
 

Friends

class SwatDB
 

Detailed Description

SwatDB FileManager Class. The interface to the file layer of the system: manages Files and Indexes.

Constructor & Destructor Documentation

◆ FileManager()

FileManager::FileManager ( Catalog cat,
BufferManager buf_mgr,
bool  load = false 
)

Creates SwatDB FileManager, the interface to the File layer.

NOTE: load paramameter has a defaulf vlaue of false, which means that the constructor can be called just passing argument values for the first 2 parameter when a false value for load is desired.

Precondition
Input parameter objects (cat and buf_mgr) are valid.
Postcondition
If load is true, FileManager is constructed for SwatDB tat is loaded from existing files on disk. File objects are created for every relation and index file in the system and corresponding Catalog entries are updated with them. If load is false, FileManager is constructed for a new empty SwatDB.
Parameters
catPointer to the SwatDB Catalog.
buf_mgrPointer to the SwatDB BufferManager.
loadbool indicating whether Files shoud be loaded from the existing SwatDB.

◆ ~FileManager()

FileManager::~FileManager ( )

Destructor.

SwatDB controls how all the database state is saved/removed at shut down and deletes the BufferManager and Catalog objects in its destructor

Member Function Documentation

◆ _closeAllFiles()

void FileManager::_closeAllFiles ( )
protected

Flushes and closes all underlying files in the system, saving db state.

NOTE: This method is called on shutdown of the SwatDB, saving the db state.

Precondition
None.
Postcondition
Header page of each File is flushed to disk, but the underlying Unix files are not removed, effectively saving the current db state to disk.

◆ _loadAllFiles()

void FileManager::_loadAllFiles ( )
private

Loads all Files listed in the Catalog.

This is a helper function to constructor when initializing from a saved db state. Calls _loadFile below for each file in the catalog.

Precondition
None.
Postcondition
New File object is created for each entry in catalog and File* is is added tot he catalog entry. New header Page is not created for each File as they are existing relation and index files, being loaded from the saved db state.

◆ _loadFile()

void FileManager::_loadFile ( FileId  fid)
private

Loads an existing relation into the system, whose contents are already stored in a file on disk.

This is a helper function to the constructor when initializing from an existing db. At the point it is called the Catalog, BufMgr, and DiskMgr have already been created.

A new file object of the approriate type is created, its header page contents are already on disk, so this will not create and initialize a header page for the File object like createRelation does.

This method is called by SwatDB constructor when initializing the system from saved db metadata.

The constructor sequence is weird, but its ordering if very important, so at this point this is called, there is already a catalog entry for this file, and the diskmanager layer has already opened its underlying disk file.

Precondition
A File object with the requested relation name is not already in the system. An entry for this file is, however, already in the catalog, but missing its File * associated with this relation or index. Its underlying file is open by the disk manager
Postcondition
A File object of the specified type is added to the system, and its entry in the Catalog is updated to point to this newly created File object.
Parameters
fidThe FileId of the Relation or Index.
Exceptions
FileAlreadyExistCatif the catalog already contains a File * for this entry.
InvalidFileTypeFileMgrif the passed CatType is invalid or not supported.

◆ _removeAllFiles()

void FileManager::_removeAllFiles ( )
protected

Removes all Files in the system and their underlying storage from the database.

NOTE: This method is called on shutdown of the SwatDB, removing the db state.

Precondition
None. @post Underlying files that store the db state of the SwatDB are removed.

◆ createRelation()

FileId FileManager::createRelation ( std::string  name,
Schema schema,
CatType  type,
std::string  file_name 
)

Creates a new Relation in the system. Adds an entry for the new file to the Catalog and creates the underlying storage for it with the DiskManager.

Precondition
A file with the requested relation or index name and type and underlying file name is not already defined in the system.
Postcondition
A new file or index of the specified type is added to the system. A new file or index object is created, its entry is added to the SwatDB catalog, and a Unix file to store its data is created on disk by the DiskManager.
Parameters
nameThe Relation name in the system.
schemaA pointer to a Schema object associated with the file. (for RelationFile types).
typeThe specific type of file or index to create.
file_nameThe name of the disk file in which the new file object will be stored.
Returns
FileId of the newly created file or index, or INVALID_FILE_ID if an error occurs.
Exceptions
FileAlreadyExistCatif the file_name already exists in the database.
RelationAlreadyExistCatif a relation named name already exists in the database.
IndexAlreadyExistsCatif an index named name already exists in the database.
InvalidFileTypeFileMgrif the passed CatType is invalid or not supported.

◆ getFile()

File* FileManager::getFile ( FileId  file_id)

Retuns File object identified by the given FileId.

Precondition
The File, identified by the FileId already exists.
Postcondition
File* is returned.
Parameters
file_idFileId of the file to be returned.
Exceptions
FileNotFoundFileMgrif the file identified by the FileId does not exist.

◆ getRelation()

File* FileManager::getRelation ( std::string  name)

Retuns File object identified by the relation name.

Precondition
The realtion of the given name already exists.
Postcondition
File* is returned.
Parameters
nameRelation ame of the relation file to be returned.
Exceptions
FileNotFoundFileMgrif the file identified by the name does not exist.

◆ removeFile()

void FileManager::removeFile ( FileId  file_id)

Deletes a File or Index from the system and removes its underlying storage from the database.

Precondition
A valid FileId is provided as input.
Postcondition
The file identified by the given FileId is removed from the database.
Parameters
file_idFileId of the file to be deleted from the database.
Exceptions
FileNotFoundFileMgrif the given FileId does not exist in the system.

◆ removeRelation()

void FileManager::removeRelation ( std::string  name)

Deletes relation from the system and removes its underlying storage from the database.

Precondition
A valid relation name is provided as input.
Postcondition
The relation of the given name is removed from the database.
Parameters
nameName of the relation to be deleted from the database.
Exceptions
FileNotFoundFileMgrif the file identified by the FileId does not exist.

Member Data Documentation

◆ buf_mgr

BufferManager* FileManager::buf_mgr
private

Pointer to this SwatDB's BufferManager object.

◆ catalog

Catalog* FileManager::catalog
private

Pointer to this SwatDB's Catalog object.


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