Skip to content

KAFKA-12158: Better return type of RaftClient.scheduleAppend#10909

Merged
hachikuji merged 7 commits intoapache:trunkfrom
dengziming:KAFKA-12158-better-raft-append-return
Aug 2, 2021
Merged

KAFKA-12158: Better return type of RaftClient.scheduleAppend#10909
hachikuji merged 7 commits intoapache:trunkfrom
dengziming:KAFKA-12158-better-raft-append-return

Conversation

@dengziming
Copy link
Member

More detailed description of your change
It's not very convenient to return Long for RaftClient.scheduleAppend, in this PR we add a RaftAppendResult class to replace it.
I also found that we lack logic on append failure, for example, the ControllerWriteEvent won't check the result of raftClient.scheduleAppend, this should be fixed in a future PR.

Summary of testing strategy (including rationale)
QA

@dengziming dengziming force-pushed the KAFKA-12158-better-raft-append-return branch 2 times, most recently from 005201a to 4bab640 Compare June 20, 2021 09:30
@dengziming dengziming force-pushed the KAFKA-12158-better-raft-append-return branch from 4bab640 to b3e360d Compare June 29, 2021 05:35
@hachikuji hachikuji added the kraft label Jul 6, 2021
@hachikuji
Copy link
Contributor

cc @jsancio

@dengziming dengziming force-pushed the KAFKA-12158-better-raft-append-return branch from b3e360d to 21b8f09 Compare July 8, 2021 04:16
@dengziming dengziming force-pushed the KAFKA-12158-better-raft-append-return branch 3 times, most recently from bc12045 to e56546e Compare July 25, 2021 05:53
@dengziming dengziming force-pushed the KAFKA-12158-better-raft-append-return branch 2 times, most recently from 39d479c to e1131c9 Compare July 29, 2021 06:16
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 @dengziming

Copy link
Contributor

@hachikuji hachikuji 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 updates. Left a few suggestions.

@dengziming dengziming force-pushed the KAFKA-12158-better-raft-append-return branch from 2ace2d6 to b2c1cbb Compare July 30, 2021 14:17
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 chances, just a few minor suggestions.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it would be nice if we could consolidate NotLeaderException and FencedEpochException. In the context of scheduleAppend, they mean the same thing to the caller. They both say that the raft state has transitioned and the operation is no longer possible. I'm inclined to keep NotLeaderException and document that it covers both cases. What do you think?

Copy link
Member Author

Choose a reason for hiding this comment

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

Here I referred to the practices of KafkaController in which we have NOT_CONTROLLER and STALE_CONTROLLER_EPOCH for RPC errors, but here I also think it's better to consolidate NotLeaderException and FencedEpochException now.

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.

One observation, otherwise LGTM.

Copy link
Member

Choose a reason for hiding this comment

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

@dengziming @hachikuji What do you both think about making this consistent with RaftClient::resign? RaftClient::resign throws IllegalArgumentException when the passed epoch is greater than the current epoch. With this change KafkaRaftClient::schedule*Append throws NotLeaderException when the passed epoch is greater than the current epoch.

Maybe something like:

if (epoch > this.epoch) {
    throw new IllegalArgumentExcpetion("...");
} else if (epoch < this.epoch) {
    throw new NotLeaderException("...");
}

Copy link
Member Author

Choose a reason for hiding this comment

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

I think this is a good suggestion, only an epoch smaller than the current leader epoch should be treated as NotLeaderException.

@dengziming dengziming force-pushed the KAFKA-12158-better-raft-append-return branch from 2aa8e31 to fdf8768 Compare August 2, 2021 06:44
Copy link
Contributor

@hachikuji hachikuji left a comment

Choose a reason for hiding this comment

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

LGTM. Pushed one trivial change in ReplicatedCounter.

@hachikuji hachikuji merged commit b980ca8 into apache:trunk Aug 2, 2021
hachikuji pushed a commit that referenced this pull request Aug 2, 2021
This patch improves the return type for `scheduleAppend` and `scheduleAtomicAppend`. Previously we were using a `Long` value and using both `null` and `Long.MaxValue` to distinguish between different error cases. In this PR, we change the return type to `long` and only return a value if the append was accepted. For the error cases, we instead throw an exception. For this purpose, the patch introduces a couple new exception types: `BufferAllocationException` and `NotLeaderException`.

Reviewers: José Armando García Sancio <jsancio@users.noreply.github.com>, Jason Gustafson <jason@confluent.io>
xdgrulez pushed a commit to xdgrulez/kafka that referenced this pull request Dec 22, 2021
…10909)

This patch improves the return type for `scheduleAppend` and `scheduleAtomicAppend`. Previously we were using a `Long` value and using both `null` and `Long.MaxValue` to distinguish between different error cases. In this PR, we change the return type to `long` and only return a value if the append was accepted. For the error cases, we instead throw an exception. For this purpose, the patch introduces a couple new exception types: `BufferAllocationException` and `NotLeaderException`.

Reviewers: José Armando García Sancio <jsancio@users.noreply.github.com>, Jason Gustafson <jason@confluent.io>
@dengziming dengziming deleted the KAFKA-12158-better-raft-append-return branch October 8, 2022 11:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants