mirror of
https://github.com/cloudnative-pg/plugin-barman-cloud.git
synced 2026-01-12 05:33:11 +01:00
Track WAL submission times in ObjectStore status
This commit is contained in:
parent
a225902a36
commit
cb1d3e88c8
@ -75,6 +75,12 @@ type RecoveryWindow struct {
|
|||||||
|
|
||||||
// The last successful backup time
|
// The last successful backup time
|
||||||
LastSuccessfulBackupTime *metav1.Time `json:"lastSuccussfulBackupTime,omitempty"`
|
LastSuccessfulBackupTime *metav1.Time `json:"lastSuccussfulBackupTime,omitempty"`
|
||||||
|
|
||||||
|
// The timestamp of the first WAL file successfully submitted to the object store
|
||||||
|
FirstWALSubmissionTime *metav1.Time `json:"firstWALSubmissionTime,omitempty"`
|
||||||
|
|
||||||
|
// The timestamp of the last WAL file successfully submitted to the object store
|
||||||
|
LastWALSubmissionTime *metav1.Time `json:"lastWALSubmissionTime,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// +kubebuilder:object:root=true
|
// +kubebuilder:object:root=true
|
||||||
|
|||||||
@ -157,6 +157,14 @@ func (in *RecoveryWindow) DeepCopyInto(out *RecoveryWindow) {
|
|||||||
in, out := &in.LastSuccessfulBackupTime, &out.LastSuccessfulBackupTime
|
in, out := &in.LastSuccessfulBackupTime, &out.LastSuccessfulBackupTime
|
||||||
*out = (*in).DeepCopy()
|
*out = (*in).DeepCopy()
|
||||||
}
|
}
|
||||||
|
if in.FirstWALSubmissionTime != nil {
|
||||||
|
in, out := &in.FirstWALSubmissionTime, &out.FirstWALSubmissionTime
|
||||||
|
*out = (*in).DeepCopy()
|
||||||
|
}
|
||||||
|
if in.LastWALSubmissionTime != nil {
|
||||||
|
in, out := &in.LastWALSubmissionTime, &out.LastWALSubmissionTime
|
||||||
|
*out = (*in).DeepCopy()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RecoveryWindow.
|
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RecoveryWindow.
|
||||||
|
|||||||
@ -609,10 +609,20 @@ spec:
|
|||||||
restored.
|
restored.
|
||||||
format: date-time
|
format: date-time
|
||||||
type: string
|
type: string
|
||||||
|
firstWALSubmissionTime:
|
||||||
|
description: The timestamp of the first WAL file successfully
|
||||||
|
submitted to the object store
|
||||||
|
format: date-time
|
||||||
|
type: string
|
||||||
lastSuccussfulBackupTime:
|
lastSuccussfulBackupTime:
|
||||||
description: The last successful backup time
|
description: The last successful backup time
|
||||||
format: date-time
|
format: date-time
|
||||||
type: string
|
type: string
|
||||||
|
lastWALSubmissionTime:
|
||||||
|
description: The timestamp of the last WAL file successfully
|
||||||
|
submitted to the object store
|
||||||
|
format: date-time
|
||||||
|
type: string
|
||||||
type: object
|
type: object
|
||||||
description: ServerRecoveryWindow maps each server to its recovery
|
description: ServerRecoveryWindow maps each server to its recovery
|
||||||
window
|
window
|
||||||
|
|||||||
@ -17,6 +17,7 @@ import (
|
|||||||
walUtils "github.com/cloudnative-pg/machinery/pkg/fileutils/wals"
|
walUtils "github.com/cloudnative-pg/machinery/pkg/fileutils/wals"
|
||||||
"github.com/cloudnative-pg/machinery/pkg/log"
|
"github.com/cloudnative-pg/machinery/pkg/log"
|
||||||
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
||||||
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apimachinery/pkg/types"
|
"k8s.io/apimachinery/pkg/types"
|
||||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||||
|
|
||||||
@ -184,6 +185,12 @@ func (w WALServiceImplementation) Archive(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update WAL submission timing in ObjectStore status after successful archiving
|
||||||
|
if err := w.updateWALSubmissionTime(ctx, &objectStore, configuration.ServerName); err != nil {
|
||||||
|
contextLogger.Error(err, "failed to update WAL submission time in ObjectStore status")
|
||||||
|
// Don't fail the archiving operation for status update errors
|
||||||
|
}
|
||||||
|
|
||||||
return &wal.WALArchiveResult{}, nil
|
return &wal.WALArchiveResult{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -469,3 +476,30 @@ func isEndOfWALStream(results []barmanRestorer.Result) bool {
|
|||||||
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// updateWALSubmissionTime updates the WAL submission timing in the ObjectStore status
|
||||||
|
func (w WALServiceImplementation) updateWALSubmissionTime(
|
||||||
|
ctx context.Context,
|
||||||
|
objectStore *barmancloudv1.ObjectStore,
|
||||||
|
serverName string,
|
||||||
|
) error {
|
||||||
|
now := metav1.NewTime(time.Now())
|
||||||
|
|
||||||
|
if objectStore.Status.ServerRecoveryWindow == nil {
|
||||||
|
objectStore.Status.ServerRecoveryWindow = make(map[string]barmancloudv1.RecoveryWindow)
|
||||||
|
}
|
||||||
|
|
||||||
|
recoveryWindow := objectStore.Status.ServerRecoveryWindow[serverName]
|
||||||
|
|
||||||
|
// Set first WAL submission time if not already set
|
||||||
|
if recoveryWindow.FirstWALSubmissionTime == nil {
|
||||||
|
recoveryWindow.FirstWALSubmissionTime = &now
|
||||||
|
}
|
||||||
|
|
||||||
|
// Always update last WAL submission time
|
||||||
|
recoveryWindow.LastWALSubmissionTime = &now
|
||||||
|
|
||||||
|
objectStore.Status.ServerRecoveryWindow[serverName] = recoveryWindow
|
||||||
|
|
||||||
|
return w.Client.Status().Update(ctx, objectStore)
|
||||||
|
}
|
||||||
|
|||||||
@ -176,14 +176,21 @@ func (c *CatalogMaintenanceRunnable) updateRecoveryWindow(
|
|||||||
return ptr.To(metav1.NewTime(*t))
|
return ptr.To(metav1.NewTime(*t))
|
||||||
}
|
}
|
||||||
|
|
||||||
recoveryWindow := barmancloudv1.RecoveryWindow{
|
|
||||||
FirstRecoverabilityPoint: convertTime(backupList.GetFirstRecoverabilityPoint()),
|
|
||||||
LastSuccessfulBackupTime: convertTime(backupList.GetLastSuccessfulBackupTime()),
|
|
||||||
}
|
|
||||||
|
|
||||||
if objectStore.Status.ServerRecoveryWindow == nil {
|
if objectStore.Status.ServerRecoveryWindow == nil {
|
||||||
objectStore.Status.ServerRecoveryWindow = make(map[string]barmancloudv1.RecoveryWindow)
|
objectStore.Status.ServerRecoveryWindow = make(map[string]barmancloudv1.RecoveryWindow)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// get existing recovery window to preserve WAL submission timing
|
||||||
|
existingWindow := objectStore.Status.ServerRecoveryWindow[serverName]
|
||||||
|
|
||||||
|
recoveryWindow := barmancloudv1.RecoveryWindow{
|
||||||
|
FirstRecoverabilityPoint: convertTime(backupList.GetFirstRecoverabilityPoint()),
|
||||||
|
LastSuccessfulBackupTime: convertTime(backupList.GetLastSuccessfulBackupTime()),
|
||||||
|
// preserve existing WAL submission timing
|
||||||
|
FirstWALSubmissionTime: existingWindow.FirstWALSubmissionTime,
|
||||||
|
LastWALSubmissionTime: existingWindow.LastWALSubmissionTime,
|
||||||
|
}
|
||||||
|
|
||||||
objectStore.Status.ServerRecoveryWindow[serverName] = recoveryWindow
|
objectStore.Status.ServerRecoveryWindow[serverName] = recoveryWindow
|
||||||
|
|
||||||
return c.Client.Status().Update(ctx, objectStore)
|
return c.Client.Status().Update(ctx, objectStore)
|
||||||
|
|||||||
@ -608,10 +608,20 @@ spec:
|
|||||||
restored.
|
restored.
|
||||||
format: date-time
|
format: date-time
|
||||||
type: string
|
type: string
|
||||||
|
firstWALSubmissionTime:
|
||||||
|
description: The timestamp of the first WAL file successfully
|
||||||
|
submitted to the object store
|
||||||
|
format: date-time
|
||||||
|
type: string
|
||||||
lastSuccussfulBackupTime:
|
lastSuccussfulBackupTime:
|
||||||
description: The last successful backup time
|
description: The last successful backup time
|
||||||
format: date-time
|
format: date-time
|
||||||
type: string
|
type: string
|
||||||
|
lastWALSubmissionTime:
|
||||||
|
description: The timestamp of the last WAL file successfully
|
||||||
|
submitted to the object store
|
||||||
|
format: date-time
|
||||||
|
type: string
|
||||||
type: object
|
type: object
|
||||||
description: ServerRecoveryWindow maps each server to its recovery
|
description: ServerRecoveryWindow maps each server to its recovery
|
||||||
window
|
window
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user