Skip to content

Avoid rewriting big files in RewriteDataFilesAction #1159

Closed as not planned
Closed as not planned

Description

@JingsongLi

I try to use RewriteDataFilesAction to avoid too many small files.
But every time will rewrite all files even just have few small files. It is very expensive and slow.

So:

  • can RewriteDataFilesAction provides a Predicate<FileScanTask> like RewriteManifestsAction for giving a way to avoid rewriting big files.

Activity

  1. jerryshao commented on Jul 10, 2020

    @jerryshao
    Contributor

    I think you can specify filter expressions to rewrite files you wanted. For example, you can only rewrite data under newly added partition, not the whole data. I'm not sure if that is enough for you.

  2. JingsongLi commented on Jul 13, 2020

    @JingsongLi
    ContributorAuthor

    I think you can specify filter expressions to rewrite files you wanted. For example, you can only rewrite data under newly added partition, not the whole data. I'm not sure if that is enough for you.

    Thanks for reply. Yes, using partition just rewrite once is OK.
    I think we optimize further, if the partition is "day_time + type", some type has enough records in its files, but some others may have less records so leads to small files, so I rewrite the all newly partitions for reduce files but can skip big files in some partitions.

  3. rdblue commented on Jul 26, 2020

    @rdblue
    Contributor

    We do this a bit differently: instead of rewriting everything that matches a filter, we configure the rewrite to primarily look for small files. Any file already near the target size is ignored, and then we bin pack the rest of the files in each partition and rewrite. That ensures that we don't rewrite large amounts of data that are already reasonably sized. We don't care about files that are too large because they can be split, only the small files.

    We also have an option to keep the files in order by file name for systems like Spark that sort the data. This is a hacky way to avoid ruining file pruning that takes advantage of clustered/sorted data.

  4. aokolnychyi commented on Jul 27, 2020

    @aokolnychyi
    Contributor

    I am working on a doc that will propose multiple compaction strategies depending on a use case. I want to map SQL extensions into that. We have been running those for a while and they proved to work even on large tables and already covers what @rdblue mentioned. I'll share the doc by the end of the week.

  5. davseitsev commented on Aug 4, 2020

    @davseitsev
    Contributor

    @rdblue logic that you described doesn't work for me. I have Spark Structured Streaming job which writes daily partitioned table and produce files of different size, primarily small ones. I ran RewriteDataFilesAction a few times on a single partition.
    First run produced 86 files with size up to 128Mb as I configured. Second run took all these files and compacted them again merging them with very small files. Third run again took all files produced by previous job and compacted them again.

    I understand that eventually compacted files will become so close to targetSize that they will be ignored, but until this happened we need to rewrite gigabytes of data again and again. Also it doesn't work for me because compaction process is relevant only for current day. At the beginning of new day we run major compaction with deduplication, sorting etc. and like "close" partition for previous day, it will not be modified anymore. Intermediate minor compaction is necessary only to prevent clients from reading thousands of small files.

    Applying filter by row timestamp can improve the situation, but as we have many tables with completely different size we need to choose right compaction period for each table to have output files with reasonable size. It's really difficult to manage because their size can vary, new table can be added, etc. Also we have late records which could not be considered for compaction if there is no fresh records in the file.

    It would be really nice to have separate configuration to limit file size or the predicate like @JingsongLi suggested.

  6. rdblue commented on Aug 4, 2020

    @rdblue
    Contributor

    What I was saying is that the service we built to do this chooses what to rewrite differently. The behavior of the rewrite action is as you describe: it will rewrite more than is necessary so we should add more configuration to provide more control.

  7. aokolnychyi commented on Aug 4, 2020

    @aokolnychyi
    Contributor

    The doc for data compaction is almost ready. It should cover what @davseitsev experiences.

  8. aokolnychyi commented on Aug 5, 2020

    @aokolnychyi
    Contributor

    The proposal is here. I'll keep editing it in the following days.

  9. github-actions commented on Feb 11, 2024

    @github-actions

    This issue has been automatically marked as stale because it has been open for 180 days with no activity. It will be closed in next 14 days if no further activity occurs. To permanently prevent this issue from being considered stale, add the label 'not-stale', but commenting on the issue is preferred when possible.

  10. github-actions commented on Feb 26, 2024

    @github-actions

    This issue has been closed because it has not received any activity in the last 14 days since being marked as 'stale'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions