postgres-operator/pkg/cluster
Thomas Rosenstein 0affa9425a Improve sync responsiveness with background execution and context cancellation
This change improves the responsiveness of the operator when handling
deletion requests by running sync operations in the background and
using context cancellation to interrupt stuck operations.

Changes:
- Add context field to Cluster struct, passed through New()
- Add Cancel() method to cancel cluster's context
- Add StartSync/EndSync/NeedsResync for managing background sync state
- Run Sync() in a background goroutine so worker can process other events
- Add context-aware DB connection methods (initDbConnWithContext)
- Add RetryWithContext() that respects context cancellation
- Cancel cluster context immediately when DeletionTimestamp detected
- Use context-aware connections in syncRoles/syncDatabases
- StartSync/NeedsResync check context cancellation to prevent new syncs
  during deletion (no need for separate deleted flag)

Flow:
1. Sync event spawns background goroutine and returns immediately
2. If another sync arrives while one is running, needsResync flag is set
3. When sync completes, it checks needsResync and requeues if needed
4. Delete cancels context -> stuck DB operations return early -> mutex released
5. StartSync/NeedsResync return false when context cancelled
6. Delete proceeds without waiting for slow/stuck sync operations
2025-12-14 20:43:53 +00:00
..
cluster.go Improve sync responsiveness with background execution and context cancellation 2025-12-14 20:43:53 +00:00
cluster_test.go Improve sync responsiveness with background execution and context cancellation 2025-12-14 20:43:53 +00:00
connection_pooler.go Ensure podAnnotations are removed from pods if reset in the config (#2826) 2025-01-24 16:53:14 +01:00
connection_pooler_new_test.go Connection pooler for replica (#1127) 2020-11-13 14:52:21 +01:00
connection_pooler_test.go Improve sync responsiveness with background execution and context cancellation 2025-12-14 20:43:53 +00:00
database.go Improve sync responsiveness with background execution and context cancellation 2025-12-14 20:43:53 +00:00
exec.go fix golangci-lint issues (#2715) 2024-08-14 12:54:44 +02:00
filesystems.go reflect change in github url (#496) 2019-02-25 11:26:55 +01:00
k8sres.go Fix Sidecar without image specification issue (#2977) 2025-12-09 09:37:11 +01:00
k8sres_test.go Improve sync responsiveness with background execution and context cancellation 2025-12-14 20:43:53 +00:00
majorversionupgrade.go bump to v1.15.0 (#2965) 2025-10-21 11:56:33 +02:00
pod.go bump dependencies and reflect linter suggestions (#2963) 2025-10-16 10:23:36 +02:00
pod_test.go Improve sync responsiveness with background execution and context cancellation 2025-12-14 20:43:53 +00:00
resources.go bump dependencies and reflect linter suggestions (#2963) 2025-10-16 10:23:36 +02:00
streams.go do not remove publications of slot defined in manifest (#2868) 2025-02-26 17:31:37 +01:00
streams_test.go Improve sync responsiveness with background execution and context cancellation 2025-12-14 20:43:53 +00:00
sync.go Improve sync responsiveness with background execution and context cancellation 2025-12-14 20:43:53 +00:00
sync_test.go Improve sync responsiveness with background execution and context cancellation 2025-12-14 20:43:53 +00:00
types.go Critical operation PDB (#2830) 2025-01-29 12:41:08 +01:00
util.go upgrade Go from 1.23.4 to 1.25.0 (#2945) 2025-08-19 14:40:39 +02:00
util_test.go Improve sync responsiveness with background execution and context cancellation 2025-12-14 20:43:53 +00:00
volumes.go upgrade Go from 1.23.4 to 1.25.0 (#2945) 2025-08-19 14:40:39 +02:00
volumes_test.go Improve sync responsiveness with background execution and context cancellation 2025-12-14 20:43:53 +00:00