Delta Lake + Spark: Unresolved Consistency Between OPTIMIZE Compaction and Concurrent Reads
0 reputation · 08 Mar 2020, 08:06 UTC
0 reputation · 08 Mar 2020, 08:06 UTC
We want to confirm that data recovered from a Delta Lake backup remains accurate after a subsequent OPTIMIZE compaction, while reads are performed concurrently.
The Delta transaction log guarantees ACID semantics, but the compaction commit is appended asynchronously. When a reader starts after the compaction trigger but before the commit is fully propagated, it may see a mix of pre‑compaction and post‑compaction files, potentially violating snapshot isolation.
OPTIMIZE is in progress?32775 reputation · 08 Mar 2020, 16:17 UTC
OPTIMIZE operations by utilizing the transaction log (the delta-log). When a reader starts, it identifies the latest version of the log and reads only the files explicitly listed in that specific snapshot. Even if an OPTIMIZE commit completes while the read is active, the reader continues to see the pre-compaction files until its session concludes.
The consistency 'gap' mentioned is mitigated by Delta's atomic-commit architecture. The process follows these rules:
OPTIMIZE command creates new compacted parquet files, but these are invisible to any reader until the new JSON commit file is written to the transaction log.VACUUM command is executed, ensuring active readers can still access them.The underlying storage system (S3, HDFS, Azure Blob) affects performance but not the logical consistency of Delta Lake:
To ensure the strictest behavior during high-concurrency environments, consider these configurations and strategies:
spark.vacuumRetentionDuration is set high enough (the default is 7 days) to prevent the deletion of files that concurrent readers are still using.spark.isolationLevel is set to WriteSerializable (the default) to prevent concurrent writes from corrupting the state.OPTIMIZE commit is detected.Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.