121 lines
3.7 KiB
Diff
121 lines
3.7 KiB
Diff
From 754126dc701fe1d945b60c634b0c84d3c976b23b Mon Sep 17 00:00:00 2001
|
|
From: huyubiao <h13958451065@163.com>
|
|
Date: Wed, 7 Jun 2023 16:33:26 +0800
|
|
Subject: [PATCH] fix: Clear buffer correctly during reload or reexec
|
|
|
|
---
|
|
core/lib/rel/api.rs | 22 +++++++++++-----------
|
|
core/lib/rel/base.rs | 10 +++++++---
|
|
core/lib/rel/history.rs | 1 -
|
|
3 files changed, 18 insertions(+), 15 deletions(-)
|
|
|
|
diff --git a/core/lib/rel/api.rs b/core/lib/rel/api.rs
|
|
index 59e4ac9..ad14796 100644
|
|
--- a/core/lib/rel/api.rs
|
|
+++ b/core/lib/rel/api.rs
|
|
@@ -187,11 +187,7 @@ impl Reliability {
|
|
self.db_compensate();
|
|
self.db_map(reload);
|
|
if reload {
|
|
- // If daemon-reload or daemon-reexec, we need to update all changes, clear db, and submit all changes to db.
|
|
- self.db_insert();
|
|
- self.history.flush();
|
|
- // Due to changes in db, we need to reload the data from db to cache.
|
|
- self.history.import();
|
|
+ self.db_flush();
|
|
}
|
|
self.make_consistent();
|
|
|
|
@@ -309,12 +305,10 @@ impl Reliability {
|
|
}
|
|
|
|
fn input_rebuild(&self) {
|
|
- // ignore history's input
|
|
self.history.switch_set(true);
|
|
|
|
self.station.input_rebuild();
|
|
|
|
- // restore history's ignore
|
|
self.history.switch_set(false);
|
|
}
|
|
|
|
@@ -331,22 +325,28 @@ impl Reliability {
|
|
/// map data from database
|
|
/// reload determine whether the configuration needs to be reloaded based on the situation.
|
|
fn db_map(&self, reload: bool) {
|
|
- // control use buf
|
|
self.history.switch_set(true);
|
|
|
|
self.station.db_map(reload);
|
|
|
|
- // control use cache
|
|
self.history.switch_set(false);
|
|
}
|
|
|
|
- /// map-data insert to buf, switch is true indicating either daemon-reload or daemon-reexec
|
|
- fn db_insert(&self) {
|
|
+ /// flush all data from buffer to db
|
|
+ fn db_flush(&self) {
|
|
+ // clear data before using buffer
|
|
self.history.switch_set(true);
|
|
|
|
+ // update all changes to buffer
|
|
self.station.db_insert();
|
|
|
|
+ // clear db, submit data from all buffers to db, clear buffer
|
|
+ self.history.flush();
|
|
+
|
|
self.history.switch_set(false);
|
|
+
|
|
+ // Due to changes in db, reload the data from db to cache.
|
|
+ self.history.import();
|
|
}
|
|
|
|
fn make_consistent(&self) {
|
|
diff --git a/core/lib/rel/base.rs b/core/lib/rel/base.rs
|
|
index 29200df..7137e13 100644
|
|
--- a/core/lib/rel/base.rs
|
|
+++ b/core/lib/rel/base.rs
|
|
@@ -27,8 +27,7 @@ use std::{env, fs};
|
|
/// the reliability database
|
|
/// K & V that can be deserialized without borrowing any data from the deserializer.
|
|
pub struct ReDb<K, V> {
|
|
- // control
|
|
- switch: RefCell<bool>,
|
|
+ switch: RefCell<bool>, // if switch is true use buffer, if switch is false use cache
|
|
|
|
// data
|
|
/* database */
|
|
@@ -97,10 +96,15 @@ where
|
|
self.cache.borrow_mut().clear();
|
|
self.add.borrow_mut().clear();
|
|
self.del.borrow_mut().clear();
|
|
+ // Do not clear the buffer because its data is transient.
|
|
}
|
|
|
|
- /// set the buffer-switch flag of data
|
|
+ /// switch between cache and buffer
|
|
pub fn switch_buffer(&self, switch: bool) {
|
|
+ if switch {
|
|
+ // Before using the buffer, data needs to be cleared.
|
|
+ self.buffer.borrow_mut().clear();
|
|
+ }
|
|
*self.switch.borrow_mut() = switch;
|
|
}
|
|
|
|
diff --git a/core/lib/rel/history.rs b/core/lib/rel/history.rs
|
|
index f9e2146..199e10e 100644
|
|
--- a/core/lib/rel/history.rs
|
|
+++ b/core/lib/rel/history.rs
|
|
@@ -158,7 +158,6 @@ impl ReliHistory {
|
|
}
|
|
|
|
pub fn switch_set(&self, switch: bool) {
|
|
- // set switch
|
|
*self.switch.borrow_mut() = switch;
|
|
for (_, db) in self.dbs.borrow().iter() {
|
|
db.switch_set(switch);
|
|
--
|
|
2.33.0
|
|
|