Skip to content

fix: Prevent materialization job from failing when some shards require more work than others #31087

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 10, 2025

Conversation

tkaemming
Copy link
Contributor

@tkaemming tkaemming commented Apr 10, 2025

Problem

If column is materialized in only a subset of shards within a partition, this task was failing.

Changes

Updates implementation to accommodate the situation where some shards require materialization mutations for a partition and others do not.

Does this work well for both Cloud and self-hosted?

Yes

How did you test this code?

Updated existing tests - it's not really feasible to write an integration test for this because our CI ClickHouse only has a single shard, but the updated unit tests should cover the non-overlapping keys (in our case, partition IDs) case that we have been seeing. Existing integration tests and type checks should ensure it runs correctly overall

for key, value in mapping.items():
keys.append(key)
values.append(value)
def join_mappings(mappings: Mapping[K1, Mapping[K2, V]]) -> Mapping[K2, Mapping[K1, V]]:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This not a very good name for this function (it is actually a pretty bad one), but I'm struggling to come up with a good name that describes what this actually does. If you would like to help put me out of my misery, the type signature and tests are probably the best examples of what this is doing. Maybe this is something similar to transposition?

@tkaemming tkaemming requested a review from a team April 10, 2025 21:10
@tkaemming tkaemming marked this pull request as ready for review April 10, 2025 21:12
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Summary

This PR fixes materialization jobs that were failing when only some shards required mutations for a partition by implementing a more robust mapping approach.

  • Added new join_mappings function to handle non-overlapping keys between shards, replacing the previous zip_values function
  • Changed get_mutations_to_run return type from sequence to mapping with partition IDs as keys for better organization
  • Modified run_materialize_mutations to process mutations by partition rather than assuming uniform shard requirements
  • Added detailed logging to track materialization progress by partition
  • Implemented comprehensive tests for the new join_mappings function with various mapping scenarios

2 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings | Greptile

@tkaemming tkaemming merged commit 11eba4c into master Apr 10, 2025
98 checks passed
@tkaemming tkaemming deleted the fix-materialize-partitions branch April 10, 2025 21:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants