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 | |
~Catalog () | |
Destroys the Catalog object. | |
FileId | addEntry (std::string name, Schema *schema, File *file, SearchKeyFormat *key_format, CatType type, FileId relation, std::string file_name, bool to_save=true) |
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. | |
void | deleteEntry (FileId file_id) |
Deletes an entry from the database. | |
void | printCatInfo () |
prints out all files in the catalog and its type, then prints out the relation file associated with it if its an index, or a list of indexes if its a relation. | |
std::uint32_t | getNumValid () |
Returns the number of valid entries in the catalog. | |
std::string | getFileName (FileId file_id) |
Returns the filename associated with the given FileId. | |
FileId | getFileId (std::string name) |
Returns the FileId associated with the File identified by the given relation name. | |
FileId | getRelationFileId (FileId file_id) |
Returns the FileId for the relation file associated with the given index file id. | |
File * | getFile (FileId file_id) |
Returns the File object associated with the given FileId. | |
Schema * | getSchema (FileId file_id) |
Returns the schema of the requested file. | |
CatType | getType (FileId file_id) |
Returns the type of the requested file. | |
std::vector< FileId > | getFileIds () |
Gets the set of valid FileIDs in the system. | |
void | setSave (bool save_on_exit, std::string rel_name) |
Setter method for the boolean save_on_exit. | |
void | setRelName (std::string old_rel_name, std::string new_rel_name) |
Setter method for the relation name and file name of a relation. Note that both the rel_name and the name of the file on disk will be changed. | |
Protected Member Functions | |
void | _setFile (FileId file_id, File *file_ptr) |
Set the File * field of a Catalog entry. | |
void | _saveDBStateToFile (std::string db_metadata_filename) |
Valled by SwatDB on shutdown to save DB meta data state to a file. | |
Private Attributes | |
std::unordered_map< std::string, FileId > | relations |
std::vector< CatalogEntry > | entries |
FileId | next_fid |
std::uint32_t | num_valid_entries |
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.
db_metadta_filename: name of file to save DB state to |
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, | ||
SearchKeyFormat * | key_format, | ||
CatType | type, | ||
FileId | relation, | ||
std::string | file_name, | ||
bool | to_save = true |
||
) |
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). |
relation | The FileId of the relation if entry created is index. |
file_name | The name of the file into which the DiskManager stores the relation. |
to_save | boolean indicator of whether or not the new catalog entry upon shutdown of SwatDB. Default to false. |
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 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 FileId for the relation file associated with the given index file id.
file_id. | FileId of an index. |
InvalidFileIdCat | if the given FileId is not valid or if it is the FileId of a relation file. |
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. |
void Catalog::setRelName | ( | std::string | old_rel_name, |
std::string | new_rel_name | ||
) |
Setter method for the relation name and file name of a relation. Note that both the rel_name and the name of the file on disk will be changed.
old_rel_name. | Relation name currently being used. |
new_rel_name. | Relation name to set. |
void Catalog::setSave | ( | bool | save_on_exit, |
std::string | rel_name | ||
) |
Setter method for the boolean save_on_exit.
save_on_exit. | bool to set save_on_exit to of the catalog entry associated with the rel_name. if true the catalog will save the file to disk when the program exits. |
rel_name. | std::string of the relation to change save_on_exit. |
|
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 increase as SwatDB adds entries. Deleting an entry sets its valid and allocated fields to false. The FileId of invalid files remain in the vector of CatalogEntry and can be re-used by new file or index adds as swatdb runs. If there are no invalid existing entries, a new one is added to the Catalog with a FileID value of next_fid, and next_fid is incremented..
|
private |