Menu

Your nightly OPTIMIZE and your streaming MERGE are fighting over the same files
πŸ“°

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

DEV Community: azureΒ·Gyan AIΒ·about 7 hours ago
#I1c4zmPj
#devtoazure#devto#dev#files#table
Long article (652 words) β€” no AI summary yet.
Reading 0:00
15s threshold

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 ;

Enter fullscreen mode

Exit fullscreen mode

Why it only breaks sometimes

If your background is SQL Server, this is the assumption that bites. SQL Agent jobs serialise against a table using locks: the second writer waits. Delta does not. Delta uses optimistic concurrency β€” both writers proceed, and the one that commits second checks whether the files it read are still current. If they are not, it fails rather than corrupting the table.

So a nightly OPTIMIZE rewriting files while a streaming MERGE is writing into the same files is not a queue. It is a race, and the loser raises a concurrent modification error.…

Continue reading β€” create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.