mirror of
https://github.com/matrix-construct/construct
synced 2024-11-17 23:40:57 +01:00
ircd::db: Add closure on manual compaction arguments.
This commit is contained in:
parent
9afac08e40
commit
7427ec991c
3 changed files with 38 additions and 10 deletions
|
@ -59,8 +59,8 @@ namespace ircd::db
|
||||||
|
|
||||||
// [SET] Other operations
|
// [SET] Other operations
|
||||||
void setopt(column &, const string_view &key, const string_view &val);
|
void setopt(column &, const string_view &key, const string_view &val);
|
||||||
void compact(column &, const std::pair<string_view, string_view> &, const int &to_level = -1);
|
void compact(column &, const std::pair<string_view, string_view> &, const compactor & = {});
|
||||||
void compact(column &, const int &level = -1);
|
void compact(column &, const int &level = -1, const compactor & = {});
|
||||||
void sort(column &, const bool &blocking = false);
|
void sort(column &, const bool &blocking = false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,7 @@ namespace ircd::db
|
||||||
void fdeletions(database &, const bool &enable, const bool &force = false);
|
void fdeletions(database &, const bool &enable, const bool &force = false);
|
||||||
uint64_t checkpoint(database &);
|
uint64_t checkpoint(database &);
|
||||||
void check(database &);
|
void check(database &);
|
||||||
void compact(database &);
|
void compact(database &, const compactor & = {});
|
||||||
void sort(database &, const bool &blocking = true);
|
void sort(database &, const bool &blocking = true);
|
||||||
void flush(database &, const bool &sync = false);
|
void flush(database &, const bool &sync = false);
|
||||||
void sync(database &);
|
void sync(database &);
|
||||||
|
|
42
ircd/db.cc
42
ircd/db.cc
|
@ -347,7 +347,8 @@ ircd::db::sort(database &d,
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ircd::db::compact(database &d)
|
ircd::db::compact(database &d,
|
||||||
|
const compactor &cb)
|
||||||
{
|
{
|
||||||
static const std::pair<string_view, string_view> range
|
static const std::pair<string_view, string_view> range
|
||||||
{
|
{
|
||||||
|
@ -357,8 +358,8 @@ ircd::db::compact(database &d)
|
||||||
for(const auto &c : d.columns)
|
for(const auto &c : d.columns)
|
||||||
{
|
{
|
||||||
db::column column{*c};
|
db::column column{*c};
|
||||||
compact(column, range, -1);
|
compact(column, range, cb);
|
||||||
compact(column, -1);
|
compact(column, -1, cb);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7350,7 +7351,8 @@ ircd::db::sort(column &column,
|
||||||
|
|
||||||
void
|
void
|
||||||
ircd::db::compact(column &column,
|
ircd::db::compact(column &column,
|
||||||
const int &level_)
|
const int &level_,
|
||||||
|
const compactor &cb)
|
||||||
{
|
{
|
||||||
database::column &c(column);
|
database::column &c(column);
|
||||||
database &d(*c.d);
|
database &d(*c.d);
|
||||||
|
@ -7382,6 +7384,19 @@ ircd::db::compact(column &column,
|
||||||
ctx::interruption_point();
|
ctx::interruption_point();
|
||||||
const ctx::uninterruptible::nothrow ui;
|
const ctx::uninterruptible::nothrow ui;
|
||||||
const std::lock_guard<decltype(write_mutex)> lock{write_mutex};
|
const std::lock_guard<decltype(write_mutex)> lock{write_mutex};
|
||||||
|
|
||||||
|
// Save and restore the existing filter callback so we can allow our
|
||||||
|
// caller to use theirs. Note that this manual compaction should be
|
||||||
|
// exclusive for this column (no background compaction should be
|
||||||
|
// occurring, at least one relying on this filter).
|
||||||
|
auto their_filter(std::move(c.cfilter.user));
|
||||||
|
const unwind unfilter{[&c, &their_filter]
|
||||||
|
{
|
||||||
|
c.cfilter.user = std::move(their_filter);
|
||||||
|
}};
|
||||||
|
|
||||||
|
c.cfilter.user = cb;
|
||||||
|
|
||||||
log::debug
|
log::debug
|
||||||
{
|
{
|
||||||
log, "'%s':'%s' COMPACT level:%d files:%zu size:%zu",
|
log, "'%s':'%s' COMPACT level:%d files:%zu size:%zu",
|
||||||
|
@ -7402,7 +7417,7 @@ ircd::db::compact(column &column,
|
||||||
void
|
void
|
||||||
ircd::db::compact(column &column,
|
ircd::db::compact(column &column,
|
||||||
const std::pair<string_view, string_view> &range,
|
const std::pair<string_view, string_view> &range,
|
||||||
const int &to_level)
|
const compactor &cb)
|
||||||
{
|
{
|
||||||
database &d(column);
|
database &d(column);
|
||||||
database::column &c(column);
|
database::column &c(column);
|
||||||
|
@ -7421,11 +7436,24 @@ ircd::db::compact(column &column,
|
||||||
|
|
||||||
rocksdb::CompactRangeOptions opts;
|
rocksdb::CompactRangeOptions opts;
|
||||||
opts.change_level = true;
|
opts.change_level = true;
|
||||||
opts.target_level = to_level;
|
opts.target_level = -1;
|
||||||
opts.allow_write_stall = true;
|
opts.allow_write_stall = true;
|
||||||
|
|
||||||
const ctx::uninterruptible::nothrow ui;
|
const ctx::uninterruptible::nothrow ui;
|
||||||
const std::lock_guard<decltype(write_mutex)> lock{write_mutex};
|
const std::lock_guard<decltype(write_mutex)> lock{write_mutex};
|
||||||
|
|
||||||
|
// Save and restore the existing filter callback so we can allow our
|
||||||
|
// caller to use theirs. Note that this manual compaction should be
|
||||||
|
// exclusive for this column (no background compaction should be
|
||||||
|
// occurring, at least one relying on this filter).
|
||||||
|
auto their_filter(std::move(c.cfilter.user));
|
||||||
|
const unwind unfilter{[&c, &their_filter]
|
||||||
|
{
|
||||||
|
c.cfilter.user = std::move(their_filter);
|
||||||
|
}};
|
||||||
|
|
||||||
|
c.cfilter.user = cb;
|
||||||
|
|
||||||
log::debug
|
log::debug
|
||||||
{
|
{
|
||||||
log, "'%s':'%s' @%lu COMPACT [%s, %s] to level %d",
|
log, "'%s':'%s' @%lu COMPACT [%s, %s] to level %d",
|
||||||
|
@ -7434,7 +7462,7 @@ ircd::db::compact(column &column,
|
||||||
sequence(d),
|
sequence(d),
|
||||||
range.first,
|
range.first,
|
||||||
range.second,
|
range.second,
|
||||||
to_level
|
opts.target_level
|
||||||
};
|
};
|
||||||
|
|
||||||
throw_on_error
|
throw_on_error
|
||||||
|
|
Loading…
Reference in a new issue