Skip to content

fix: release nested freezes after backup failure - #140

Open
sanikolaev wants to merge 1 commit into
mainfrom
fix/issue-138-orphaned-lock
Open

fix: release nested freezes after backup failure#140
sanikolaev wants to merge 1 commit into
mainfrom
fix/issue-138-orphaned-lock

Conversation

@sanikolaev

@sanikolaev sanikolaev commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator

This PR prevents a failed backup from leaving an RT table frozen when an error occurs after its per-table FREEZE.

Follow-up to #138.

How to reproduce manually

rm -fr /opt/homebrew/var/manticore/t
mysql -h0 -P9306 -e "drop table if exists t; CREATE TABLE t(f text) exceptions_list='a=>b'; INSERT INTO t(id,f) VALUES (1,'a'); FLUSH RAMCHUNK t"
rm /opt/homebrew/var/manticore/t/exceptions_chunk0_0.txt
manticore-backup --backup-dir=/tmp/

 ✘  ~/manticoresearch-buddy  main  mysql -P9306 -h0 -e "show locks"
+------+------+-----------+-----------------+
| Type | Name | Lock Type | Additional Info |
+------+------+-----------+-----------------+
| rt   | t    | freeze    | Count: 1        |
+------+------+-----------+-----------------+

Root cause

Backup freezes tables twice:

  1. A bulk FREEZE protects all selected tables.
  2. Each table is frozen again while its files are copied.

If a frozen file disappears before it is processed, such as an exceptions file, filesize() throws before the per-table UNFREEZE is reached.

The existing shutdown cleanup releases only one freeze level, leaving the affected table locked with Count: 1.

Fix

Wrap the work following the per-table FREEZE in try/catch/finally:

  • On failure, release the initial bulk freeze and rethrow the original exception.
  • Always release the per-table freeze in finally.

This balances both freeze levels without querying SHOW LOCKS in production.

Test

Added a regression test that:

  • Performs the real bulk and per-table freezes.
  • Injects a missing file after the per-table freeze.
  • Verifies that backup fails with the expected filesize(): stat failed error.
  • Verifies in the same process that SHOW LOCKS contains no lock for the table.

@sanikolaev
sanikolaev requested a review from donhardman August 4, 2026 10:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant