Skip to content

KAFKA-14712: Produce correct error msg with correct metadataversion#13773

Merged
showuon merged 10 commits into
apache:trunkfrom
Owen-CH-Leung:KAFKA-14712
Jul 24, 2023
Merged

KAFKA-14712: Produce correct error msg with correct metadataversion#13773
showuon merged 10 commits into
apache:trunkfrom
Owen-CH-Leung:KAFKA-14712

Conversation

@Owen-CH-Leung

Copy link
Copy Markdown
Contributor

Fix the confusing error message

Committer Checklist (excluded from commit message)

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

@Owen-CH-Leung
Owen-CH-Leung marked this pull request as ready for review May 27, 2023 13:04
@Owen-CH-Leung

Copy link
Copy Markdown
Contributor Author

@mumrah can I ask for your review ? Thanks

@showuon

showuon commented Jun 15, 2023

Copy link
Copy Markdown
Member

@Owen-CH-Leung , thanks for the patch, could you add tests for this change?

@Owen-CH-Leung

Copy link
Copy Markdown
Contributor Author

b4dd894

@showuon Thanks a lot for your feedback. I've added tests to test the handleLoss function. The issue as described in KAFKA-14712 should go away now.

@divijvaidya
divijvaidya requested a review from mumrah June 15, 2023 09:09

@mumrah mumrah left a comment

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.

Hi @Owen-CH-Leung, thanks for the patch! I've made a few suggestions in the PR.

public final class ImageWriterOptions {
public static class Builder {
private MetadataVersion metadataVersion;
private MetadataVersion orgMetadataVersion;

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.

How about "requestedMetadataVersion" ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks. Refactored to requestedMetadataVersion

setOrgMetadataVersion(metadataVersion);
setRawMetadataVersion(MetadataVersion.MINIMUM_KRAFT_VERSION);
} else {
setRawMetadataVersion(metadataVersion);

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.

Let's set both metadata versions here as well so we don't have to deal with a null later

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sure. I've set both fields in this function call. Note that I've also modified the ImageDowngradeTest to use the setMetadataVersion instead of setRawMetadataVersion (Maybe we should change setRawMetadataVersion to private` also ?)

@Owen-CH-Leung
Owen-CH-Leung requested a review from mumrah June 16, 2023 03:00
@Owen-CH-Leung

Owen-CH-Leung commented Jun 16, 2023

Copy link
Copy Markdown
Contributor Author

@mumrah @showuon I saw there're a few unit test failed in the CI job (e.g. MirrorConnectorsIntegrationExactlyOnceTest.testReplication(), but I don't think it's related to my changes ? Can someone take a look and give me some hints as in how I can get a green CI ? Thanks a lot

@showuon

showuon commented Jun 21, 2023

Copy link
Copy Markdown
Member

@Owen-CH-Leung , please try to rebase to the latest trunk branch, the failed testReplication should be fixed. Thanks.

@Owen-CH-Leung

Copy link
Copy Markdown
Contributor Author

@showuon Thanks. I just rebase to the latest trunk branch. But I saw there're still tests failed for core:integrationTest


[2023-06-21T15:53:46.873Z]     org.apache.kafka.common.errors.TimeoutException: Timeout expired after 60000ms while awaiting InitProducerId```

@showuon showuon left a comment

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.

@Owen-CH-Leung , thanks for the PR. Left a comment to the test.

Comment on lines +64 to +78
for (int i = MetadataVersion.MINIMUM_KRAFT_VERSION.ordinal();
i < MetadataVersion.VERSIONS.length;
i++) {
ByteArrayOutputStream outContent = new ByteArrayOutputStream();
MetadataVersion version = MetadataVersion.VERSIONS[i];
ImageWriterOptions options = new ImageWriterOptions.Builder()
.setMetadataVersion(version)
.setLossHandler(customLossHandler)
.build();
System.setOut(new PrintStream(outContent));
options.handleLoss(expectedMessage);
System.setOut(originalOut);
String formattedMessage = String.format("Metadata has been lost because the following could not be represented in metadata version %s: %s", version, expectedMessage);
assertEquals(formattedMessage, outContent.toString().trim());
}

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.

I think we can simplify this test as this without relying System.out:

for (int i = MetadataVersion.MINIMUM_KRAFT_VERSION.ordinal();
             i < MetadataVersion.VERSIONS.length;
             i++) {
            
            MetadataVersion version = MetadataVersion.VERSIONS[i];
            String formattedMessage = String.format("Metadata has been lost because the following could not be represented in metadata version %s: %s", version, expectedMessage);
            Consumer<UnwritableMetadataException> customLossHandler = e -> {
                assertEquals(formattedMessage, e.getMessage());
            };
            ImageWriterOptions options = new ImageWriterOptions.Builder()
                    .setMetadataVersion(version)
                    .setLossHandler(customLossHandler)
                    .build();
            options.handleLoss(expectedMessage);
}

WDYT?

@Owen-CH-Leung Owen-CH-Leung Jul 17, 2023

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@showuon Thanks! Yes it's a lot cleaner. I've adopted your suggestion.

@Owen-CH-Leung
Owen-CH-Leung requested a review from showuon July 17, 2023 11:04

@showuon showuon left a comment

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.

LGTM! Just a minor comment.

Comment on lines +65 to +67
Consumer<UnwritableMetadataException> customLossHandler = e -> {
assertEquals(formattedMessage, e.getMessage());
};

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.

nit: no need curly brackets here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

ahh yes. Removed it

@showuon

showuon commented Jul 18, 2023

Copy link
Copy Markdown
Member

@mumrah , do you want to have another look? I'm going to merge this later this week if no other comments. Thanks.

@showuon

showuon commented Jul 24, 2023

Copy link
Copy Markdown
Member

Failed tests are unrelated:

    Build / JDK 17 and Scala 2.13 / org.apache.kafka.connect.mirror.integration.MirrorConnectorsIntegrationExactlyOnceTest.testOffsetTranslationBehindReplicationFlow()
    Build / JDK 17 and Scala 2.13 / kafka.server.KafkaServerKRaftRegistrationTest.[1] Type=ZK, Name=testRegisterZkBrokerInKraft, MetadataVersion=3.4-IV0, Security=PLAINTEXT
    Build / JDK 11 and Scala 2.13 / org.apache.kafka.connect.mirror.integration.MirrorConnectorsIntegrationExactlyOnceTest.testOffsetTranslationBehindReplicationFlow()
    Build / JDK 11 and Scala 2.13 / org.apache.kafka.connect.mirror.integration.MirrorConnectorsIntegrationExactlyOnceTest.testOffsetTranslationBehindReplicationFlow()
    Build / JDK 11 and Scala 2.13 / org.apache.kafka.connect.mirror.integration.MirrorConnectorsWithCustomForwardingAdminIntegrationTest.testSyncTopicConfigs()
    Build / JDK 20 and Scala 2.13 / kafka.log.remote.RemoteIndexCacheTest.testCacheEntryExpiry()
    Build / JDK 20 and Scala 2.13 / org.apache.kafka.trogdor.coordinator.CoordinatorTest.testTaskRequestWithOldStartMsGetsUpdated()

@showuon
showuon merged commit 4981fa9 into apache:trunk Jul 24, 2023
Cerchie pushed a commit to Cerchie/kafka that referenced this pull request Jul 25, 2023
…pache#13773)

Fix the confusing error message in ImageWriterOptions

Reviewers: Luke Chen <showuon@gmail.com>, David Arthur <mumrah@gmail.com>
jeqo pushed a commit to aiven/kafka that referenced this pull request Aug 15, 2023
…pache#13773)

Fix the confusing error message in ImageWriterOptions

Reviewers: Luke Chen <showuon@gmail.com>, David Arthur <mumrah@gmail.com>
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