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

MINOR: A few cleanups for DescribeQuorum APIs #12548

Merged
merged 7 commits into from Aug 24, 2022

Conversation

hachikuji
Copy link
Contributor

@hachikuji hachikuji commented Aug 22, 2022

A few small cleanups:

  • Change field types in QuorumInfo:
    • leaderId: Integer -> int
    • leaderEpoch: Integer -> long (to allow for type expansion in the future)
    • highWatermark: Long -> long
  • Use field names lastFetchTimestamp and lastCaughtUpTimestamp consistently
  • Move construction of DescribeQuorumResponseData.PartitionData into LeaderState
  • Consolidate fetch time/offset update logic into LeaderState.ReplicaState.updateFollowerState

Committer Checklist (excluded from commit message)

  • Verify design and implementation
  • Verify test coverage and CI build status
  • Verify documentation (including upgrade notes)

Copy link
Member

@jsancio jsancio left a comment

Choose a reason for hiding this comment

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

Thanks for the changes. Wanted to give you a quick review. Working on a more thorough review.

Copy link
Contributor

@showuon showuon left a comment

Choose a reason for hiding this comment

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

Thanks for the PR. Left some comments.

private final Integer leaderEpoch;
private final Long highWatermark;
private final int leaderId;
private final long leaderEpoch;
Copy link
Contributor

Choose a reason for hiding this comment

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

The leaderEpoch is in int32 type, any reason we change to use long here?

{ "name": "LeaderEpoch", "type": "int32", "versions": "0+",
"about": "The latest known leader epoch"},

Comment on lines 66 to 84
return leaderId.equals(that.leaderId)
&& voters.equals(that.voters)
&& observers.equals(that.observers);
return leaderId == that.leaderId
&& leaderEpoch == that.leaderEpoch
&& highWatermark == that.highWatermark
&& Objects.equals(highWatermarkUpdateTimeMs, that.highWatermarkUpdateTimeMs)
&& Objects.equals(voters, that.voters)
&& Objects.equals(observers, that.observers);
Copy link
Contributor

Choose a reason for hiding this comment

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

nice catch!

|LeaderId: ${quorumInfo.leaderId}
|LeaderEpoch: ${quorumInfo.leaderEpoch}
|HighWatermark: ${quorumInfo.highWatermark}
|HighWatermarkUpdateTimeMs: ${quorumInfo.highWatermarkUpdateTimeMs}
Copy link
Contributor

Choose a reason for hiding this comment

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

Since this is a script output, I think it'd better we did some pre-processing to avoid printing out something like: OptionalLong[12345] or OptionalLong.empty.

@@ -304,7 +311,7 @@ public long epochStartOffset() {
return epochStartOffset;
}

private ReplicaState getReplicaState(int remoteNodeId) {
private ReplicaState getOrCreateReplicaState(int remoteNodeId) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nice renaming

DescribeQuorumResponseData.ReplicaState leaderState = voterStates.stream()
.filter(voterState -> voterState.replicaId() == localId)
.findFirst()
.orElseThrow(() -> new AssertionError(""));
Copy link
Contributor

Choose a reason for hiding this comment

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

Forgot to add the error message here and below.

Copy link
Contributor

Choose a reason for hiding this comment

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

Please update it and below. Thanks.

@showuon
Copy link
Contributor

showuon commented Aug 23, 2022

Also, some MetadataQuorumCommandTest tests failed due to this change. FYI.
cc @dengziming , who just updated the metadata quorum command.

@dengziming
Copy link
Member

Also, some MetadataQuorumCommandTest tests failed due to this change. FYI.

This is a very simple problem, we changed the output of the tool so the assertion in the test case failed, we only need to adjust the test case.

@hachikuji
Copy link
Contributor Author

hachikuji commented Aug 23, 2022

Just a general note, I'm repurposing this patch as a general cleanup of the new DescribeQuorum APIs. I changed my mind about HighWatermarkUpdateTimeMs. I think it can be inferred from the existing state, even if imperfectly. I don't feel like knowing the exact value adds that much.

@hachikuji hachikuji changed the title KAFKA-14142; Expose kraft high watermark update time in quorum command MINOR: A few cleanups for DescribeQuorum APIs Aug 23, 2022
Copy link
Member

@jsancio jsancio left a comment

Choose a reason for hiding this comment

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

Thanks for the changes @hachikuji . I still need to review the tests.

@jsancio jsancio added the 3.3 label Aug 23, 2022
Copy link
Member

@jsancio jsancio left a comment

Choose a reason for hiding this comment

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

LGTM thanks for the improvement @hachikuji

Copy link
Contributor

@showuon showuon left a comment

Choose a reason for hiding this comment

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

@hachikuji , thanks for explaining why leaderEpoch change to long. But there are 2 comments you didn't address, yet. Please take a look. Thanks.

DescribeQuorumResponseData.ReplicaState leaderState = voterStates.stream()
.filter(voterState -> voterState.replicaId() == localId)
.findFirst()
.orElseThrow(() -> new AssertionError(""));
Copy link
Contributor

Choose a reason for hiding this comment

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

Please update it and below. Thanks.

@hachikuji
Copy link
Contributor Author

@showuon Apologies for missing your comments. I pushed an update to address them. Thanks for reviewing!

@hachikuji hachikuji merged commit 5c52c61 into apache:trunk Aug 24, 2022
hachikuji added a commit that referenced this pull request Aug 24, 2022
A few small cleanups in the `DescribeQuorum` API and handling logic:

- Change field types in `QuorumInfo`:
  - `leaderId`: `Integer` -> `int`
  - `leaderEpoch`: `Integer` -> `long` (to allow for type expansion in the future)
  - `highWatermark`: `Long` -> `long`
- Use field names `lastFetchTimestamp` and `lastCaughtUpTimestamp` consistently
- Move construction of `DescribeQuorumResponseData.PartitionData` into `LeaderState`
- Consolidate fetch time/offset update logic into `LeaderState.ReplicaState.updateFollowerState`

Reviewers: Luke Chen <showuon@gmail.com>, José Armando García Sancio <jsancio@users.noreply.github.com>
@showuon
Copy link
Contributor

showuon commented Aug 25, 2022

Thanks @hachikuji , LGTM! Nice refactor!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants