Class MetadataDB

Class Documentation

class gkfs::metadata::MetadataDB

Public Functions

MetadataDB(const std::string &path, const std::string_view database)
~MetadataDB()
std::string get(const std::string &key) const

Gets the KV store value for a key.

Parameters

key – KV store key

Throws

DBException – on failure, NotFoundException if entry doesn’t exist

Returns

KV store value

void put(const std::string &key, const std::string &val)

Puts an entry into the KV store.

Parameters
  • key – KV store key

  • val – KV store value

Throws

DBException

void put_no_exist(const std::string &key, const std::string &val)

Puts an entry into the KV store if it doesn’t exist.

Parameters
  • key – KV store key

  • val – KV store value

Throws

DBException – on failure, ExistException if entry already exists

void remove(const std::string &key)

Removes an entry from the KV store.

Parameters

key – KV store key

Throws

DBException – on failure, NotFoundException if entry doesn’t exist

bool exists(const std::string &key)

Checks for existence of an entry.

Parameters

key – KV store key

Throws

DBException – on failure, NotFoundException if entry doesn’t exist

Returns

true if exists

void update(const std::string &old_key, const std::string &new_key, const std::string &val)

Updates a metadata entry atomically and also allows to change keys.

Parameters
  • old_key – KV store key to be replaced

  • new_key – new KV store key

  • val – KV store value

Throws

DBException – on failure, NotFoundException if entry doesn’t exist

off_t increase_size(const std::string &key, size_t io_size, off_t offset, bool append)

Increases only the size part of the metadata entry via a RocksDB Operand as part of a write operation.

Parameters
  • key – KV store key

  • io_size – new size for entry

  • append

Throws

DBException – on failure, NotFoundException if entry doesn’t exist

void decrease_size(const std::string &key, size_t size)

Decreases only the size part of the metadata entry via a RocksDB Operand. This is used for truncate, e.g..

Parameters
  • key – KV store key

  • size – new size for entry

Throws

DBException – on failure, NotFoundException if entry doesn’t exist

std::vector<std::pair<std::string, bool>> get_dirents(const std::string &dir) const

Return all file names and modes for the first-level entries of the given directory.

Parameters

dir – directory prefix string

Returns

vector of pair <std::string name, bool is_dir>, where name is the name of the entries and is_dir is true in the case the entry is a directory.

std::vector<std::tuple<std::string, bool, size_t, time_t>> get_dirents_extended(const std::string &dir) const

Return all file names and modes for the first-level entries of the given directory including their sizes and creation time.

Parameters

dir – directory prefix string

Returns

vector of pair <std::string name, bool is_dir - size - ctime>, where name is the name of the entries and is_dir is true in the case the entry is a directory.

void iterate_all() const

Iterate over complete database, note ONLY used for debugging and is therefore unused.

Private Members

std::string path_
std::shared_ptr<spdlog::logger> log_
std::unique_ptr<AbstractMetadataBackend> backend_