From 2a2a8bcf86302ead0c06d7ea67467aa10c31d29f Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Mon, 3 Dec 2018 17:34:43 -0800 Subject: [PATCH] modules/m_state: Checkpoint preliminary GC util. --- modules/console.cc | 18 +++++++++++++++ modules/m_state.cc | 57 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+) diff --git a/modules/console.cc b/modules/console.cc index d76f5bcad..c1844cb7b 100644 --- a/modules/console.cc +++ b/modules/console.cc @@ -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 gc + { + "m_state", "ircd__m__state__gc" + }; + + const size_t count + { + gc() + }; + + out << "done: " << count << std::endl; + return true; +} + // // commit // diff --git a/modules/m_state.cc b/modules/m_state.cc index b0b6112c4..b62c476cf 100644 --- a/modules/m_state.cc +++ b/modules/m_state.cc @@ -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 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 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; +}