From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [IPv6:2a0f:8001:1:32::40]) by lore.proxmox.com (Postfix) with ESMTPS id B9E6B1FF0C2 for ; Thu, 03 Dec 2026 16:05:15 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id A45B121797; Thu, 03 Dec 2026 16:05:10 +0100 (CET) From: Christian Ebner To: pbs-devel@lists.proxmox.com Subject: [PATCH v2 proxmox-backup 0/9] pull: avoid lock contention with verify on unchanged snapshots Date: Thu, 3 Dec 2026 16:04:39 +0100 Message-ID: <20261203150448.412515-1-c.ebner@proxmox.com> X-Mailer: git-send-email 2.47.3 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1796310300251 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.333 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: TSHQC3ZYBHB7D6I4ZYWIYXEA37DTJILL X-Message-ID-Hash: TSHQC3ZYBHB7D6I4ZYWIYXEA37DTJILL X-MailFrom: c.ebner@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox Backup Server development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Pull jobs re-sync the newest already synced snapshot of each group to fetch a client log that may not have been available during the last run. This currently takes an exclusive snapshot lock up front, although the snapshot is unchanged in the vast majority of cases. Since commit 7241811f7 ("fix #6990: server: drop verify state on non-decrypt pull job") synced snapshots no longer inherit the verify state from the source, so a verify job on the target checks every newly synced snapshot while holding a shared lock. A concurrent pull then fails to acquire the exclusive lock and aborts the whole group, delaying newer snapshots until the next run. This series first checks existing, non-corrupt snapshots under a shared lock without touching the target snapshot directory. Only if target changes are required, the shared lock is released and an exclusive lock is acquired, after which the snapshot state is re-evaluated. Unchanged snapshots without a client log on the source skip the exclusive lock entirely. Patches 1-5 are preparatory refactorings of the snapshot pull code without functional changes (apart from one dropped log line on patch 5). Patches 6-7 add timeout-aware exclusive snapshot locking, which validates the lock against a concurrent removal and recreation of the snapshot. Patches 8-9 implement the actual change. Based on a report in the community forum: https://forum.proxmox.com/threads/187896/ Changes since v1 (thanks @Jakob for review and testing): - drop the in-place shared to exclusive lock upgrade since internal tooling flagged a race on lock upgrade, since flock() upgrades are not atomic and bypass the lock inode validation. Instead, release the shared lock and acquire a validated exclusive lock with timeout, re-evaluating the snapshot state afterwards. - add BackupDir::lock_with_timeout() and create_locked_backup_dir_with_timeout() for the above, including tests for contended, timed out and stale inode cases. - use a named constant for the 15s lock timeout. - split out refactorings: start logging (now first), deferred sync stats, target manifest loading helper and decoupling the decryption key decision from logging, so the shared lock check can reuse it. - split the client log check into its own patch. Christian Ebner (9): server: pull: refactor snapshot sync start logging server: pull: defer sync stats instantiation until needed server: pull: load source manifest into memory instead of a temp file server: pull: move target manifest loading logic into reusable helper server: pull: decouple decryption key gathering from logging pbs-datastore: add BackupDir::lock_with_timeout() pbs-datastore: add create_locked_backup_dir_with_timeout() server: pull: check for unchanged snapshots under a shared lock server: pull: skip exclusive lock when source has no client log pbs-datastore/src/backup_info.rs | 173 +++++++- pbs-datastore/src/datastore.rs | 37 +- src/server/pull.rs | 673 +++++++++++++++++++------------ src/server/sync.rs | 89 ++-- 4 files changed, 676 insertions(+), 296 deletions(-) -- 2.47.3