Vol surfaces are curtailed to the newest 500 at server startup
This commit is contained in:
1 parent
a5c62c66b1
commit
c688657d53
2 files changed
+47
No files matched your search
@@ -132,6 +132,7 @@ AnalyticsServiceServer::AnalyticsServiceServer(
|
||||
make_reports_stateful_publisher())) {
|
||||
// publishing all vol surfaces
|
||||
LOG(Gen, Info, "Starting AnalyticsServiceServer");
|
||||
_clean_up_vss();
|
||||
auto vs_table = me->vs_store->retrieve_all();
|
||||
for (auto const &ns_vals : vs_table) {
|
||||
const std::string &vs_name = ns_vals.first;
|
||||
@@ -428,4 +429,47 @@ void AnalyticsServiceServer::get_archived_theos(
|
||||
|
||||
AnalyticsServiceServer::~AnalyticsServiceServer() {}
|
||||
|
||||
void AnalyticsServiceServer::_clean_up_vss() {
|
||||
const size_t final_sz = 500;
|
||||
auto all_rows = me->vs_store->retrieve_all();
|
||||
for (const auto &ns_k : all_rows) {
|
||||
const auto &vs = ns_k.first;
|
||||
const auto &vs_row_map = ns_k.second;
|
||||
if (vs_row_map.size() <= final_sz) {
|
||||
LOG(Gen, Info,
|
||||
"AnalyticsServiceServer::_clean_up_vss ignoring vs: {} because it "
|
||||
"has only {} rows",
|
||||
vs, vs_row_map.size());
|
||||
continue;
|
||||
}
|
||||
std::vector<uint64_t> keys_uint;
|
||||
for (const auto &r : vs_row_map) {
|
||||
const auto &k = r.first;
|
||||
try {
|
||||
keys_uint.push_back(std::stoull(k));
|
||||
} catch (int) {
|
||||
LOG(Gen, Error,
|
||||
"AnalyticsServiceServer::_clean_up_vss could not convert "
|
||||
"key: "
|
||||
"{} to uint",
|
||||
k);
|
||||
}
|
||||
}
|
||||
// sort and remove
|
||||
std::sort(keys_uint.begin(), keys_uint.end());
|
||||
size_t n_del_rows = keys_uint.size() - final_sz;
|
||||
std::vector<uint64_t> keys_uint_to_del = std::vector<uint64_t>(
|
||||
keys_uint.begin(), keys_uint.begin() + n_del_rows);
|
||||
std::set<std::string> keys_to_del;
|
||||
for (auto k : keys_uint_to_del) {
|
||||
keys_to_del.insert(std::to_string(k));
|
||||
}
|
||||
LOG(Gen, Info,
|
||||
"AnalyticsServiceServer::_clean_up_vss vs: {} n_rows: {} removing {} "
|
||||
"rows",
|
||||
vs, keys_uint.size(), keys_to_del.size());
|
||||
me->vs_store->remove(vs, keys_to_del);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace bts::analytics
|
||||
Reference in new issue
Block a user