Fixing the SQLite error on archive_theos that was crashing the server on a duplicate key assertion

This commit is contained in:
taha afzal committed 2022-06-06 15:14:57 -04:00
1 parent bf4c8e252f
commit 7097c85555
2 files changed
+32 -7

No files matched your search

@@ -71,6 +71,18 @@ std::tuple<int, std::string> parse_vs_id_name(
return {std::stoi(parts[1]), parts[2]};
}
void fire_cb(
const api::Response<::bts::api::ResultMessage> &resp,
bool is_success,
std::string const *msg = nullptr) {
api::ResultMessage res;
res.set_success(is_success);
if (msg != nullptr) {
res.set_error_message(*msg);
}
resp(res);
}
struct AnalyticsServiceServer::PImpl {
bts::api::ServiceContext &context;
const std::string vs_ns_sep = ".";
@@ -264,6 +276,14 @@ void AnalyticsServiceServer::clean_up(
void AnalyticsServiceServer::set_exp_parameters(
const bts::api::analytics::ExpirationParameterEntryList &exp_params_args,
const api::Response<::bts::api::ResultMessage> &response) {
LOG(Gen, Info, "AnalyticsServiceServer::set_exp_parameters params: {}",
exp_params_args.param_list().size());
if (exp_params_args.param_list().empty()) {
std::string err_msg = "Empty params list, call failed";
LOG(Gen, Error, "AnalyticsServiceServer::set_exp_parameters {}", err_msg);
fire_cb(response, false, &err_msg);
return;
}
ExpirationParameterEntryList exp_params = exp_params_args;
exp_params.set_id(1);
std::string ns = me->exp_params_ns;
@@ -272,9 +292,7 @@ void AnalyticsServiceServer::set_exp_parameters(
add_or_update_to_table(me->exp_params_store.get(), ns, key, value);
me->exp_params_publisher.add_or_update(exp_params);
me->exp_params_publisher.flush();
api::ResultMessage res;
res.set_success(true);
response(res);
fire_cb(response, true);
}
void AnalyticsServiceServer::set_volsurface_usage_list(
@@ -351,13 +369,20 @@ void AnalyticsServiceServer::delete_report(
void AnalyticsServiceServer::archive_theos(
const bts::api::analytics::ArchivedTheoList &theo_list,
const api::Response<::bts::api::ResultMessage> &resp) {
LOG(Gen, Info,
"AnalyticsServiceServer::archive_theos sec_tups: {} sec_theo: {}",
theo_list.sec_tups().size(), theo_list.sec_theo().size());
if (theo_list.sec_theo().empty()) {
std::string err_msg = "Empty archived theo list, call failed";
LOG(Gen, Error, "AnalyticsServiceServer::archive_theos {}", err_msg);
fire_cb(resp, false, &err_msg);
return;
}
const std::string &ns = me->archived_theos_ns;
const std::string key = std::to_string(theo_list.save_time());
std::string value = utils::pb::to_string(theo_list);
me->theos_store->insert(ns, key, value);
api::ResultMessage res;
res.set_success(true);
resp(res);
fire_cb(resp, true);
}
void AnalyticsServiceServer::get_archived_theos(