apache / hudi

Upserts, Deletes And Incremental Processing on Big Data.
https://hudi.apache.org/
Apache License 2.0
5.23k stars 2.39k forks source link

[SUPPORT] Flink COW append mode unnecessary replacecommit in old partitions #9130

Open ertanden opened 1 year ago

ertanden commented 1 year ago

Describe the problem you faced

We have an append mode COW table, where we sink messages incoming from a Kafka topic. Table is partitioned by day.

Clustering is enabled and we also have cleaner configured with KEEP_LATEST_FILE_VERSIONS for retaining only 1 file version.

The problem is whenever clustering is triggered, although the previous day partitions already has just a single file and no new commits in those old partitions, there's still a replacecommit periodically applied. So it seems like it copies the single file unnecessarily to a new one and then the cleaner gets rid of the old file. I tried setting the clustering filter mode to RECENT_DAYS, but it still does the same thing for the partition of yesterday.

You can see down below the timeline for the partition from yesterday 2023-07-04.

Am I missing something? Is there some configuration I need to make to prevent this? Or is this a bug?

Thanks!

Expected behavior

I don't expect a replacecommit when there's only a single file anyways in the partition without any new commits.

Environment Description

Additional context

╔═══════════════╤═══════════════════╤════════════╤═════════════════════════════════════════╤═════════════════╤════════════╤═════════════╤═════════════╤═══════════════════╤══════════════╤══════════════════╤═════════════════════════╤═══════════════════════╤═══════════════════╤═════════════════════════════════╤═════════════════════╗
║ Action        │ Instant           │ Partition  │ FileId                                  │ Previous Commit │ Num Writes │ Num Inserts │ Num Deletes │ Num Update Writes │ Total Errors │ Total Log Blocks │ Total Corrupt LogBlocks │ Total Rollback Blocks │ Total Log Records │ Total Updated Records Compacted │ Total Bytes Written ║
╠═══════════════╪═══════════════════╪════════════╪═════════════════════════════════════════╪═════════════════╪════════════╪═════════════╪═════════════╪═══════════════════╪══════════════╪══════════════════╪═════════════════════════╪═══════════════════════╪═══════════════════╪═════════════════════════════════╪═════════════════════╣
║ replacecommit │ 20230705152558040 │ 2023-07-04 │ 8a61fa78-edb6-4921-b339-a3e1d1a3124d-0  │ null            │ 6705       │ 6705        │ 0           │ 0                 │ 0            │ 0                │ 0                       │ 0                     │ 0                 │ 0                               │ 674,2 KB            ║
╟───────────────┼───────────────────┼────────────┼─────────────────────────────────────────┼─────────────────┼────────────┼─────────────┼─────────────┼───────────────────┼──────────────┼──────────────────┼─────────────────────────┼───────────────────────┼───────────────────┼─────────────────────────────────┼─────────────────────╢
║ replacecommit │ 20230705152158072 │ 2023-07-04 │ 027e0d7a-4be8-4661-9399-b80e3eedd24c-0  │ null            │ 6705       │ 6705        │ 0           │ 0                 │ 0            │ 0                │ 0                       │ 0                     │ 0                 │ 0                               │ 674,2 KB            ║
╟───────────────┼───────────────────┼────────────┼─────────────────────────────────────────┼─────────────────┼────────────┼─────────────┼─────────────┼───────────────────┼──────────────┼──────────────────┼─────────────────────────┼───────────────────────┼───────────────────┼─────────────────────────────────┼─────────────────────╢
║ replacecommit │ 20230705151758257 │ 2023-07-04 │ 62cc0a2b-4b3a-473d-a18c-091ee8e4846b-0  │ null            │ 6705       │ 6705        │ 0           │ 0                 │ 0            │ 0                │ 0                       │ 0                     │ 0                 │ 0                               │ 674,2 KB            ║
╟───────────────┼───────────────────┼────────────┼─────────────────────────────────────────┼─────────────────┼────────────┼─────────────┼─────────────┼───────────────────┼──────────────┼──────────────────┼─────────────────────────┼───────────────────────┼───────────────────┼─────────────────────────────────┼─────────────────────╢
║ replacecommit │ 20230705151357744 │ 2023-07-04 │ bc0974ba-3f2a-4885-accd-05133f44366b-0  │ null            │ 6705       │ 6705        │ 0           │ 0                 │ 0            │ 0                │ 0                       │ 0                     │ 0                 │ 0                               │ 674,2 KB            ║
╟───────────────┼───────────────────┼────────────┼─────────────────────────────────────────┼─────────────────┼────────────┼─────────────┼─────────────┼───────────────────┼──────────────┼──────────────────┼─────────────────────────┼───────────────────────┼───────────────────┼─────────────────────────────────┼─────────────────────╢
║ replacecommit │ 20230705150958014 │ 2023-07-04 │ 9a8e88e1-8109-4554-840d-df188eb097cd-0  │ null            │ 6705       │ 6705        │ 0           │ 0                 │ 0            │ 0                │ 0                       │ 0                     │ 0                 │ 0                               │ 674,2 KB            ║
╟───────────────┼───────────────────┼────────────┼─────────────────────────────────────────┼─────────────────┼────────────┼─────────────┼─────────────┼───────────────────┼──────────────┼──────────────────┼─────────────────────────┼───────────────────────┼───────────────────┼─────────────────────────────────┼─────────────────────╢
║ replacecommit │ 20230705150558125 │ 2023-07-04 │ 9ec0aaa8-4abd-4f31-826f-1e7dcd7fe985-0  │ null            │ 6705       │ 6705        │ 0           │ 0                 │ 0            │ 0                │ 0                       │ 0                     │ 0                 │ 0                               │ 674,2 KB            ║
╟───────────────┼───────────────────┼────────────┼─────────────────────────────────────────┼─────────────────┼────────────┼─────────────┼─────────────┼───────────────────┼──────────────┼──────────────────┼─────────────────────────┼───────────────────────┼───────────────────┼─────────────────────────────────┼─────────────────────╢
║ replacecommit │ 20230705150158159 │ 2023-07-04 │ e1acfa81-cd29-41b8-bc76-8ce83330ce10-0  │ null            │ 6705       │ 6705        │ 0           │ 0                 │ 0            │ 0                │ 0                       │ 0                     │ 0                 │ 0                               │ 674,2 KB            ║
╟───────────────┼───────────────────┼────────────┼─────────────────────────────────────────┼─────────────────┼────────────┼─────────────┼─────────────┼───────────────────┼──────────────┼──────────────────┼─────────────────────────┼───────────────────────┼───────────────────┼─────────────────────────────────┼─────────────────────╢
║ commit        │ 20230705150022378 │ 2023-07-04 │ 3a6bdbd2-15f4-492a-a46d-66e88a4c9a2f-28 │ null            │ 117        │ 117         │ 0           │ 0                 │ 0            │ 0                │ 0                       │ 0                     │ 0                 │ 0                               │ 432,9 KB            ║
╟───────────────┼───────────────────┼────────────┼─────────────────────────────────────────┼─────────────────┼────────────┼─────────────┼─────────────┼───────────────────┼──────────────┼──────────────────┼─────────────────────────┼───────────────────────┼───────────────────┼─────────────────────────────────┼─────────────────────╢
║ commit        │ 20230705145923082 │ 2023-07-04 │ 62eb405a-7cbf-46cb-b7b8-2577bb65184f-37 │ null            │ 100        │ 100         │ 0           │ 0                 │ 0            │ 0                │ 0                       │ 0                     │ 0                 │ 0                               │ 431,7 KB            ║
╟───────────────┼───────────────────┼────────────┼─────────────────────────────────────────┼─────────────────┼────────────┼─────────────┼─────────────┼───────────────────┼──────────────┼──────────────────┼─────────────────────────┼───────────────────────┼───────────────────┼─────────────────────────────────┼─────────────────────╢
║ commit        │ 20230705145923082 │ 2023-07-04 │ ec3a9beb-71c7-4750-b81c-7367f37c85fb-36 │ null            │ 11         │ 11          │ 0           │ 0                 │ 0            │ 0                │ 0                       │ 0                     │ 0                 │ 0                               │ 428,3 KB            ║
╟───────────────┼───────────────────┼────────────┼─────────────────────────────────────────┼─────────────────┼────────────┼─────────────┼─────────────┼───────────────────┼──────────────┼──────────────────┼─────────────────────────┼───────────────────────┼───────────────────┼─────────────────────────────────┼─────────────────────╢
║ commit        │ 20230705145830077 │ 2023-07-04 │ 9a000aad-aacb-471f-bc38-30123a654607-8  │ null            │ 2166       │ 2166        │ 0           │ 0                 │ 0            │ 0                │ 0                       │ 0                     │ 0                 │ 0                               │ 514,2 KB            ║
╟───────────────┼───────────────────┼────────────┼─────────────────────────────────────────┼─────────────────┼────────────┼─────────────┼─────────────┼───────────────────┼──────────────┼──────────────────┼─────────────────────────┼───────────────────────┼───────────────────┼─────────────────────────────────┼─────────────────────╢
║ commit        │ 20230705145830077 │ 2023-07-04 │ 3673fdd1-22b9-4007-ba3c-57d12140a4aa-3  │ null            │ 1573       │ 1573        │ 0           │ 0                 │ 0            │ 0                │ 0                       │ 0                     │ 0                 │ 0                               │ 488,5 KB            ║
╟───────────────┼───────────────────┼────────────┼─────────────────────────────────────────┼─────────────────┼────────────┼─────────────┼─────────────┼───────────────────┼──────────────┼──────────────────┼─────────────────────────┼───────────────────────┼───────────────────┼─────────────────────────────────┼─────────────────────╢
║ commit        │ 20230705145830077 │ 2023-07-04 │ cb7f38c3-a396-4f7e-93a6-98f17d969793-2  │ null            │ 407        │ 407         │ 0           │ 0                 │ 0            │ 0                │ 0                       │ 0                     │ 0                 │ 0                               │ 442,0 KB            ║
╟───────────────┼───────────────────┼────────────┼─────────────────────────────────────────┼─────────────────┼────────────┼─────────────┼─────────────┼───────────────────┼──────────────┼──────────────────┼─────────────────────────┼───────────────────────┼───────────────────┼─────────────────────────────────┼─────────────────────╢
║ commit        │ 20230705145830077 │ 2023-07-04 │ 7a1f01a3-9b97-410b-9046-e9b48cd4e8d0-24 │ null            │ 1588       │ 1588        │ 0           │ 0                 │ 0            │ 0                │ 0                       │ 0                     │ 0                 │ 0                               │ 489,2 KB            ║
╟───────────────┼───────────────────┼────────────┼─────────────────────────────────────────┼─────────────────┼────────────┼─────────────┼─────────────┼───────────────────┼──────────────┼──────────────────┼─────────────────────────┼───────────────────────┼───────────────────┼─────────────────────────────────┼─────────────────────╢
║ replacecommit │ 20230705145827741 │ 2023-07-04 │ 8a4217a1-13cb-4f7d-a1bd-259cdaa6d246-0  │ null            │ 743        │ 743         │ 0           │ 0                 │ 0            │ 0                │ 0                       │ 0                     │ 0                 │ 0                               │ 458,7 KB            ║
╟───────────────┼───────────────────┼────────────┼─────────────────────────────────────────┼─────────────────┼────────────┼─────────────┼─────────────┼───────────────────┼──────────────┼──────────────────┼─────────────────────────┼───────────────────────┼───────────────────┼─────────────────────────────────┼─────────────────────╢
║ commit        │ 20230705145730210 │ 2023-07-04 │ 33744ee3-9c78-47d5-ae64-4655e071dc80-38 │ null            │ 51         │ 51          │ 0           │ 0                 │ 0            │ 0                │ 0                       │ 0                     │ 0                 │ 0                               │ 429,6 KB            ║
╟───────────────┼───────────────────┼────────────┼─────────────────────────────────────────┼─────────────────┼────────────┼─────────────┼─────────────┼───────────────────┼──────────────┼──────────────────┼─────────────────────────┼───────────────────────┼───────────────────┼─────────────────────────────────┼─────────────────────╢
║ commit        │ 20230705145730210 │ 2023-07-04 │ 8de58cf1-9cc6-4cfb-a2ae-2baa846a62f9-33 │ null            │ 319        │ 319         │ 0           │ 0                 │ 0            │ 0                │ 0                       │ 0                     │ 0                 │ 0                               │ 439,5 KB            ║
╟───────────────┼───────────────────┼────────────┼─────────────────────────────────────────┼─────────────────┼────────────┼─────────────┼─────────────┼───────────────────┼──────────────┼──────────────────┼─────────────────────────┼───────────────────────┼───────────────────┼─────────────────────────────────┼─────────────────────╢
║ commit        │ 20230705145730210 │ 2023-07-04 │ aa7321dc-a64a-412e-8131-3977e53b720e-44 │ null            │ 373        │ 373         │ 0           │ 0                 │ 0            │ 0                │ 0                       │ 0                     │ 0                 │ 0                               │ 442,5 KB            ║
╚═══════════════╧═══════════════════╧════════════╧═════════════════════════════════════════╧═════════════════╧════════════╧═════════════╧═════════════╧═══════════════════╧══════════════╧══════════════════╧═════════════════════════╧═══════════════════════╧═══════════════════╧═════════════════════════════════╧═════════════════════╝
voonhous commented 1 year ago

