all lists on lists.proxmox.com
 help / color / mirror / Atom feed
* [PATCH proxmox-backup] api: gc: fix mismatched UPID and jobstate in GC status
@ 2026-11-13  8:16 Christian Ebner
  2026-11-14 21:27 ` applied: " Thomas Lamprecht
  0 siblings, 1 reply; 2+ messages in thread
From: Christian Ebner @ 2026-11-13  8:16 UTC (permalink / raw)
  To: pbs-devel

garbage_collection_status_unchecked() gathers information from two
locations, the .gc-status as well as the job state file.
The former is written only on successful garbage collection runs,
the latter on every run, including failed ones.

Collecting the status incorrectly mixed the information from both,
leading to comparison of timestamps from two different runs, which
caused incorrect or negative durations. Further, missing a
.gc-status UPID dropped last-run endtimes and states completely.

To fix this, prefer computed_schedule.last_run_upid together with its
matching endtime and state, and guard duration calculation against
negative values. If jobstate has no last_run_upid, fall back to
reading the task status for a non-active .gc-status UPID.

Reported-by: https://forum.proxmox.com/threads/187530/
Signed-off-by: Christian Ebner <c.ebner@proxmox.com>
---
 src/api2/admin/datastore.rs | 32 +++++++++++++++++++++++++-------
 1 file changed, 25 insertions(+), 7 deletions(-)

diff --git a/src/api2/admin/datastore.rs b/src/api2/admin/datastore.rs
index 3ba25934f..382c3c965 100644
--- a/src/api2/admin/datastore.rs
+++ b/src/api2/admin/datastore.rs
@@ -64,7 +64,9 @@ use pbs_datastore::{
     ensure_datastore_is_mounted, task_tracking,
 };
 use pbs_tools::json::required_string_param;
-use proxmox_rest_server::{WorkerTask, formatter, worker_is_active};
+use proxmox_rest_server::{
+    WorkerTask, formatter, upid_read_status, worker_is_active, worker_is_active_local,
+};
 
 use crate::api2::backup::optional_ns_param;
 use crate::api2::node::rrd::create_value_from_rrd;
@@ -1267,20 +1269,36 @@ pub(crate) fn garbage_collection_status_unchecked(
     };
 
     let datastore = DataStore::lookup_datastore(lookup_with(&store, Operation::Read))?;
-    let status_in_memory = datastore.last_gc_status();
+    let mut status_in_memory = datastore.last_gc_status();
 
     let computed_schedule: JobScheduleStatus =
         compute_schedule_status("garbage_collection", &store, info.schedule.as_deref())?;
 
-    if let Some(ref upid) = status_in_memory.upid {
-        if let Some(endtime) = computed_schedule.last_run_endtime {
-            if let Ok(parsed_upid) = upid.parse::<UPID>() {
-                info.duration = Some(endtime - parsed_upid.starttime);
-            }
+    let calc_duration = |starttime: i64, endtime: i64| -> Option<i64> {
+        endtime.checked_sub(starttime).filter(|&d| d >= 0)
+    };
+
+    if let Some(upid) = &computed_schedule.last_run_upid {
+        if let (Some(endtime), Ok(parsed_upid)) =
+            (computed_schedule.last_run_endtime, upid.parse::<UPID>())
+        {
+            info.duration = calc_duration(parsed_upid.starttime, endtime);
         }
 
         info.last_run_endtime = computed_schedule.last_run_endtime;
         info.last_run_state = computed_schedule.last_run_state;
+        status_in_memory.upid = Some(upid.clone());
+    } else if let Some(upid) = &status_in_memory.upid {
+        if let Ok(parsed_upid) = upid.parse::<UPID>() {
+            if !worker_is_active_local(&parsed_upid) {
+                if let Ok(task_state) = upid_read_status(&parsed_upid) {
+                    let endtime = task_state.endtime();
+                    info.duration = calc_duration(parsed_upid.starttime, endtime);
+                    info.last_run_endtime = Some(endtime);
+                    info.last_run_state = Some(task_state.to_string());
+                }
+            }
+        }
     }
 
     info.next_run = computed_schedule.next_run;
-- 
2.47.3





^ permalink raw reply related	[flat|nested] 2+ messages in thread

* applied: [PATCH proxmox-backup] api: gc: fix mismatched UPID and jobstate in GC status
  2026-11-13  8:16 [PATCH proxmox-backup] api: gc: fix mismatched UPID and jobstate in GC status Christian Ebner
@ 2026-11-14 21:27 ` Thomas Lamprecht
  0 siblings, 0 replies; 2+ messages in thread
From: Thomas Lamprecht @ 2026-11-14 21:27 UTC (permalink / raw)
  To: pbs-devel, Christian Ebner

On Fri, 13 Nov 2026 09:16:27 +0100, Christian Ebner wrote:
> garbage_collection_status_unchecked() gathers information from two
> locations, the .gc-status as well as the job state file.
> The former is written only on successful garbage collection runs,
> the latter on every run, including failed ones.
> 
> Collecting the status incorrectly mixed the information from both,
> leading to comparison of timestamps from two different runs, which
> caused incorrect or negative durations. Further, missing a
> .gc-status UPID dropped last-run endtimes and states completely.
> 
> [...]

Applied, thanks!

[1/1] api: gc: fix mismatched UPID and jobstate in GC status
      commit: b743599749d76f34b92c6a21d1bb62477a8c0fda




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-14 21:28 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-13  8:16 [PATCH proxmox-backup] api: gc: fix mismatched UPID and jobstate in GC status Christian Ebner
2026-11-14 21:27 ` applied: " Thomas Lamprecht

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal