0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-06-29 15:28:20 +02:00

ircd::db: Add WAL fflush; move table flushes to "sort()"; adjust interfaces.

This commit is contained in:
Jason Volk 2018-04-26 17:19:29 -07:00
parent 93ca1448d1
commit 8083a5d71c
4 changed files with 75 additions and 22 deletions

View file

@ -48,7 +48,7 @@ namespace ircd::db
// [SET] Other operations
void setopt(column &, const string_view &key, const string_view &val);
void compact(column &, const string_view &begin = {}, const string_view &end = {});
void flush(column &, const bool &blocking = false);
void sort(column &, const bool &blocking = false);
}
/// Columns add the ability to run multiple LevelDB's in synchrony under the same

View file

@ -44,10 +44,11 @@ namespace ircd::db
// Control panel
void setopt(database &, const string_view &key, const string_view &val);
void compact(database &);
void fdeletions(database &, const bool &enable, const bool &force = false);
void checkpoint(database &, const string_view &dir);
void flush(database &, const bool &blocking = true);
void compact(database &);
void sort(database &, const bool &blocking = true);
void flush(database &, const bool &sync = false);
void sync(database &);
}

View file

@ -135,12 +135,36 @@ ircd::db::sync(database &d)
/// each column individually.
void
ircd::db::flush(database &d,
const bool &blocking)
const bool &sync)
{
throw_on_error
{
d.d->FlushWAL(sync)
};
}
/// Moves memory structures to SST files for all columns. This doesn't
/// necessarily sort anything that wasn't previously sorted, but it may create
/// new SST files and shouldn't be confused with a typical fflush().
/// Note that if blocking=true, blocking may occur for each column individually.
void
ircd::db::sort(database &d,
const bool &blocking)
{
for(const auto &c : d.columns)
{
db::column column{*c};
db::flush(column, blocking);
db::sort(column, blocking);
}
}
void
ircd::db::compact(database &d)
{
for(const auto &c : d.columns)
{
db::column column{*c};
compact(column, string_view{}, string_view{});
}
}
@ -190,16 +214,6 @@ ircd::db::fdeletions(database &d,
};
}
void
ircd::db::compact(database &d)
{
for(const auto &c : d.columns)
{
db::column column{*c};
compact(column, string_view{}, string_view{});
}
}
void
ircd::db::setopt(database &d,
const string_view &key,
@ -628,12 +642,16 @@ noexcept try
path);
rocksdb::CancelAllBackgroundWork(d.get(), true); // true = blocking
this->checkpoint.reset(nullptr);
this->columns.clear();
log.debug("'%s': closed columns; background_errors: %lu; synchronizing...",
log.debug("'%s': background_errors: %lu; flushing...",
name,
property<uint64_t>(*this, rocksdb::DB::Properties::kBackgroundErrors));
flush(*this);
this->checkpoint.reset(nullptr);
this->columns.clear();
log.debug("'%s': closed columns; synchronizing...",
name);
sync(*this);
log.debug("'%s': synchronized with hardware.",
name);
@ -3944,14 +3962,14 @@ ircd::db::describe(const column &column)
}
void
ircd::db::flush(column &column,
const bool &blocking)
ircd::db::sort(column &column,
const bool &blocking)
{
database::column &c(column);
database &d(*c.d);
rocksdb::FlushOptions opts;
opts.wait = blocking;
log.debug("'%s':'%s' @%lu FLUSH",
log.debug("'%s':'%s' @%lu FLUSH (sort)",
name(d),
name(c),
sequence(d));

View file

@ -818,6 +818,40 @@ catch(const std::out_of_range &e)
bool
console_cmd__db__flush(opt &out, const string_view &line)
try
{
const params param{line, " ",
{
"dbname", "[sync]"
}};
const auto dbname
{
param.at(0)
};
const auto sync
{
param.at(1, false)
};
auto &database
{
*db::database::dbs.at(dbname)
};
flush(database, sync);
out << "done" << std::endl;
return true;
}
catch(const std::out_of_range &e)
{
out << "No open database by that name" << std::endl;
return true;
}
bool
console_cmd__db__sort(opt &out, const string_view &line)
try
{
const params param{line, " ",
{
@ -839,7 +873,7 @@ try
*db::database::dbs.at(dbname)
};
flush(database, blocking);
sort(database, blocking);
out << "done" << std::endl;
return true;
}