#include <filemgr.h>
SwatDB FileManager Class. The interface to the file layer of the system: manages Files and Indexes.
◆ FileManager()
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
-
◆ ~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
◆ _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
-
fid | The FileId of the Relation or Index. |
- Exceptions
-
◆ _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
-
name | The Relation name in the system. |
schema | A pointer to a Schema object associated with the file. (for RelationFile types). |
type | The specific type of file or index to create. |
file_name | The 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
-
FileAlreadyExistCat | if the file_name already exists in the database. |
RelationAlreadyExistCat | if a relation named name already exists in the database. |
IndexAlreadyExistsCat | if an index named name already exists in the database. |
InvalidFileTypeFileMgr | if the passed CatType is invalid or not supported. |
◆ getFile()
Retuns File object identified by the given FileId.
- Precondition
- The File, identified by the FileId already exists.
- Postcondition
- File* is returned.
- Parameters
-
file_id | FileId of the file to be returned. |
- Exceptions
-
◆ 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
-
name | Relation ame of the relation file to be returned. |
- Exceptions
-
◆ 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_id | FileId of the file to be deleted from the database. |
- Exceptions
-
◆ 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
-
name | Name of the relation to be deleted from the database. |
- Exceptions
-
◆ buf_mgr
◆ catalog
The documentation for this class was generated from the following file: