Repository navigation
refactor(metadata): split long files in the metadata crate - #5151
Open
thepatrykk wants to merge 6 commits into
Open
thepatrykk wants to merge 6 commits into
thepatrykk wants to merge 6 commits into
Conversation
impls/recovery.rs and stm/user.rs ran past the 2500 line limit of file-length.sh. Their tests move into a tests.rs file of each module as they are, so the test paths do not change and both files fall under the limit.
change_log/tests.rs ran past the 2500 line limit of file-length.sh. Its tests move into change_log/tests/ by topic: streams, topics, groups, users, sessions, paging and credentials. A helper that serves one topic moves with it, and the Harness and the shared helpers stay in tests.rs.
The tests of impls/metadata.rs came to 9061 lines, more than one file can hold under the 2500 line limit of file-length.sh. They move into impls/metadata/tests/, one file per topic: prepares, snapshots, sessions, placement, topic_options, admission, commit_walk, checkpoint_jobs, logouts and transfers. A helper that serves one topic moves with it, and the shared helpers stay in tests/mod.rs.
The tests of stm/stream.rs came to 5498 lines, more than one file can hold under the 2500 line limit of file-length.sh. They move into stm/stream/tests/, one file per topic: topics, durability, snapshots, changes, resolution, counts, replication and captures. A helper that serves one topic moves with it. The shared helpers stay in tests/mod.rs, with the pub helpers that the snapshot, shadow and metadata tests import.
impls/metadata.rs ran past the 2500 line limit of file-length.sh with 4853 lines of code. Its two largest IggyMetadata impl blocks move into impl blocks with the same header in impls/metadata/, by what they do: state_transfer, in_process, commit_flow, checkpoints, placement_admission and replication. The Plane and PlaneIdentity impls cannot be split, so they move whole into plane.rs. The types, the smaller impl blocks and the free functions stay in metadata.rs. The methods move as they are, apart from the line wraps that rustfmt makes. The 19 methods that another new module calls get pub(super), which keeps them inside impls::metadata. Each new module imports the names it uses, because the crate denies wildcard_imports. The checkpoint test hooks that exist only in test builds are imported under #[cfg(test)], and the imports that only the tests used move into impls/metadata/tests/mod.rs.
stm/stream.rs ran past the 2500 line limit of file-length.sh with 4171 lines of code. The Streams impl block moves into impl blocks in stm/stream/, by what the methods do: lookups, groups, partition_queries, replication and seeding. The StateHandler impls of the stream, topic and partition requests move into handlers.rs with the helpers that only they use. The types, the snapshot code and the other impls stay in stream.rs. The code moves as it is. stream.rs re-exports the five handler items that user.rs and shadow.rs import, so their paths do not change. Those items are declared pub instead of pub(crate), because clippy::redundant_pub_crate refuses pub(crate) in a private module, and the re-export keeps them inside the crate. Each new module imports the names it uses, and the imports that only the tests used move into stm/stream/tests/mod.rs.
thepatrykk
marked this pull request as ready for review
December 1, 2026 18:32
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
scripts/ci/file-length.sh caps a Rust file at 2500 lines of code.
Five files of the metadata crate sat over the cap on the allowlist,
impls/metadata.rs with 13913 lines and stm/stream.rs with 9668.
In three of the files the tests made the length. The impls/recovery.rs
and stm/user.rs tests move into a tests.rs file of each module, and
change_log/tests.rs splits by topic into change_log/tests/. The tests
of impls/metadata.rs and stm/stream.rs came to 9061 and 5498 lines,
so they move into a tests/ directory of each module with one file per
topic.
Even without their tests, impls/metadata.rs and stm/stream.rs held
4853 and 4171 lines of code. The two largest IggyMetadata impl blocks
move into impl blocks with the same header in impls/metadata/, by
what the methods do, and the Plane impl moves whole into plane.rs.
The Streams impl splits the same way into stm/stream/, and the
StateHandler impls of the stream, topic and partition requests move
into handlers.rs.
The code moves as it is, apart from the line wraps that rustfmt makes.
The 19 methods that another new module calls get pub(super), and
stream.rs re-exports the handler items that other modules import, so
no path outside the split modules changes. Each new code module
imports the names it uses, because the crate denies wildcard_imports.
Each step is a commit of its own. The same 602 tests pass before and
after, and the five files leave the allowlist.