Commit 135b6085 authored by Giacomo Strangolino's avatar Giacomo Strangolino
Browse files

1.4 simplification: onUpdate const reference instead of pointer

parent d1a634db
......@@ -161,7 +161,7 @@ void CaSupDbActivity::onTimeout(CuTimer *) {
f.remove_from_recovery(d->dbh, id);
}
else { // dormant
const std::vector<CuData> *srcs = nullptr;
std::vector<CuData> srcs;
stat = m_get_status(s, &f);
d->log->write("ca-supervisor", stat, CuLog::LevelError);
cuprintf("%s", stat.c_str());
......@@ -169,21 +169,21 @@ void CaSupDbActivity::onTimeout(CuTimer *) {
if(s.has("state", "RECOVER")) { // need RECOVER: CaSupDbFuncs::get_active_services (2.)
srcs = f.get_srcs_for_srv_id(d->dbh, id);
/// print debug section
if(srcs->size() > 0) {
if(srcs.size() > 0) {
d->log->write("ca-supervisor", "dormant service: {" + s.toString() + "} expected: " + s["expected"].toString(), CuLog::LevelError);
}
for(const CuData& src : *srcs)
for(const CuData& src : srcs)
d->log->write("ca-supervisor", "in charge of " + src["source"].toString() + " chan " + src["chan"].toString(), CuLog::LevelInfo);
d->log->write("ca-supervisor", "dormant service: {" + s.toString() + "} was in charge of " + std::to_string(srcs->size()) + " sources");
d->log->write("ca-supervisor", "dormant service: {" + s.toString() + "} was in charge of " + std::to_string(srcs.size()) + " sources");
if(srcs->size() == 0) {
if(srcs.size() == 0) {
d->log->write("ca-supervisor", "sources of dormant service " + s["addr"].toString() + ":" + s["port"].toString() +
" have been taken charge of by one (or more) service instances", CuLog::LevelInfo);
}
else {
printf("[0x%lx] \e[1;32m recovering %ld activities for service id %d\e[0m\n", pthread_self(), srcs->size(), id);
printf("[0x%lx] \e[1;32m recovering %ld activities for service id %d\e[0m\n", pthread_self(), srcs.size(), id);
bool ok = f.insert_recovery_data(d->dbh, id, d->superv_id);
if(ok)
ok = f.insert_recover_operation_start(d->dbh, d->superv_id, id, srcs);
......
......@@ -63,16 +63,16 @@ std::vector<CuData> CaSupDbFuncs::get_active_services(CaDbH *dbh) {
// return sources (=activities) for the given service id
// sources client id must be valid (i.e. in the register table)
std::vector<CuData>* CaSupDbFuncs::get_srcs_for_srv_id(CaDbH *h, int id) {
std::vector<CuData> CaSupDbFuncs::get_srcs_for_srv_id(CaDbH *h, int id) {
const std::string &stm = "SELECT activity.source,activity.chan,service.conf_id,activity.cli_id "
"FROM activity,service,register "
"WHERE service.id=activity.srv_id AND service.id=$1 "
"AND activity.cli_id=register.client_id";
CaDbRes res = h->execute(stm, std::vector<std::string> { std::to_string(id) });
std::vector<CuData> *v = new std::vector<CuData>();
*v = m_res_to_data(res);
std::vector<CuData> v;
v = m_res_to_data(res);
printf( "CaSupDbFuncs::get_srcs_for_srv_id query with id %d returned %ld datas res size %ld\n",
id, v->size(), res.size());
id, v.size(), res.size());
last_db_error = res.errmsg;
return v;
}
......@@ -298,7 +298,7 @@ bool CaSupDbFuncs::insert_recovery_data(CaDbH *h, int srv_id,int superv_id) {
bool CaSupDbFuncs::insert_recover_operation_start(CaDbH *h,
int superv_id,
int from_srv_id,
const std::vector<CuData> *srcs) {
const std::vector<CuData> &srcs) {
std::string conf_id;
std::string stm = "SELECT srvconf.conf_id FROM srvconf,service where service.id=$1 AND srvconf.conf_id=service.conf_id";
CaDbRes r = h->execute(stm, std::vector<std::string> { std::to_string(from_srv_id) });
......@@ -311,7 +311,7 @@ bool CaSupDbFuncs::insert_recover_operation_start(CaDbH *h,
if(!r.error() && r.size() > 0)
recover_op_id = r.value(0, "id");
if(recover_op_id.length() > 0) {
for (const CuData& s : *srcs) {
for (const CuData& s : srcs) {
printf("\e[1;33minsert_recover_operation_start: data ras %s\e[0m\n", datos(s));
stm = "INSERT INTO recover_activities (operation_id,source,chan,cli_id,from_srv_conf) VALUES ($1,$2,$3,$4,$5)";
r = h->execute(stm, std::vector<std::string> { recover_op_id, s.s("source"), s.s("chan"),s.s("cli_id"), conf_id });
......
......@@ -13,7 +13,7 @@ class CaSupDbFuncs
public:
CaSupDbFuncs();
std::vector<CuData> get_active_services(CaDbH *dbh);
std::vector<CuData> *get_srcs_for_srv_id(CaDbH *h, int id);
std::vector<CuData> get_srcs_for_srv_id(CaDbH *h, int id);
bool remove_activities_for_srv_id(CaDbH *h, int id);
bool restore_activities_after_recover_failure(CaDbH *h, const std::list<CuData> &srcs);
......@@ -27,7 +27,7 @@ public:
bool set_last_recover_successful(CaDbH *h, bool success);
int register_instance(CaDbH *h, const std::string &url);
bool unregister_instance(CaDbH *h, int id);
bool insert_recover_operation_start(CaDbH *h, int superv_id, int from_srv_id, const std::vector<CuData> *srcs);
bool insert_recover_operation_start(CaDbH *h, int superv_id, int from_srv_id, const std::vector<CuData> &srcs);
bool unregister_activities(CaDbH *dbhan,
const std::string &cli_id,
const std::string &chan,
......
......@@ -118,8 +118,8 @@ int main(int argc, char *argv[]) {
CaReceiver_A *server_a = nullptr;
printf("\e[1;32m # \e[0mmain.cpp: starting receiver on %s\n", datos(opts));
server_a = new CaReceiver_A(opts);
cumbia->registerActivity(server_a, supervisor, CuData("type", "ca-supervisor-receiver"), *thf_impl, *thread_eb_f);
cumbia->registerActivity(sup, supervisor, montok, *thf_impl, *thread_eb_f);
cumbia->registerActivity(server_a, supervisor, "ca-supervisor-receiver", *thf_impl, *thread_eb_f);
cumbia->registerActivity(sup, supervisor, "ca-sup-dba", *thf_impl, *thread_eb_f);
printf("\e[1;32m # \e[0mmain.cpp: \e[1;32mcasupervisor version \e[2;32m%s\e[0m started\n", CASUPERVISOR_VERSION);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment