Development stories

Give table maintenance one owner

KratosForge Editorial · 2026-11-27

Kratos works on one bronze gear secured in a locking jig while other tools wait behind a rail and his wolf watches.
Custom illustration · Give a shared workpiece one maintenance owner at a time.

Compaction is meant to rearrange files while preserving their rows. Two maintenance jobs can each look reasonable in isolation and still conflict when they share a table. KratosForge’s merged PR #3391 addresses a delta-rs 1.6.6 race described in its review: overlapping compactions could both commit their rewrites and leave duplicated rows. Separate cleanup races could remove files another operation had just committed or restored.

The fix gives participating maintenance paths a shared local lock for each table. Notebook OPTIMIZE, Z-Order, VACUUM, the Maintain page’s local compaction and restore paths use that coordination. A competing operation waits up to 120 seconds; if the lock stays busy, it stops without making its maintenance change and explains why. Background metadata compaction and failed-write cleanup use a non-waiting attempt instead: when busy, they skip that work.

The shared local maintenance path
  1. Participating notebook, Maintain or schedule entry point
  2. Acquire the same local per-table lock
  3. Run maintenance, then release ownership

Cleanup is an important part of the decision. A newly created file that is absent from an older table snapshot may belong to another operation preparing its commit. Deleting it as an abandoned write can leave a committed version unreadable. The new failed-write cleanup path removes nothing while the maintenance lock is held and leaves the leftover files for VACUUM. That trades immediate tidiness for preserving files whose ownership is uncertain.

The implementation combines an operating-system file lock with a thread lock, so separate kernels and threads can take turns. Re-entry by the holding context is allowed, avoiding a deadlock when a higher-level operation calls a helper that takes the same lock. The operating system releases the file lock if its process ends. The regression file forces specific overlaps using real child processes, then checks row IDs and that every referenced file still exists. All 15 tests passed locally, including thread exclusion and a killed holder releasing its lock.

The boundary matters. This coordinates participating processes that share the local lock directory; Fabric Spark and another PC do not take this lock. It is not a distributed maintenance lease. The review also records key-normalization gaps for uppercase file://LOCALHOST addresses and file-URI UNC forms. Use a consistent table address and coordinate maintenance schedules across machines rather than treating a local lock as protection from every writer.

This article describes app commit 3b42256 on main. Stable was last updated November 2 when checked on November 27, and no live OneLake concurrency run was performed for this review. For your own maintenance system, list every path that can rewrite, restore or delete table files. Make those paths agree on ownership before testing retries. Then force the overlap and assert the rows and referenced files, not just that both jobs returned successfully.

← All publications

Search documentation

Start typing to search all 115 guides.

Search runs in your browser esc to close