Skip to content

KAFKA-10864: Convert end txn marker schema to use auto-generated protocol#9766

Merged
chia7712 merged 5 commits intoapache:trunkfrom
dengziming:end-txn-auto-protocol
Mar 5, 2025
Merged

KAFKA-10864: Convert end txn marker schema to use auto-generated protocol#9766
chia7712 merged 5 commits intoapache:trunkfrom
dengziming:end-txn-auto-protocol

Conversation

@dengziming
Copy link
Copy Markdown
Member

@dengziming dengziming commented Dec 18, 2020

More detailed description of your change

  1. Convert end txn marker schema to use auto-generated protocol EndTxnMarker
  2. substitute CURRENT_END_TXN_MARKER_VALUE_SIZE with an endTnxMarkerValueSize method since the size is accumulated from EndTxnMarker.
  3. add buffer to EndTransactionMarker to avoid twice compute from serializeValue and endTnxMarkerValueSize.
  4. flexibleVersions is set to none.

Summary of testing strategy (including rationale)
A unit test to verify serialize and deserialize

Committer Checklist (excluded from commit message)

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

Copy link
Copy Markdown

@abbccdda abbccdda 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, one high level question I have is that whether the new auto generated protocol format is exactly the same as old hard-coded schema format, since this field is used inter-broker. Could you write a test to prove that they could translate between each other?

Comment thread clients/src/main/java/org/apache/kafka/common/record/MemoryRecords.java Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Add a comment for the field. Also do you think we need flexible version support here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Firstly I tried to use flexible version here, but it's not the same as the old hard-coded schema format. Could we bump the version and support flexible version from version 1 ?

@dengziming
Copy link
Copy Markdown
Member Author

Thanks for the PR, one high level question I have is that whether the new auto generated protocol format is exactly the same as old hard-coded schema format, since this field is used inter-broker. Could you write a test to prove that they could translate between each other?

Thank you, I tested that the 2 schemas could translate between each other locally, now I add the code to EndTransactionMarkerTest.

@dengziming dengziming requested a review from abbccdda January 5, 2021 10:36
@dengziming dengziming force-pushed the end-txn-auto-protocol branch from 62c0038 to fe6b884 Compare January 18, 2021 12:59
@dengziming
Copy link
Copy Markdown
Member Author

ping @abbccdda , Also ping @chia7712 to have a look.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Dec 1, 2024

This PR is being marked as stale since it has not had any activity in 90 days. If you
would like to keep this PR alive, please leave a comment asking for a review. If the PR has
merge conflicts, update it with the latest from the base branch.

If you are having difficulty finding a reviewer, please reach out on the [mailing list](https://kafka.apache.org/contact).

If this PR is no longer valid or desired, please feel free to close it. If no activity occurs in the next 30 days, it will be automatically closed.

@github-actions github-actions Bot added the stale Stale PRs label Dec 1, 2024
@chia7712
Copy link
Copy Markdown
Member

chia7712 commented Dec 1, 2024

@dengziming could you please fix the conflicts?

@dengziming
Copy link
Copy Markdown
Member Author

Hi, @chia7712 , Thanks for noticing this PR, I have rebased on trunk and the test looks fine.

We have a controversy here that in the past the length of EndTransactionMarker is hard-coded to 6, however it is dynamically acquired from it's serialized ByteBuffer, so I stored buffer of a EndTransactionMarker when it's created, this will add some state but reduce one calculation.

Another alternative is to change MemoryRecords.writeEndTransactionalMarker signature to directly receive (xxx..., ByteBuffer markerBuffer, ControlRecordType markerType) as the below screenshot, but this involves more refactor, WDYT.

image

@github-actions github-actions Bot removed the stale Stale PRs label Dec 23, 2024
Copy link
Copy Markdown
Member

@chia7712 chia7712 left a comment

Choose a reason for hiding this comment

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

@dengziming sorry for delay review :(

one small comment is left. PTAL

@dengziming dengziming force-pushed the end-txn-auto-protocol branch from 00e9aae to be75709 Compare February 27, 2025 09:23
Copy link
Copy Markdown
Member

@chia7712 chia7712 left a comment

Choose a reason for hiding this comment

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

@dengziming thanks for this patch!

public class EndTransactionMarkerTest {

// Old hard-coded schema, used to validate old hard-coded schema format is exactly the same as new auto generated protocol format
private Schema v0Schema = new Schema(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

could you please add final?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

done.


int coordinatorEpoch = value.getInt(2);
return new EndTransactionMarker(type, coordinatorEpoch);
public int endTxnMarkerValueSize() {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could you please add unit test for this method?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes, it's good to test it since it's public.

Copy link
Copy Markdown
Member

@chia7712 chia7712 left a comment

Choose a reason for hiding this comment

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

@dengziming thanks for this patch, overall LGTM and one last comment is left

log.debug("Received end transaction marker value version {}. Parsing as version {}", version,
CURRENT_END_TXN_MARKER_VERSION);
EndTxnMarker.HIGHEST_SUPPORTED_VERSION);
EndTxnMarker marker = new EndTxnMarker(new ByteBufferAccessor(value), version);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

According to the debug message, we should use EndTxnMarker.HIGHEST_SUPPORTED_VERSION instead of version to parse it as EndTxnMarker.HIGHEST_SUPPORTED_VERSION, right?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Oh, you are so careful about this, though it seems obscure, I agree with you that we should indeed use EndTxnMarker.HIGHEST_SUPPORTED_VERSION.

@chia7712 chia7712 merged commit 1bfa4cd into apache:trunk Mar 5, 2025
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