Urgent.News

What's breaking now, across hundreds of outlets.

Tech

Your nightly OPTIMIZE and your streaming MERGE are fighting over the same files

The maintenance notebook is three lines, it ran fine for a month, and now it fails most nights with a concurrent modification error. Nothing changed in the notebook. What changed is that the streaming job feeding the same table got busier. -- nightly maintenance notebook (Spark SQL), 02:00 OPTIMIZE silver_events ; VACUUM silver_events ; DESCRIBE HISTORY silver_events LIMIT 5 ; Why it only breaks…

A maintenance job that optimizes the "silver_events" table is failing nightly due to concurrent modification errors. The issue is not with the maintenance notebook or the jobs themselves, but rather the timing of when they run. The streaming job feeding the same table has become busier, causing conflicts between the two jobs.

Unlike SQL Server, Delta uses optimistic concurrency, meaning both writers can proceed simultaneously. The one that commits second checks whether the files it read are still current. If not, it fails, leading to the concurrent modification error. This is not a queue, but a race condition between the two jobs.

To fix the issue, the maintenance job should only optimize a specific partition of the table, using a partition predicate. This ensures that the job only rewrites files in the recent partitions, which the streaming MERGE has already finished writing to. By doing so, the two jobs no longer rewrite the same files, eliminating the possibility of a collision.

Additionally, the maintenance job should use the ZORDER BY clause to improve query performance. Partitioning on a high-cardinality column can create millions of tiny folders, leading to poor query performance. Z-ordering, on the other hand, co-locates each customer's rows into a few files within each event_date partition, allowing the filter to skip most files and improving query performance.

In summary, the concurrent modification errors are caused by the timing of the streaming MERGE and the maintenance job rewriting the same files. By optimizing only a specific partition of the table, using a partition predicate, and employing Z-ordering, the two jobs can run concurrently without conflicts, and the maintenance job will no longer fail.

Rewritten by urgent.news; may contain errors — check the original.

Source: dev.to

Read the original at dev.to →

Report a problem with this story

More in Tech

How to monitor cron jobs (and know when they silently fail)

Cron has one job: start a command at a time. It doesn’t check whether the command worked, and it can’t tell you about runs that never started. Nobody looks for those, so they cost the most.

  • Implement a heartbeat check to monitor cron job success
  • Secure the ping URL, accessible only to the job's user
  • Adjust grace period based on job's run time and schedule

How to Become a Forward Deployed Engineer: Career Guide for Developers, Architects and Business Analysts

Short answer Developers, architects and business analysts each bring part of the forward deployed engineer profile. Developers have the code, architects the systems thinking, analysts the discovery…

  • Forward deployed engineers combine developer, architect, and business analyst skills.
  • Success requires expertise in all three areas and comfort with ambiguity and pressure.
  • Transition involves six to twelve months of skill-building and customer engagement.

More from Tuesday, 1 December 2026 →