sysmaster/backport-fix-only-remove-one-unit-s-pid-from-db-PR-568-remove.patch
licunlong 0c7d548f94 sync patches from upstream
(cherry picked from commit e23ebb83bd7672e4dc8da68a9a8c73fe6e016341)
2023-06-19 10:39:49 +08:00

53 lines
2.0 KiB
Diff

From 8e872af3529d75a05fad98824786415045c8cf10 Mon Sep 17 00:00:00 2001
From: licunlong <licunlong1@huawei.com>
Date: Wed, 31 May 2023 15:57:55 +0800
Subject: [PATCH] fix: only remove one unit's pid from db PR #568 removes all
unit's pids when one unit enters dead state, which is definitely wrong. We
should only remove one unit's pid from db, and other unit's pids should still
be watched.
---
core/bin/unit/datastore/child.rs | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/core/bin/unit/datastore/child.rs b/core/bin/unit/datastore/child.rs
index 60c73c5..f4460f0 100644
--- a/core/bin/unit/datastore/child.rs
+++ b/core/bin/unit/datastore/child.rs
@@ -59,7 +59,7 @@ impl UnitChild {
}
pub(super) fn add_watch_pid(&self, id: &str, pid: Pid) {
- log::debug!("borrow add watch_pids for pid:{}, id:{}", pid, id);
+ log::debug!("Adding watch_pids {} to {}", pid, id);
let unit = self.units.get(id).unwrap();
self.data.add_watch_pid(unit.clone(), pid);
unit.child_add_pids(pid);
@@ -67,17 +67,19 @@ impl UnitChild {
pub(super) fn unwatch_pid(&self, id: &str, pid: Pid) {
let unit = self.units.get(id).unwrap();
- log::debug!("borrow remove watch_pids for {}", pid);
+ log::debug!("Removing watch_pids {} from {}", pid, id);
self.data.unwatch_pid(unit.clone(), pid);
unit.child_remove_pids(pid);
}
pub(super) fn unwatch_all_pids(&self, id: &str) {
+ log::debug!("Unwatching all watch_pids of {}", id);
let unit = self.units.get(id).unwrap();
- for i in self.data.watch_pids.borrow().keys() {
- unit.child_remove_pids(*i);
+ let delete_pids = unit.get_pids();
+ for pid in delete_pids {
+ unit.child_remove_pids(pid);
+ self.data.unwatch_pid(unit.clone(), pid);
}
- self.data.watch_pids.borrow_mut().clear();
}
pub(super) fn get_unit_by_pid(&self, pid: Pid) -> Option<Rc<UnitX>> {
--
2.30.2