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,15 +102,15 @@ AlarmInfo ExpTimes::mon_proc() {
|
||||
<< ",last_load_time_:"
|
||||
<< mix_cc::mix_time_t(last_load_time_).to_formatted_time()
|
||||
<< ",rw_time:" << rw_time_ << "min" << endl;
|
||||
update_history_times();
|
||||
if (update_history_times() == 0) {
|
||||
logger_->Debug() << "exp_type:" << exp_type_
|
||||
<< ",update_history_times(),shear_times:"
|
||||
<< rule_stat_.shear_times
|
||||
<< ",running_time:" << rule_stat_.running_time
|
||||
<< ",rw_time:" << rw_time_ << "min" << endl;
|
||||
/*更新时间标记*/
|
||||
last_load_time_ = this->now_time_;
|
||||
}
|
||||
}
|
||||
if (update_times() == 0) {
|
||||
if (check_alarm()) {
|
||||
this->rule_stat_.alarm_value = this->rule_stat_.current_value;
|
||||
@ -255,10 +255,16 @@ int ExpTimes::update_history_times() {
|
||||
<< std::to_string(this->act_started_)
|
||||
<< ",now_times:" << now_times
|
||||
<< ",now_used_time:" << now_used_time << std::endl;
|
||||
if (get_history_times() == -2) {
|
||||
// insert into
|
||||
int ret = -1;
|
||||
try {
|
||||
int hist_ret = get_history_times();
|
||||
if (hist_ret == -1) {
|
||||
logger_->Error() << "get_history_times() db2 查询失败,跳过本次持久化"
|
||||
<< std::endl;
|
||||
} else if (hist_ret == -2) {
|
||||
logger_->Debug() << "首次存入!" << endl;
|
||||
this->insert_history_times(now_times, now_used_time);
|
||||
ret = 0;
|
||||
} else {
|
||||
T_RULE_SAMPLE_1D trs1a;
|
||||
if (exp_type_ == ExpType::OccTimesAcc) {
|
||||
@ -279,11 +285,18 @@ int ExpTimes::update_history_times() {
|
||||
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_.running_time = now_used_time;
|
||||
SingletonTemp<EqpStat>::GetInstance().update_static(this->rule_id_, true);
|
||||
return 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ExpTimes::insert_history_times(int64_t now_times, double now_used_time) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user