From c06dd2e9dff840e8a0cb74286da79ab2e149ef99 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Tue, 23 Jan 2018 15:39:44 -0800 Subject: [PATCH] ircd::db: Split internal db header. --- ircd/db.cc | 77 +++++------------------------------------------------ ircd/db.h | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+), 70 deletions(-) create mode 100644 ircd/db.h diff --git a/ircd/db.cc b/ircd/db.cc index f19cdba87..826debdca 100644 --- a/ircd/db.cc +++ b/ircd/db.cc @@ -48,84 +48,21 @@ #include #include -namespace ircd::db -{ - const auto BLOCKING = rocksdb::ReadTier::kReadAllTier; - const auto NON_BLOCKING = rocksdb::ReadTier::kBlockCacheTier; - const auto DEFAULT_READAHEAD = 4_MiB; +#include "db.h" - struct throw_on_error; - - string_view reflect(const rocksdb::Env::Priority &p); - string_view reflect(const rocksdb::Env::IOPriority &p); - string_view reflect(const rocksdb::RandomAccessFile::AccessPattern &p); - const std::string &reflect(const rocksdb::Tickers &); - const std::string &reflect(const rocksdb::Histograms &); - rocksdb::Slice slice(const string_view &); - string_view slice(const rocksdb::Slice &); - - // Frequently used get options and set options are separate from the string/map system - rocksdb::WriteOptions &operator+=(rocksdb::WriteOptions &, const sopts &); - rocksdb::ReadOptions &operator+=(rocksdb::ReadOptions &, const gopts &); - rocksdb::WriteOptions make_opts(const sopts &); - rocksdb::ReadOptions make_opts(const gopts &); - - // Database options creator - bool optstr_find_and_remove(std::string &optstr, const std::string &what); - rocksdb::DBOptions make_dbopts(std::string &optstr, bool *read_only = nullptr, bool *fsck = nullptr); - template rocksdb::DBOptions make_dbopts(const std::string &, args&&...); - - // Validation functors - bool valid(const rocksdb::Iterator &); - bool operator!(const rocksdb::Iterator &); - using valid_proffer = std::function; - bool valid(const rocksdb::Iterator &, const valid_proffer &); - bool valid_eq(const rocksdb::Iterator &, const string_view &); - bool valid_lte(const rocksdb::Iterator &, const string_view &); - bool valid_gt(const rocksdb::Iterator &, const string_view &); - void valid_or_throw(const rocksdb::Iterator &); - void valid_eq_or_throw(const rocksdb::Iterator &, const string_view &); - - // [GET] seek suite - template bool seek(database::column &, const pos &, const rocksdb::ReadOptions &, std::unique_ptr &it); - template bool seek(database::column &, const pos &, const gopts &, std::unique_ptr &it); - std::unique_ptr seek(column &, const gopts &); - std::unique_ptr seek(column &, const string_view &key, const gopts &); - std::vector seek(database &, const gopts &); - - std::pair operator*(const rocksdb::Iterator &); - - // [SET] writebatch suite - std::string debug(const rocksdb::WriteBatch &); - bool has(const rocksdb::WriteBatch &, const op &); - void commit(database &, rocksdb::WriteBatch &, const rocksdb::WriteOptions &); - void commit(database &, rocksdb::WriteBatch &, const sopts &); - void append(rocksdb::WriteBatch &, column &, const column::delta &delta); - void append(rocksdb::WriteBatch &, const cell::delta &delta); - - std::vector column_names(const std::string &path, const rocksdb::DBOptions &); - std::vector column_names(const std::string &path, const std::string &options); -} - -struct ircd::db::throw_on_error -{ - throw_on_error(const rocksdb::Status & = rocksdb::Status::OK()); -}; - -ircd::log::log ircd::db::log +decltype(ircd::db::log) +ircd::db::log { // Dedicated logging facility for the database subsystem "db", 'D' }; -namespace ircd::db +decltype(ircd::db::rog) +ircd::db::rog { // Dedicated logging facility for rocksdb's log callbacks - log::log rog - { - "rdb", 'R' - }; -} + "rdb", 'R' +}; std::map ircd::db::database::dbs diff --git a/ircd/db.h b/ircd/db.h new file mode 100644 index 000000000..bc5970fe3 --- /dev/null +++ b/ircd/db.h @@ -0,0 +1,78 @@ +// Matrix Construct +// +// Copyright (C) Matrix Construct Developers, Authors & Contributors +// Copyright (C) 2016-2018 Jason Volk +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice is present in all copies. The +// full license for this software is available in the LICENSE file. + +#pragma once + +namespace ircd::db +{ + struct throw_on_error; + + const auto BLOCKING = rocksdb::ReadTier::kReadAllTier; + const auto NON_BLOCKING = rocksdb::ReadTier::kBlockCacheTier; + const auto DEFAULT_READAHEAD = 4_MiB; + + // Dedicated logging facility for rocksdb's log callbacks + extern log::log rog; + + string_view reflect(const rocksdb::Env::Priority &p); + string_view reflect(const rocksdb::Env::IOPriority &p); + string_view reflect(const rocksdb::RandomAccessFile::AccessPattern &p); + const std::string &reflect(const rocksdb::Tickers &); + const std::string &reflect(const rocksdb::Histograms &); + rocksdb::Slice slice(const string_view &); + string_view slice(const rocksdb::Slice &); + + // Frequently used get options and set options are separate from the string/map system + rocksdb::WriteOptions &operator+=(rocksdb::WriteOptions &, const sopts &); + rocksdb::ReadOptions &operator+=(rocksdb::ReadOptions &, const gopts &); + rocksdb::WriteOptions make_opts(const sopts &); + rocksdb::ReadOptions make_opts(const gopts &); + + // Database options creator + bool optstr_find_and_remove(std::string &optstr, const std::string &what); + rocksdb::DBOptions make_dbopts(std::string &optstr, bool *read_only = nullptr, bool *fsck = nullptr); + template rocksdb::DBOptions make_dbopts(const std::string &, args&&...); + + // Validation functors + bool valid(const rocksdb::Iterator &); + bool operator!(const rocksdb::Iterator &); + using valid_proffer = std::function; + bool valid(const rocksdb::Iterator &, const valid_proffer &); + bool valid_eq(const rocksdb::Iterator &, const string_view &); + bool valid_lte(const rocksdb::Iterator &, const string_view &); + bool valid_gt(const rocksdb::Iterator &, const string_view &); + void valid_or_throw(const rocksdb::Iterator &); + void valid_eq_or_throw(const rocksdb::Iterator &, const string_view &); + + // [GET] seek suite + template bool seek(database::column &, const pos &, const rocksdb::ReadOptions &, std::unique_ptr &it); + template bool seek(database::column &, const pos &, const gopts &, std::unique_ptr &it); + std::unique_ptr seek(column &, const gopts &); + std::unique_ptr seek(column &, const string_view &key, const gopts &); + std::vector seek(database &, const gopts &); + + std::pair operator*(const rocksdb::Iterator &); + + // [SET] writebatch suite + std::string debug(const rocksdb::WriteBatch &); + bool has(const rocksdb::WriteBatch &, const op &); + void commit(database &, rocksdb::WriteBatch &, const rocksdb::WriteOptions &); + void commit(database &, rocksdb::WriteBatch &, const sopts &); + void append(rocksdb::WriteBatch &, column &, const column::delta &delta); + void append(rocksdb::WriteBatch &, const cell::delta &delta); + + std::vector column_names(const std::string &path, const rocksdb::DBOptions &); + std::vector column_names(const std::string &path, const std::string &options); +} + +struct ircd::db::throw_on_error +{ + throw_on_error(const rocksdb::Status & = rocksdb::Status::OK()); +};