Skip to content

refactor(meta): replace manual struct instantiation with constructor methods #18393

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 5 commits into from
Jul 19, 2025

Conversation

drmingdrmer
Copy link
Member

@drmingdrmer drmingdrmer commented Jul 19, 2025

I hereby agree to the terms of the CLA available at: https://docs.databend.com/dev/policies/cla/

Summary

refactor(meta): replace manual struct instantiation with constructor methods

Replace manual struct instantiation with constructor methods across meta types
to improve code consistency and maintainability following the LogEntry pattern:

  • UpsertKV: Use ::new(), ::update(), ::delete() instead of manual instantiation
  • WatchRequest: Use ::new() with ::with_filter(), ::with_initial_flush() builders
  • RaftRequest: Use GrpcHelper::encode_raft_request() for consistent serialization
  • TxnPutRequest: Add ::new() constructor for (key, value, prev_value, expire_at, ttl_ms)
  • TxnGetRequest: Add ::new() constructor for (key)
  • TxnDeleteRequest: Add ::new() constructor for (key, prev_value, match_seq)

This provides better type safety, readability, and ensures field changes only
require updating constructor methods rather than scattered manual instantiations.

refactor(meta): replace manual LogEntry construction with constructor methods

Replace manual LogEntry struct instantiation with LogEntry::new(cmd) for cases
where time_ms is None, and introduce LogEntry::new_with_time(cmd, time_ms) for
cases that need to preserve existing timestamps.

Tests

  • Unit Test
  • Logic Test
  • Benchmark Test
  • No Test - Explain why

Type of change

  • Other

Related Issues


This change is Reviewable

… methods

Replace manual LogEntry struct instantiation with LogEntry::new(cmd) for cases
where time_ms is None, and introduce LogEntry::new_with_time(cmd, time_ms) for
cases that need to preserve existing timestamps.
…methods

Replace manual struct instantiation with constructor methods across meta types
to improve code consistency and maintainability following the LogEntry pattern:

- UpsertKV: Use ::new(), ::update(), ::delete() instead of manual instantiation
- WatchRequest: Use ::new() with ::with_filter(), ::with_initial_flush() builders
- RaftRequest: Use GrpcHelper::encode_raft_request() for consistent serialization
- TxnPutRequest: Add ::new() constructor for (key, value, prev_value, expire_at, ttl_ms)
- TxnGetRequest: Add ::new() constructor for (key)
- TxnDeleteRequest: Add ::new() constructor for (key, prev_value, match_seq)

This provides better type safety, readability, and ensures field changes only
require updating constructor methods rather than scattered manual instantiations.
@github-actions github-actions bot added the pr-refactor this PR changes the code base without new features or bugfix label Jul 19, 2025
…odule access

- Remove unused MatchSeq and Operation imports from util.rs
- Fix grpc_helper module access by using re-exported GrpcHelper
- Ensure all constructor method refactoring passes clippy lints
@drmingdrmer drmingdrmer marked this pull request as ready for review July 19, 2025 13:08
@drmingdrmer drmingdrmer merged commit 31678f2 into databendlabs:main Jul 19, 2025
89 checks passed
@drmingdrmer drmingdrmer deleted the 355-meta-refactor branch July 19, 2025 13:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr-refactor this PR changes the code base without new features or bugfix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant