0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-29 02:02:38 +01:00

ircd::db: Add SST scan interface w/ console suite.

This commit is contained in:
Jason Volk 2021-11-17 17:07:24 -08:00
parent 5f5c1db9b1
commit d0a1d32488
4 changed files with 172 additions and 1 deletions

View file

@ -15,6 +15,7 @@ struct ircd::db::database::sst
{ {
struct info; struct info;
struct dump; struct dump;
struct scan;
[[deprecated]] [[deprecated]]
static void tool(const vector_view<const string_view> &args); static void tool(const vector_view<const string_view> &args);
@ -97,3 +98,11 @@ struct ircd::db::database::sst::dump
dump(dump &&) = delete; dump(dump &&) = delete;
dump(const dump &) = delete; dump(const dump &) = delete;
}; };
struct ircd::db::database::sst::scan
{
using closure = std::function<bool (const string_view &, const string_view &)>;
scan(db::database &, const string_view &path, const closure &);
scan(db::database &, const string_view &path); // VerifyChecksum
};

View file

@ -50,6 +50,7 @@
#include <rocksdb/filter_policy.h> #include <rocksdb/filter_policy.h>
#include <rocksdb/table.h> #include <rocksdb/table.h>
#include <rocksdb/sst_file_manager.h> #include <rocksdb/sst_file_manager.h>
#include <rocksdb/sst_file_reader.h>
#include <rocksdb/sst_dump_tool.h> #include <rocksdb/sst_dump_tool.h>
#include <rocksdb/compaction_filter.h> #include <rocksdb/compaction_filter.h>
#include <rocksdb/wal_filter.h> #include <rocksdb/wal_filter.h>

View file

@ -3615,7 +3615,98 @@ ircd::db::database::sst::tool(const vector_view<const string_view> &args)
} }
// //
// sst::dump::dump // sst::scan
//
ircd::db::database::sst::scan::scan(database &d,
const string_view &fpath)
{
const auto &opts
{
d.d->GetOptions()
};
rocksdb::SstFileReader reader
{
opts
};
const string_view path_parts[]
{
fs::base::db, db::name(d), fpath
};
const auto path
{
fs::path_string(path_parts)
};
throw_on_error
{
reader.Open(path)
};
db::gopts gopts;
throw_on_error
{
reader.VerifyChecksum(make_opts(gopts))
};
}
ircd::db::database::sst::scan::scan(database &d,
const string_view &fpath,
const closure &call)
{
const auto &opts
{
d.d->GetOptions()
};
rocksdb::SstFileReader reader
{
opts
};
const string_view path_parts[]
{
fs::base::db, db::name(d), fpath
};
const auto path
{
fs::path_string(path_parts)
};
throw_on_error
{
reader.Open(path)
};
db::gopts gopts;
std::unique_ptr<rocksdb::Iterator> it
{
reader.NewIterator(make_opts(gopts))
};
for(it->SeekToFirst(); db::valid(*it); it->Next())
{
const auto &key
{
slice(it->key())
};
const auto &val
{
slice(it->value())
};
if(!call(key, val))
break;
}
}
//
// sst::dump
// //
ircd::db::database::sst::dump::dump(db::column column, ircd::db::database::sst::dump::dump(db::column column,

View file

@ -4711,6 +4711,76 @@ console_cmd__db__sst__dump(opt &out, const string_view &line)
return true; return true;
} }
bool
console_cmd__db__sst__scan(opt &out, const string_view &line)
{
const params param{line, " ",
{
"dbname", "path",
}};
const auto dbname
{
param.at("dbname")
};
const auto path
{
param.at("path")
};
auto &database
{
db::database::get(dbname)
};
db::database::sst::scan
{
database, path
};
out << "Completed without error." << std::endl;
return true;
}
bool
console_cmd__db__sst__scan__count(opt &out, const string_view &line)
{
const params param{line, " ",
{
"dbname", "path",
}};
const auto dbname
{
param.at("dbname")
};
const auto path
{
param.at("path")
};
auto &database
{
db::database::get(dbname)
};
size_t i(0);
db::database::sst::scan
{
database, path, [&out, &i]
(const auto &key, const auto &val)
{
++i;
return true;
}
};
out << "Found " << i << " entries." << std::endl;
return true;
}
bool bool
console_cmd__db__wal(opt &out, const string_view &line) console_cmd__db__wal(opt &out, const string_view &line)
try try