Fix: protect update_history_times snapshot restore from DB failures
Three fixes in update_history_times(): 1. Wrap DB operations in try-catch — exception no longer skips the snapshot restore, preventing permanent loss of accumulated counts 2. Treat get_history_times() -1 return (DB failure) as skip, not as "record exists" → no more silent UPDATE on non-existent rows 3. Only call update_static and advance last_load_time_ on success, so a failed persist retries on the next cycle instead of waiting another rw_time_ minutes
This commit is contained in:
parent
b3932b0af8
commit
6ed178b367
@ -102,14 +102,14 @@ AlarmInfo ExpTimes::mon_proc() {
|
|||||||
<< ",last_load_time_:"
|
<< ",last_load_time_:"
|
||||||
<< mix_cc::mix_time_t(last_load_time_).to_formatted_time()
|
<< mix_cc::mix_time_t(last_load_time_).to_formatted_time()
|
||||||
<< ",rw_time:" << rw_time_ << "min" << endl;
|
<< ",rw_time:" << rw_time_ << "min" << endl;
|
||||||
update_history_times();
|
if (update_history_times() == 0) {
|
||||||
logger_->Debug() << "exp_type:" << exp_type_
|
logger_->Debug() << "exp_type:" << exp_type_
|
||||||
<< ",update_history_times(),shear_times:"
|
<< ",update_history_times(),shear_times:"
|
||||||
<< rule_stat_.shear_times
|
<< rule_stat_.shear_times
|
||||||
<< ",running_time:" << rule_stat_.running_time
|
<< ",running_time:" << rule_stat_.running_time
|
||||||
<< ",rw_time:" << rw_time_ << "min" << endl;
|
<< ",rw_time:" << rw_time_ << "min" << endl;
|
||||||
/*更新时间标记*/
|
last_load_time_ = this->now_time_;
|
||||||
last_load_time_ = this->now_time_;
|
}
|
||||||
}
|
}
|
||||||
if (update_times() == 0) {
|
if (update_times() == 0) {
|
||||||
if (check_alarm()) {
|
if (check_alarm()) {
|
||||||
@ -255,35 +255,48 @@ int ExpTimes::update_history_times() {
|
|||||||
<< std::to_string(this->act_started_)
|
<< std::to_string(this->act_started_)
|
||||||
<< ",now_times:" << now_times
|
<< ",now_times:" << now_times
|
||||||
<< ",now_used_time:" << now_used_time << std::endl;
|
<< ",now_used_time:" << now_used_time << std::endl;
|
||||||
if (get_history_times() == -2) {
|
int ret = -1;
|
||||||
// insert into
|
try {
|
||||||
logger_->Debug() << "首次存入!" << endl;
|
int hist_ret = get_history_times();
|
||||||
this->insert_history_times(now_times, now_used_time);
|
if (hist_ret == -1) {
|
||||||
} else {
|
logger_->Error() << "get_history_times() db2 查询失败,跳过本次持久化"
|
||||||
T_RULE_SAMPLE_1D trs1a;
|
<< std::endl;
|
||||||
if (exp_type_ == ExpType::OccTimesAcc) {
|
} else if (hist_ret == -2) {
|
||||||
this->rule_stat_.current_value = now_times;
|
logger_->Debug() << "首次存入!" << endl;
|
||||||
exec<db2_t, size_t>(update(trs1a)
|
this->insert_history_times(now_times, now_used_time);
|
||||||
.set(trs1a.Count() = now_times, trs1a.X1() = 2,
|
ret = 0;
|
||||||
trs1a.Flag() = this->exp_type_)
|
} else {
|
||||||
.where(trs1a.RuleId() == this->rule_id_));
|
T_RULE_SAMPLE_1D trs1a;
|
||||||
logger_->Debug() << "update_history_times(),update,now_times:"
|
if (exp_type_ == ExpType::OccTimesAcc) {
|
||||||
<< now_times << endl;
|
this->rule_stat_.current_value = now_times;
|
||||||
} else if (exp_type_ == ExpType::HoldTimeAcc) {
|
exec<db2_t, size_t>(update(trs1a)
|
||||||
this->rule_stat_.current_value = now_used_time;
|
.set(trs1a.Count() = now_times, trs1a.X1() = 2,
|
||||||
exec<db2_t, size_t>(update(trs1a)
|
trs1a.Flag() = this->exp_type_)
|
||||||
.set(trs1a.X1() = now_used_time,
|
.where(trs1a.RuleId() == this->rule_id_));
|
||||||
trs1a.Count() = 2,
|
logger_->Debug() << "update_history_times(),update,now_times:"
|
||||||
trs1a.Flag() = this->exp_type_)
|
<< now_times << endl;
|
||||||
.where(trs1a.RuleId() == this->rule_id_));
|
} else if (exp_type_ == ExpType::HoldTimeAcc) {
|
||||||
logger_->Debug() << "update_history_times(),update,now_used_time:"
|
this->rule_stat_.current_value = now_used_time;
|
||||||
<< now_used_time << endl;
|
exec<db2_t, size_t>(update(trs1a)
|
||||||
|
.set(trs1a.X1() = now_used_time,
|
||||||
|
trs1a.Count() = 2,
|
||||||
|
trs1a.Flag() = this->exp_type_)
|
||||||
|
.where(trs1a.RuleId() == this->rule_id_));
|
||||||
|
logger_->Debug() << "update_history_times(),update,now_used_time:"
|
||||||
|
<< now_used_time << endl;
|
||||||
|
}
|
||||||
|
ret = 0;
|
||||||
}
|
}
|
||||||
|
if (ret == 0) {
|
||||||
|
SingletonTemp<EqpStat>::GetInstance().update_static(this->rule_id_, true);
|
||||||
|
}
|
||||||
|
} catch (const std::exception &e) {
|
||||||
|
logger_->Error() << "update_history_times() db2 操作异常: " << e.what()
|
||||||
|
<< std::endl;
|
||||||
}
|
}
|
||||||
this->rule_stat_.shear_times = now_times;
|
this->rule_stat_.shear_times = now_times;
|
||||||
this->rule_stat_.running_time = now_used_time;
|
this->rule_stat_.running_time = now_used_time;
|
||||||
SingletonTemp<EqpStat>::GetInstance().update_static(this->rule_id_, true);
|
return ret;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int ExpTimes::insert_history_times(int64_t now_times, double now_used_time) {
|
int ExpTimes::insert_history_times(int64_t now_times, double now_used_time) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user