@ertanden A fix has been submitted for this recently to skip clustering for a single input filegroup.

  1. https://github.com/apache/hudi/pull/7159
  2. https://github.com/apache/hudi/pull/8347

You will have to set these 2 configurations accordingly in order for this to take effect:

hoodie.clustering.plan.strategy.single.group.clustering.enabled=false
hoodie.clustering.plan.strategy.sort.columns="" 

Note that hoodie.clustering.plan.strategy.sort.columns will need to be null or empty.

p.s. I noticed that the configuration pages hasn't been updated, which is why this feature isn't documented in the official docsite.

ertanden commented 1 year ago

@voonhous thanks for the information, very helpful. Indeed, it would be nice to have this documented. I think the issue can be closed once the documentation is in place.

On the other side, I thought that this should be the default behavior. The extra configuration needed seems a bit sketchy. For example it is recommended to have a sortable key etc for clustering to work better, but then to prevent constant file re-writes we need to disable the sort columns?

Sorry, I may not have enough information about the internals how clustering works, but just trying to express what makes sense... I just feel that this default behavior is not optimized or even buggy.

voonhous commented 1 year ago

@ertanden, I agree that these 2 configurations are conflicting with each other.

Clustering is usually performed together with sorting. And to disable single file group clustering, we are giving up sorting.

Should offline clustering be enabled as a scheduled service, this would mean that these 2 "features" are mutually exclusive of each other, you can have one, but not both.

As such, there's a PR here that is working on improving this: https://github.com/apache/hudi/pull/8760

IMO, if there's a single group that is considered for clustering, sorting shouldn't be considered as sorting will not yield any added reasonable/significant read performance on a file that is predetermined to be "small" anyways.

Hence, I do agree that the default behaviour can be improved.