Skip to content
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

Change: change Vote<NID:NodeId> to Vote<C:RaftTypeConfig> #1279

Merged
merged 1 commit into from
Dec 25, 2024

Conversation

drmingdrmer
Copy link
Member

@drmingdrmer drmingdrmer commented Dec 24, 2024

Changelog

Change: change Vote<NID:NodeId> to Vote<C:RaftTypeConfig>

This refactoring moves Vote from a per-NodeId type to a per-TypeConfig type,
to make it consistent with RaftTypeConfig usage across the codebase.

Upgrade tip:

Vote is now parameterized by RaftTypeConfig instead of NodeId

  • Change Vote<NodeId> to Vote<C> where C: RaftTypeConfig, for
    example, change Vote<u64> to Vote<YourTypeConfig>.

This change is Reviewable

@drmingdrmer drmingdrmer force-pushed the 161-vote-c branch 4 times, most recently from a51c0c3 to 864bc17 Compare December 24, 2024 03:10
This refactoring moves Vote from a per-NodeId type to a per-TypeConfig type,
to make it consistent with `RaftTypeConfig` usage across the codebase.

- Part of: databendlabs#1278

Upgrade tip:

Vote is now parameterized by `RaftTypeConfig` instead of `NodeId`

- Change `Vote<NodeId>` to `Vote<C> where C: RaftTypeConfig`, for
  example, change `Vote<u64>` to `Vote<YourTypeConfig>`.
@drmingdrmer
Copy link
Member Author

To address #1278, types like Vote<NID>, LeaderId<NID>, and LogId<NID> need to be updated to use RaftTypeConfig. This configuration encapsulates all customizable associated types, rather than relying on a single NID: NodeID.

@lichuang
Copy link
Contributor

dose change Vote definition need to do some backward compatibility test?say: save some Vote data of old format, and read it using new format.

@drmingdrmer
Copy link
Member Author

dose change Vote definition need to do some backward compatibility test?say: save some Vote data of old format, and read it using new format.

No. There is no data format change. The only thing changed is the way to declare the data format: Vote<NID> -> Vote<RaftTypeConfig>

@lichuang
Copy link
Contributor

dose change Vote definition need to do some backward compatibility test?say: save some Vote data of old format, and read it using new format.

No. There is no data format change. The only thing changed is the way to declare the data format: Vote<NID> -> Vote<RaftTypeConfig>

i see the new definition is

pub struct Vote<C: RaftTypeConfig> {
    /// The id of the node that tries to become the leader.
    pub leader_id: LeaderId<C::NodeId>,

    pub committed: bool,
}

so there is no format change. but my question is: since the new and old definition declare id as C::NodeId, what the point introduce RaftTypeConfig param instead of NID: NodeId?

@drmingdrmer
Copy link
Member Author

so there is no format change. but my question is: since the new and old definition declare id as C::NodeId, what the point introduce RaftTypeConfig param instead of NID: NodeId?

In order to allow to define all of the data types in protobuf, such as Vote, LeaderId, LogId, these types can not use a Rust type field. But instead, they must reference the types with C::XXX, for example:

struct Vote<NID> {
 leader_id: LeaderId<_>,
 // ..
}

Should be updated to

struct Vote<C> {
 leader_id: C::LeaderId,
}

Copy link
Collaborator

@SteveLauC SteveLauC left a comment

Choose a reason for hiding this comment

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

Reviewed 47 of 47 files at r1.
Reviewable status: all files reviewed (commit messages unreviewed), all discussions resolved (waiting on @schreter)

@drmingdrmer drmingdrmer merged commit 5714674 into databendlabs:main Dec 25, 2024
31 of 32 checks passed
@drmingdrmer drmingdrmer deleted the 161-vote-c branch December 25, 2024 04:34
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.

3 participants