SwatDB
|
#include <catalog.h>
Public Member Functions | |
Catalog () | |
creates an empty Catalog (should only be one in the system) | |
Catalog (std::string db_metadata_file) | |
create a catalog from existing DB state stored in meta data file More... | |
~Catalog () | |
Destroys the Catalog object. More... | |
FileId | addEntry (std::string name, Schema *schema, File *file, CatType type, std::string file_name) |
Adds an entry to the catalog with a defined schema. May be called to create an entry for an index or relation as the SwatDB instance runs, or may be called as a SwatDB instance is booted from a saved state. More... | |
void | deleteEntry (FileId file_id) |
Deletes an entry from the database. More... | |
std::string | getFileName (FileId file_id) |
Returns the filename associated with the given FileId. More... | |
FileId | getFileId (std::string name) |
Returns the FileId associated with the File identified by the given relation/index name. More... | |
File * | getFile (FileId file_id) |
Returns the File object associated with the given FileId. More... | |
Schema * | getSchema (FileId file_id) |
Returns the schema of the requested file. More... | |
CatType | getType (FileId file_id) |
Returns the type of the requested file. More... | |
std::vector< FileId > | getFileIds () |
Gets the set of valid FileIDs in the system. More... | |
Protected Member Functions | |
void | _setFile (FileId file_id, File *file_ptr) |
Set the File * field of a Catalog entry. More... | |
void | _saveDBStateToFile (std::string db_metadata_filename) |
Valled by SwatDB on shutdown to save DB meta data state to a file. More... | |
Private Attributes | |
std::vector< CatalogEntry > | entries |
FileId | next_fid |
std::mutex | cat_mux |
Friends | |
class | SwatDB |
class | FileManager |
SwatDB Catalog Class: defines the interface to the part of SwatDB that keeps track of information about Relations and Indices in the system. High-level layers may add index and relation entries, and examine their schema for query processing. Low level layers may access some internal information about a Relation or Index through methods provided by the Catalog class. A Relation and Index is uniquely identified in the system by its FileId value.
The Catalog class is the only one that needs to know the format of a saved DB metadata file. It is the class that reads and parses the DB metadata as part of initing the SwatDB state to an existing DB, and also the one that saves Catalog state to a DB metadata file on shutdown. The main SwatDB class controls invoking the Catalog class constructor to init the catalog from a saved DB metadata file or to init an empty Catalog on start-up. It also is the only class that can invoke the Catalog's _saveDBStateToFile method, which it may do on shutdown of the DB. Currently, the metadata file format is the following (NOTE: TODO missing is representation of entries schema in metadata): num_entries 1st entry's Relation or Index name (string) 1st entry's File or Relation Type (int (its CatType value)) 1st entry's Disk file name (string) 2nd entry's Relation of Index name (string) ... FileIds are unique for a full execution of SwatDB regardless of if relations and indices are created or deleted at runtime. They do not persist across two separate boots of SwatDB.
Catalog::Catalog | ( | std::string | db_metadata_file | ) |
create a catalog from existing DB state stored in meta data file
db_metadata_file | file containing metadata information about the DB with which to initialize the Catalog |
Catalog::~Catalog | ( | ) |
|
protected |
Valled by SwatDB on shutdown to save DB meta data state to a file.
Set the File * field of a Catalog entry.
This is called by the FileManager constructor when SwatDB is booted and inited from exising db state.
file_id | A valid FileId. |
file_ptr | A pointer to a valid File object |
InvalidFileIdCat | if the FileId is not valid. |
FileAlreadyExistCat | if the file entry already has a valid File * |
FileId Catalog::addEntry | ( | std::string | name, |
Schema * | schema, | ||
File * | file, | ||
CatType | type, | ||
std::string | file_name | ||
) |
Adds an entry to the catalog with a defined schema. May be called to create an entry for an index or relation as the SwatDB instance runs, or may be called as a SwatDB instance is booted from a saved state.
name | The name of the relation. |
schema | The schema object assciated with the relation (may be null). |
file | A pointer to the File object associated with the relation/index (may be null). |
type | The type of entry (index or relation). |
file_name | The name of the file into which the DiskManager stores the relation. |
FileAlreadyExistCat | if the file_name already exists in the database. |
RelationAlreadyExistCat | if a relation named name already exists in the databse. |
IndexAlreadyExistsCat | if an index named name already exists in the database. |
void Catalog::deleteEntry | ( | FileId | file_id | ) |
Deletes an entry from the database.
file_id | The FileID of the file/index to remove from the database. |
InvalidFileIdCat | if the FileId is not valid. |
Returns the File object associated with the given FileId.
file_id | A FileId. |
InvalidFileIdCat | if the given FileId is not valid. |
FileId Catalog::getFileId | ( | std::string | name | ) |
Returns the FileId associated with the File identified by the given relation/index name.
file_id | A FileId. |
InvalidNameCat | if the given name is not valid. |
std::vector<FileId> Catalog::getFileIds | ( | ) |
Gets the set of valid FileIDs in the system.
std::string Catalog::getFileName | ( | FileId | file_id | ) |
Returns the filename associated with the given FileId.
file_id | A FileId. |
InvalidFileIdCat | if the given FileId is not valid. |
Returns the schema of the requested file.
file_id | A valid FileId. |
InvalidFileIdCat | if the FileId is not valid. |
Returns the type of the requested file.
file_id | A valid FileId. |
InvalidFileIdCat | if the FileId is not valid. |
|
private |
Mutex object to control access to the table of catalog entries.
|
private |
The set of entries, one for each relation and index in the database.
|
private |
FileIds are monotonically increasing as SwatDB adds entries. Deleting an entry sets its valid member to false. The FileId of invalid files remains in this vector.