0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-25 16:22:35 +01:00

modules/m_state: Checkpoint preliminary GC util.

This commit is contained in:
Jason Volk 2018-12-03 17:34:43 -08:00
parent b025de1068
commit 2a2a8bcf86
2 changed files with 75 additions and 0 deletions

View file

@ -5279,6 +5279,24 @@ console_cmd__state__root(opt &out, const string_view &line)
return true;
}
bool
console_cmd__state__gc(opt &out, const string_view &line)
{
using prototype = size_t ();
static mods::import<prototype> gc
{
"m_state", "ircd__m__state__gc"
};
const size_t count
{
gc()
};
out << "done: " << count << std::endl;
return true;
}
//
// commit
//

View file

@ -15,3 +15,60 @@ IRCD_MODULE
{
"Matrix state library; modular components."
};
namespace ircd::m::state
{
extern "C" size_t ircd__m__state__gc(void);
}
size_t
ircd::m::state::ircd__m__state__gc()
{
std::set<id_buffer> heads;
{
const db::gopts opts{db::get::NO_CACHE};
//opts.readahead = 4_MiB;
db::column &column{m::dbs::room_events};
for(auto it(column.begin(opts)); it; ++it)
{
const auto &root(it->second);
id_buffer buf;
copy(buf, root);
heads.emplace(buf);
}
}
std::set<id_buffer> active;
for(auto it(begin(heads)); it != end(heads); it = heads.erase(it))
{
const auto &root(*it);
std::cout << "root: " << string_view{root} << std::endl;
state::for_each(root, state::iter_bool_closure{[&active]
(const json::array &key, const string_view &val)
{
std::cout << "key: " << key << std::endl;
std::cout << "val: " << val << std::endl;
return true;
}});
break;
}
/*
static const db::gopts opts
{
db::get::NO_CACHE
};
auto &column{m::dbs::state_node};
for(auto it(column.begin(opts)); it; ++it)
{
id_buffer buf;
const auto &root(it->second);
copy(buf, root);
active.emplace(buf);
}
*/
size_t ret(active.size());
return ret;
}