mirror of
https://github.com/matrix-construct/construct
synced 2024-05-20 03:43:47 +02:00
ircd::db: Add conf items to connect database options to ircd::conf.
This commit is contained in:
parent
fc06ea8ded
commit
ab7dd15618
|
@ -108,7 +108,7 @@ struct ircd::db::database
|
|||
uint64_t checkpoint;
|
||||
std::string path;
|
||||
std::string optstr;
|
||||
bool fsck, slave, read_only;
|
||||
bool fsck, slave, read_only, opened;
|
||||
std::shared_ptr<struct env> env;
|
||||
std::shared_ptr<struct stats> stats;
|
||||
std::shared_ptr<struct logger> logger;
|
||||
|
@ -121,6 +121,7 @@ struct ircd::db::database
|
|||
std::shared_ptr<rocksdb::Cache> row_cache;
|
||||
std::vector<descriptor> descriptors;
|
||||
std::unique_ptr<rocksdb::DBOptions> opts;
|
||||
std::vector<std::unique_ptr<conf::item<std::string>>> confs;
|
||||
std::unordered_map<string_view, std::shared_ptr<column>> column_names;
|
||||
std::unique_ptr<rocksdb::DB> d;
|
||||
ctx::mutex write_mutex;
|
||||
|
|
61
ircd/db.cc
61
ircd/db.cc
|
@ -5357,6 +5357,67 @@ ircd::db::optstr_find_and_remove(std::string &optstr,
|
|||
return true;
|
||||
}
|
||||
|
||||
std::vector<std::unique_ptr<ircd::conf::item<std::string>>>
|
||||
ircd::db::make_confs(const db::options &opts,
|
||||
const pair<string_view> &name,
|
||||
const conf::set_cb &setter)
|
||||
{
|
||||
const db::options::map map(opts);
|
||||
|
||||
std::vector<std::unique_ptr<conf::item<std::string>>> ret;
|
||||
ret.reserve(map.size());
|
||||
|
||||
char buf[512];
|
||||
for(const auto &[key, val] : map)
|
||||
ret.emplace_back(std::make_unique<conf::item<std::string>>
|
||||
(
|
||||
json::members
|
||||
{
|
||||
{ "name", make_conf_name(buf, name, key) },
|
||||
{ "default", string_view{val} },
|
||||
},
|
||||
setter
|
||||
));
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
ircd::string_view
|
||||
ircd::db::unmake_conf_name_key(const conf::item<void> &item)
|
||||
{
|
||||
const auto &name
|
||||
{
|
||||
lstrip(lstrip(item.name, confs_prefix), '.')
|
||||
};
|
||||
|
||||
const auto &[dbname, remain]
|
||||
{
|
||||
split(name, '.')
|
||||
};
|
||||
|
||||
const auto &[colname, key]
|
||||
{
|
||||
split(remain, '.')
|
||||
};
|
||||
|
||||
return key;
|
||||
}
|
||||
|
||||
ircd::string_view
|
||||
ircd::db::make_conf_name(const mutable_buffer &buf,
|
||||
const pair<string_view> &name,
|
||||
const string_view &key)
|
||||
{
|
||||
return fmt::sprintf
|
||||
{
|
||||
buf, "%s.%s.%s.%s",
|
||||
confs_prefix,
|
||||
name.first,
|
||||
name.second,
|
||||
key,
|
||||
};
|
||||
}
|
||||
|
||||
decltype(ircd::db::read_checksum)
|
||||
ircd::db::read_checksum
|
||||
{
|
||||
|
|
|
@ -104,6 +104,13 @@ namespace ircd::db
|
|||
rocksdb::WriteOptions make_opts(const sopts &) noexcept;
|
||||
rocksdb::ReadOptions make_opts(const gopts &) noexcept;
|
||||
|
||||
// Database options as ircd::conf items.
|
||||
static const string_view confs_prefix {"ircd.db"};
|
||||
using confs = std::vector<std::unique_ptr<conf::item<std::string>>>;
|
||||
string_view make_conf_name(const mutable_buffer &, const pair<string_view> &, const string_view &);
|
||||
string_view unmake_conf_name_key(const conf::item<void> &);
|
||||
confs make_confs(const db::options &, const pair<string_view> &, const conf::set_cb &);
|
||||
|
||||
// Database options creator
|
||||
static bool optstr_find_and_remove(std::string &optstr, const std::string &what);
|
||||
rocksdb::DBOptions make_dbopts(std::string optstr, std::string *const &out = nullptr, bool *read_only = nullptr, bool *fsck = nullptr);
|
||||
|
@ -397,6 +404,8 @@ ircd::db::database::column final
|
|||
std::shared_ptr<struct database::stats> stats;
|
||||
std::shared_ptr<struct database::allocator> allocator;
|
||||
rocksdb::BlockBasedTableOptions table_opts;
|
||||
const bool options_preconfiguration;
|
||||
std::vector<std::unique_ptr<conf::item<std::string>>> confs;
|
||||
custom_ptr<rocksdb::ColumnFamilyHandle> handle;
|
||||
|
||||
public:
|
||||
|
|
|
@ -713,6 +713,7 @@ ircd::db::name(const database &d)
|
|||
namespace ircd::db
|
||||
{
|
||||
extern const description default_description;
|
||||
static options::map conf_open_opts;
|
||||
}
|
||||
|
||||
// Instance list linkage
|
||||
|
@ -864,6 +865,10 @@ try
|
|||
{
|
||||
slave || ircd::read_only
|
||||
}
|
||||
,opened
|
||||
{
|
||||
false
|
||||
}
|
||||
,env
|
||||
{
|
||||
std::make_shared<struct env>(this)
|
||||
|
@ -1073,6 +1078,51 @@ try
|
|||
|
||||
return opts;
|
||||
}()}
|
||||
,confs{[this]() -> db::confs
|
||||
{
|
||||
const pair<string_view> name
|
||||
{
|
||||
this->name, "db"
|
||||
};
|
||||
|
||||
auto ret
|
||||
{
|
||||
make_confs(db::options(*this->opts), name, [this]
|
||||
(const conf::item<void> &item)
|
||||
{
|
||||
const string_view key
|
||||
{
|
||||
unmake_conf_name_key(item)
|
||||
};
|
||||
|
||||
const string_view val
|
||||
{
|
||||
dynamic_cast<const conf::item<std::string> &>(item)
|
||||
};
|
||||
|
||||
// The conf setter can be called prior to open (by an env var) in
|
||||
// which case we integrate the conf with the options passed at open.
|
||||
if(!this->opened)
|
||||
{
|
||||
conf_open_opts.emplace(key, val);
|
||||
return;
|
||||
}
|
||||
|
||||
//const db::database &d(*this);
|
||||
//db::setopt(mutable_cast(d), key, val);
|
||||
})
|
||||
};
|
||||
|
||||
// Merge any conf item results (likely set by env var at this point) into
|
||||
// the master options.
|
||||
if(!conf_open_opts.empty())
|
||||
{
|
||||
this->opts = std::make_unique<rocksdb::DBOptions>(conf_open_opts.merge(*this->opts));
|
||||
conf_open_opts.clear();
|
||||
}
|
||||
|
||||
return ret;
|
||||
}()}
|
||||
,column_names{[this]
|
||||
{
|
||||
// Existing columns at path. If any are left the descriptor set did not
|
||||
|
@ -1297,6 +1347,7 @@ try
|
|||
check(*this);
|
||||
}
|
||||
|
||||
opened = true;
|
||||
log::info
|
||||
{
|
||||
log, "[%s] Opened database @ `%s' with %zu columns at sequence number %lu.",
|
||||
|
@ -1426,6 +1477,7 @@ noexcept try
|
|||
d->Close()
|
||||
};
|
||||
|
||||
opened = false;
|
||||
env->st.reset(nullptr);
|
||||
|
||||
log::info
|
||||
|
@ -1691,15 +1743,7 @@ ircd::db::database::column::column(database &d,
|
|||
std::make_shared<struct database::allocator>(this->d, this, database::allocator::cache_arena, descriptor.block_size)
|
||||
#endif
|
||||
}
|
||||
,handle
|
||||
{
|
||||
nullptr, [&d](rocksdb::ColumnFamilyHandle *const handle)
|
||||
{
|
||||
assert(d.d);
|
||||
if(handle && d.d)
|
||||
d.d->DestroyColumnFamilyHandle(handle);
|
||||
}
|
||||
}
|
||||
,options_preconfiguration{[this]
|
||||
{
|
||||
// If possible, deduce comparator based on type given in descriptor
|
||||
if(!this->descriptor->cmp.less)
|
||||
|
@ -1953,7 +1997,59 @@ ircd::db::database::column::column(database &d,
|
|||
|
||||
// Finally set the table options in the column options.
|
||||
this->options.table_factory.reset(rocksdb::NewBlockBasedTableFactory(table_opts));
|
||||
return true;
|
||||
}()}
|
||||
,confs{[this]() -> db::confs
|
||||
{
|
||||
const pair<string_view> name
|
||||
{
|
||||
this->d->name, this->descriptor->name
|
||||
};
|
||||
|
||||
auto ret
|
||||
{
|
||||
make_confs(db::options(this->options), name, [this]
|
||||
(const conf::item<void> &item)
|
||||
{
|
||||
const string_view key
|
||||
{
|
||||
unmake_conf_name_key(item)
|
||||
};
|
||||
|
||||
const string_view val
|
||||
{
|
||||
dynamic_cast<const conf::item<std::string> &>(item)
|
||||
};
|
||||
|
||||
if(!this->d->opened)
|
||||
{
|
||||
conf_open_opts.emplace(key, val);
|
||||
return;
|
||||
}
|
||||
|
||||
//const db::column &c(*this);
|
||||
//db::setopt(mutable_cast(c), key, val);
|
||||
})
|
||||
};
|
||||
|
||||
if(!conf_open_opts.empty())
|
||||
{
|
||||
this->options = conf_open_opts.merge(this->options);
|
||||
conf_open_opts.clear();
|
||||
}
|
||||
|
||||
return ret;
|
||||
}()}
|
||||
,handle
|
||||
{
|
||||
nullptr, [&d](rocksdb::ColumnFamilyHandle *const handle)
|
||||
{
|
||||
assert(d.d);
|
||||
if(handle && d.d)
|
||||
d.d->DestroyColumnFamilyHandle(handle);
|
||||
}
|
||||
}
|
||||
{
|
||||
log::debug
|
||||
{
|
||||
log, "schema '%s' column [%s => %s] cmp[%s] pfx[%s] lru:%s:%s bloom:%zu compression:%d %s",
|
||||
|
@ -1962,9 +2058,9 @@ ircd::db::database::column::column(database &d,
|
|||
demangle(mapped_type.name()),
|
||||
this->cmp.Name(),
|
||||
this->options.prefix_extractor? this->prefix.Name() : "none",
|
||||
cache_size? "YES": "NO",
|
||||
cache_size_comp? "YES": "NO",
|
||||
bloom_bits,
|
||||
table_opts.block_cache? "YES": "NO",
|
||||
table_opts.block_cache_compressed? "YES": "NO",
|
||||
this->descriptor->bloom_bits,
|
||||
int(this->options.compression),
|
||||
this->descriptor->name
|
||||
};
|
||||
|
|
|
@ -2256,7 +2256,7 @@ console_cmd__conf__list(opt &out, const string_view &line)
|
|||
};
|
||||
|
||||
out
|
||||
<< std::setw(64) << std::left << std::setfill('_') << _key
|
||||
<< std::setw(80) << std::left << std::setfill('_') << _key
|
||||
<< " " << item_p->get(val + size(_key))
|
||||
<< std::endl;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue