Skip to content

refactor(metadata): split long files in the metadata crate - #5151

Open
thepatrykk wants to merge 6 commits into
masterfrom
refactor/file-length-metadata
Open

thepatrykk wants to merge 6 commits into
masterfrom
refactor/file-length-metadata

Conversation

@thepatrykk

Copy link
Copy Markdown
Contributor

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.

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
thepatrykk marked this pull request as ready for review December 1, 2026 18:32
@github-actions github-actions Bot added the S-waiting-on-review PR is waiting on a reviewer label Dec 1, 2026

This branch has not been deployed

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

Labels

S-waiting-on-review PR is waiting on a reviewer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant