You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hudi.apache.org by "kbuci (via GitHub)" <gi...@apache.org> on 2026/01/13 19:34:26 UTC

[I] [to be discussed] Optimize clean on spark to gracefully handle a large increase in uncleaned files. [hudi]

kbuci opened a new issue, #17844:
URL: https://github.com/apache/hudi/issues/17844

   ### Task Description
   
   **What needs to be done:**
   For instant/duration based cleaning policy (KEEP_LATEST_COMMITS/KEEP_LATEST_BY_HOURS), when would like the implementation of clean planner/execution in spark to be optimized to meet the following requirement:
   
   - If there are new files to be cleaned, then the next clean should be scheduled and executed in a bounded amount of time/memory usage, regardless of how many seconds/commits have elapsed since the prior ECTR (clean's earliest commit to retain). It is acceptable if the new `.clean` only makes "partial" progress and blocks the new ECTR, as long as the next clean plan "resumes" from where this previous clean completed.
   
   
   **Why this task is needed:**
   
   For context, we would like to handle the following scenarios that we have seen for our use cases
   - A dataset has an ingestion spark job which only writes bulk-insert instants. But after a few years, a second concurrent job does a clustering write. This causes the next clean planner attempt (in the ingestion job) to scan thousands of partitions in the dataset, since the prior ECTR doesn't exist or there have been many instants since it. We have seen increased runtimes and spark driver OOM failures - even if there are only a few files to actually "clean" in the clean plan.
   - An update-heavy dataset has had no cleans be attempted (due to a misconfiguration or orchestration issue). When clean runs again, it can OOM when creating the .clean/.clean.requested due to a high # files to clean.
   
   Note that both incremental and non-incremental clean planner determine a list of partitions, and find all updated/replaced file groups before new/proposed ECTR. The difference is the non-incremental clean scans all partitions in the dataset, instead of only partitions referenced by instants since the latest ECTR.
   
   ### Task Type
   
   Code improvement/refactoring
   
   ### Related Issues
   
   **Parent feature issue:** (if applicable )
   **Related issues:**
   NOTE: Use `Relationships` button to add parent/blocking issues after issue is created.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@hudi.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [to be discussed] Configure clean on spark to gracefully handle a large increase in uncleaned files. [hudi]

Posted by "vinothchandar (via GitHub)" <gi...@apache.org>.
vinothchandar commented on issue #17844:
URL: https://github.com/apache/hudi/issues/17844#issuecomment-3888444951

   If you can sketch something e2e that uses empty cleans - and address the "we won't schedule cleaning for months" and "not holding up archival" -- issues, cleanly, that would be awesome.. @kbuci 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@hudi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [to be discussed] Configure clean on spark to gracefully handle a large increase in uncleaned files. [hudi]

Posted by "vinothchandar (via GitHub)" <gi...@apache.org>.
vinothchandar commented on issue #17844:
URL: https://github.com/apache/hudi/issues/17844#issuecomment-3888605617

   Can we write out scenarios/requirements for these?
   
   - Always to incremental cleaning in these scenarios
   - Okay to do full clean planning in these degraded mode states


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@hudi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [to be discussed] Configure clean on spark to gracefully handle a large increase in uncleaned files. [hudi]

Posted by "kbuci (via GitHub)" <gi...@apache.org>.
kbuci commented on issue #17844:
URL: https://github.com/apache/hudi/issues/17844#issuecomment-3820542082

   Thanks for the discussion
   
   @vinothchandar 
   
   > empty clean for now, without any additional format changes or complexity (stop gap)
   
   as requested, here is a PR for supporting an empty clean plan https://github.com/apache/hudi/pull/11605/changes . Surya had created this back in HUDI 0.x, but I can rebase it on latest master if it helps. 
   
   > To ponder; if we can maintain the table service state also in the MDT..
   For our use cases we want to support being able to use "restore" to restore a datasets to an earlier instant on the timeline. So I believe this approach would satisfy that requirement. Since the MDT would also be restored to said instant. But thinking out loud:
   - Even this allows us to no longer need empty clean, we would still need some "operation" that wouldn't actually clean anything but would write a new ECTR to the MDT. And some configuration/logic to determine who (clean? archival?) attempts this operation (and how often). So even though this prevents us from having to block archival on ECTR, it looks to me that we would still have to orchestrate some operation at a regular cadence (the same way we do for empty clean)
   - In our org's 0.14 HUDI workloads, we sometimes have to delete and re-create the MDT to mitigate bugs/issues that merge (since re-creating the MDT is much cheaper for us than re-creating the entire dataset/data files). If we want to still keep this flexibility/mitigation option available in 1.2 without forcing our workloads to do a full scan clean (after this MDT rebootstrap event), we might want to consider also duplicating the latest ECTR somewhere else outside of the proposed MDT partition (such as some [dot] hoodie metafile)
   
   > Orthogonally, love to see some numbers at which we see this issues i.e number of files and such.. 
   
   Sure let me try to find some logs/numbers on our end. But I should mention upfront that, in addition to using HUDI 0.14, we:
   - Do not use timeline server. This is since back in 0.10 we noticed issues (memory pressure iirc) for workloads where we process multiple datasets in a single "ingestion" spark job. And we have not yet internally validated if this still is an issue on 0.14/1.x
   - Use in memory filesystem view.  We don't use spillable filesystem view due to a correctness issue we noticed due to serialization https://github.com/apache/hudi/issues/17957 
   
   
   
   @danny0405 
   > in this commit, the fs view request from clean planner goes though a set of new stateless APIs(that basically does not cache the file group on fs view), so that to midigate the memory pressure of driver.
   
   Thanks for sharing this context. We actually backported some recent changes to clean like https://github.com/apache/hudi/pull/10928 to our 0.14 tbuild o try to mitigate these issues. I have not done any proper profiling but my initial hunch is that:
   - The `shouldUseBatchLookup` option in CleanPlanActionExecutor is continually adding partitions from all batches to the FS view without "unloading" partitions from prior batch. So the driver memory usage continually increases. And then when it is copied over to the spark task (which "looks for" all files to clean in a given partition) that adds more memory usage as well. 
   (note that as mentioned above, although we use MDT we do not use timeline server or spillable FS view)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@hudi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [to be discussed] Configure clean on spark to gracefully handle a large increase in uncleaned files. [hudi]

Posted by "kbuci (via GitHub)" <gi...@apache.org>.
kbuci commented on issue #17844:
URL: https://github.com/apache/hudi/issues/17844#issuecomment-3894416252

   @vinothchandar Thanks for follow-up.
   
   Our requirement that we are discussing currently I believe is still on the same track as what we mentioned earlier: https://github.com/apache/hudi/issues/17844#issuecomment-3815413409 , where as you put it:
   
   > Issue 1 : Avoiding cleaning fallback to full scan mode, when table is updated/clustered sporadically.
   
   I agree that whatever solutions we decide on should ideally be agnostic to write workload of dataset, but taking a step back and going back to the problem, our specific issue/workloads that caused use to raise this requirement is 
   
   > A dataset has an ingestion spark job which only writes bulk-insert instants to the latest partition. But after a few years, a second concurrent job does a clustering write. This causes the next clean planner attempt (in the ingestion job) to scan thousands of partitions in the dataset, since the prior ECTR doesn't exist or there have been many instants since it. We have seen increased runtimes and spark driver OOM failures - even if there are only a few files to actually "clean" in the clean plan.
   
   Or to be even more specific (assuming that clean is being reliably attempted on the dataset):
   -  We have (day based partitioned) datasets with 1000s of partitions - with current setup "full table scan" clean planning takes 10+ minutes
   - Each ingestion write only targets partitions within the last few days, creating only new file groups in each partition
   -  If there are no updates/replace operations for a few days, then ECTR will fall out of active timeline. 
   - The next time a update/replace operation happens, HUDI then attempts a clean right after, but it now has to fallback to full scan clean. Which has the following impact:
   -- If the clean is "inline" during post-commit ingestion phase, then the next write gets delayed
   -- If the clean is ran by a concurrent "table service platform", then the table lock will be held for longer, and indirectly delay ingestion
   
   Our internal approach to resolve this was to make sure we had a way to constantly "bump up" the ECTR even if there was nothing to clean. Which is why the "empty clean" solution. 
   
   Later on though, we came across a different problem/issue that applies to more write workloads: clean is paused/not running for a long time. For our org this typically happened due to 
   - We disable auto clean in ingestion write jobs, due to perf issues (OOM issues mentioned earlier or runtime increases like  https://github.com/apache/hudi/pull/18016 ). Because we didn't have sufficient spark resources, we couldn't onboard this to our table service platform for cleaning. So until the fix was deployed a few weeks later, clean was paused.
   - The next time clean is unpaused, the ingestion job will resort to full table scan. Unless the dataset workload updates a high enough % of older partition, then this will typically be worse performance than an incremental clean. 
   And because of this, we later added a guardrail to our internal HUDI build to block archival on ECTR
   
   As you already brought up though, this is an orchestration issues "outside" of HUDI. I had a discussion with @nsivabalan , and it seems that rather than having our internal hudi build keep on blocking archival on ECTR, we can re-frame the problem as "only attempt archival if clean has finished". For inline table services this means having a way to automatically disable archival if clean is disabled. I will have some more internal discussions on this, but we can track/discuss this separately, and just focus on the "first" issue (bumping up ECTR if there is nothing to clean) in this thread if thats better. We just wanted to bring up the reason for why we currently block archival on ECTR, since I believe you had asked it earlier.
   
   Unfortunately for your other question
   
   > Always to incremental cleaning in these scenarios
   
   I will need some more time to provide a concise answer. Since although hypothetically a large enough timeline will cause a severe read/write runtime degradation, we have not really any encountered any scenario in production where the ingestion/query runtime was so long, that we had to disallow ingesting new records into the dataset (until an archival was forced). 
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@hudi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [to be discussed] Optimize clean on spark to gracefully handle a large increase in uncleaned files. [hudi]

Posted by "nsivabalan (via GitHub)" <gi...@apache.org>.
nsivabalan commented on issue #17844:
URL: https://github.com/apache/hudi/issues/17844#issuecomment-3766338298

   Thanks @kbuci for the feature ask. 
   - May I know if we are looking for a fix in latest master (1.x), or 0.x as well. 
   - Clarification on the 2nd fix w/n your organization: I understand the config to control the "num instants to clean" in every clean operation. But did you guys also consider "num files to clean" config. w/ num files, we can set it to 100k or something which would work for all datasets right. Just that with "num instants to clean", as you pointed out, we might need to manually configure diff values for diff streams. Was just curious on any brainstorming you did before going ahead w/ "num instants to clean" based solution. 
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@hudi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [to be discussed] Optimize clean on spark to gracefully handle a large increase in uncleaned files. [hudi]

Posted by "kbuci (via GitHub)" <gi...@apache.org>.
kbuci commented on issue #17844:
URL: https://github.com/apache/hudi/issues/17844#issuecomment-3775629090

   > Thanks [@kbuci](https://github.com/kbuci) for the feature ask.
   > 
   > * May I know if we are looking for a fix in latest master (1.x), or 0.x as well.
   Just for 1.x, latest master
   > * Clarification on the 2nd fix w/n your organization: I understand the config to control the "num instants to clean" in every clean operation. But did you guys also consider "num files to clean" config. w/ num files, we can set it to 100k or something which would work for all datasets right. Just that with "num instants to clean", as you pointed out, we might need to manually configure diff values for diff streams. 
   
   We considered having "num files to clean" configs in internal design discussions, due to the reasons you raised. Essentially I was thinking of having two types of "knobs"
   - The "num files to clean" . 
   - The storage footprint of the clean planner. For example, even if there is nothing to clean, if there are thousands of partitions with thousands of files each, then the resulting in-memory filesystem view object creating during clean planner may cause memory pressure. For such datasets/workloads, we would probably want some sort of limit on `partition count scanned x files per partition`.
   
   For incremental clean this may mean at the worst case we would only move the ECTR one instant. For full-scan clean its a bit more tricky - we would have to "partially" clean a subset of the partitions per run of clean. 
   
   Also even if we were to add these configs, the next issue would be how to have users know what values to set? It would be ideal if a user could pass in a general config for clean dictating "how much memory should clean use at most", and then HUDI could infer the values for the aforementioned configs
   
   > Was just curious on any brainstorming you did before going ahead w/ "num instants to clean" based solution.
   Back when we implemented that config internally, it was mainly done urgently so that we could quickly mitigate production issues with upsert-heavy datasets. Where if clean was paused for a while and resumed later, the next clean would have to process a large enough count of files to cause an OOM. So regardless of if this config makes it in the final design here, we don't expect this internal config to be sufficient for all the workloads/scenarios discussed above
   
   
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@hudi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [to be discussed] Configure clean on spark to gracefully handle a large increase in uncleaned files. [hudi]

Posted by "vinothchandar (via GitHub)" <gi...@apache.org>.
vinothchandar commented on issue #17844:
URL: https://github.com/apache/hudi/issues/17844#issuecomment-3850182551

   @kbuci thanks for the detailed summary.  I skimmed the PR. tbh - understanding the scale issues (so we can at-least try and reproducing the bottleneck with full cleaning) seems like the first thing to try. 
   
   More thoughts below: 
   
   > we would still need some "operation" that wouldn't actually clean anything but would write a new ECTR to the MDT
   
   Right now that operation is the clean planning, which then writes the empty commit. But you are right that something needs to 'advance' the ECTR periodically and I don't want to add any new table services around this. One idea I am thinking is as follows and can be helpful for the other checkpoint maintenance track as well.  https://github.com/apache/hudi/issues/17848 
   
   
   > if we can maintain the table service state also in the MDT..
   Instead of MDT, we could just make ECTR, checkpoints rolling over metadata in the timeline. If you think about this conceptually, we can either model this as `state` (MDT) or `log` (timeline). 
   
   Any action completed to the timeline is already performed under a lock (if you have multi writers or async table services). So we can safely aggregate such metadata with each write. i.e ECTR would be stored in every instant on the active timeline (ofc a new clean can change that value), even non clean actions. This is way more flexible, we can point to the actual last clean instant in the LSM timeline if needed, read parts of the log efficiently for any planning activity..  
   
   **Question**: Can you confirm that - if the ECTR is always retained in the last instant of timeline - we can resolve your scenario? 
   
   
   
   
   
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@hudi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [to be discussed] Configure clean on spark to gracefully handle a large increase in uncleaned files. [hudi]

Posted by "danny0405 (via GitHub)" <gi...@apache.org>.
danny0405 commented on issue #17844:
URL: https://github.com/apache/hudi/issues/17844#issuecomment-3816327895

   kind of related fix: https://github.com/apache/hudi/pull/10002, in this commit, the fs view request from clean planner goes though a set of new stateless APIs(that basically does not cache the file group on fs view), so that to midigate the memory pressure of driver.
   
   The queried file group from the Http request exists temporarily both on driver and the client(the clean planner).


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@hudi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [to be discussed] Configure clean on spark to gracefully handle a large increase in uncleaned files. [hudi]

Posted by "vinothchandar (via GitHub)" <gi...@apache.org>.
vinothchandar commented on issue #17844:
URL: https://github.com/apache/hudi/issues/17844#issuecomment-3888442695

   > In order to minimize chance of full table scan clean (if archival were to run before ECTR progressed) and avoid incremental clean repeatedly re-reading the same instants from last ECTR (which takes up time).
   
   My thought process here, is to first microbenchmark this at some rough scale points you can share. Then decide. Anything we plan, I'd love to plan alongside LSM timeline. It's not worth spending efforts on other angles IMO. it stretches us thin. 
   
   > But for clean/ECTR, this doesn't fully address the issue (unlike empty clean), since we need to make sure the instant corresponding to the ECTR is getting "progressed" even if there is nothing to clean
   
   To your point,  yes there are still complexities. 
   
   >when we port it to upstream we can remove the requirement of archival needing to block for ECTR
   
   I'd love to sketch a full end-end solution for this. IMO your requirement of running cleaning sporadically i.e clean plan may not run for months and always wanting incremental cleans are at conflict with each other. We can make this work as long as clean is scheduled at-least every few hours for each table being managed. i.e system needs liveness. 
   
   
   Even for approach (b),  whether we can advance ECTR safely in a guaranteed fashion before hitting archival, depends on write activity, e.g delta commits, commits, replace commits. For e.g if you have an existing ECTR at a completed clean, only .deltacommit/ .commit that adds files only (vs producing new file slices) can safely advance ECTR. So, if we get a replace commit in between, we cannot advance ECTR beyond that; ie`clean, c1, c2, ...., c10, replace commit RC| update commit, c11, ... , c50` , we cannot advance ECTR beyond the replace/update commit, right.. and the left side instants could become candidates for archival.. 
   
   In short, we need to embrace the LSM timeline (and become performant at scanning all instants from a given point) [replay log] (OR) after a point, it makes no sense to do log replay i.e we just read MDT and plan the full clean.. I feel we are overdesigning around performance without much real benchmarks,


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@hudi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [to be discussed] Configure clean on spark to gracefully handle a large increase in uncleaned files. [hudi]

Posted by "kbuci (via GitHub)" <gi...@apache.org>.
kbuci commented on issue #17844:
URL: https://github.com/apache/hudi/issues/17844#issuecomment-3874199431

   Thanks for the suggestion, I had a chat with @nsivabalan as well on this and I think this approach (putting the extraMetadata/checkpoint info from last ingestion write in each commit/replacecommit instant regardless of operation type) solves the concern of "losing" ingestion checkpoint info. So we can replace the "empty" commit https://github.com/apache/hudi/pull/11606/changes#diff-9d596db608948d6ebe428c69c82e287baef15e50f9382a701d7eb98260e51aff approach with this suggested approach.
   
   But for clean/ECTR, this doesn't fully address the issue (unlike empty clean), since we need to make sure the instant corresponding to the ECTR is getting "progressed" even if there is nothing to clean. In order to minimize chance of full table scan clean (if archival were to run before ECTR progressed) and avoid incremental clean repeatedly re-reading the same instants from last ECTR (which takes up time). My first thought is that in order to address this (clean) issue we would need to either
   
   a. Implement empty clean. But unlike our org's empty clean approach, when we port it to upstream we can remove the requirement of archival needing to block for ECTR. And we can discuss that guardrail separately, since even empty clean by itself will mostly solve the aforementioned incremental cleaning gaps (if the user is reliably attempting clean on a regular cadence and monitoring for transient failures). 
   
   OR
   
   b. We can build on your suggestion here (of storing the ECTR in every (delta)commit/replacecommit write): when committing the instant the writer itself can update the ECTR if it "knows" that there is nothing behind left to clean since last ECTR, based on instant metadata. Specifically, it will check the instant file metadata of the ECTR and every instant after, and if there are no compacted/replaced/updated( base files), then it will bump up the ECTR as far as it can. I assume the community would not want to go with this approach, since it duplicates some clean logic in ingestion write path and couples clean with ingestion write logic. But just wanted to share it as an alternative  


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@hudi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [to be discussed] Configure clean on spark to gracefully handle a large increase in uncleaned files. [hudi]

Posted by "vinothchandar (via GitHub)" <gi...@apache.org>.
vinothchandar commented on issue #17844:
URL: https://github.com/apache/hudi/issues/17844#issuecomment-4071189352

   I think we aligned on a solution here for now. Assigned it back to you all. (Reassign if its not accurate)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@hudi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [to be discussed] Optimize clean on spark to gracefully handle a large increase in uncleaned files. [hudi]

Posted by "nsivabalan (via GitHub)" <gi...@apache.org>.
nsivabalan commented on issue #17844:
URL: https://github.com/apache/hudi/issues/17844#issuecomment-3792867838

   1a. how to make clean planning efficient for an immutable dataset which has only bulk_inserts, but might have clustering or insert overwrites occasionally. Our best solution is empty cleans for now. Lets propose this in next dev sync meeting. even w/ 1.x, we need to support this use-case for v6 tables.
   1.b: for the same use-case, for v9 tables in 1.x, we can afford to lookup in lsm timeline all the way to prev clean instant if need be. So, even if we take this route for v9 tables, we need a solution for v6 tables (1.a)
   
   2. Avoid OOMs w/ very large cleans. If clean was not running for a longer period of time, when we resume, we do not want to clean say 100 commits in one go. We need a way to make slower progress and eventually catchup w/o causing OOMs. 
   
   3. If there are too many partitions to touch (DIM workload), even for single commit, planning for all partitions could result in OOMs. yet to be re-triaged. 
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@hudi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [to be discussed] Configure clean on spark to gracefully handle a large increase in uncleaned files. [hudi]

Posted by "vinothchandar (via GitHub)" <gi...@apache.org>.
vinothchandar commented on issue #17844:
URL: https://github.com/apache/hudi/issues/17844#issuecomment-3815413409

   To ponder; if we can maintain the table service state also in the MDT.. 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@hudi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org