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

KAFKA-15182: Normalize source connector offsets before invoking SourceConnector::alterOffsets #14003

Merged
merged 4 commits into from Jul 14, 2023

Conversation

yashmayya
Copy link
Contributor

See discussion here

TLDR: When users attempt to externally modify source connector offsets via the PATCH /offsets endpoint (introduced in KIP-875), type mismatches can occur between offsets passed to SourceConnector::alterOffsets and the offsets that are retrieved by connectors / tasks via an instance of OffsetStorageReader after the offsets have been modified. In order to prevent this type mismatch that could lead to subtle bugs in connectors, we could serialize + deserialize the offsets using the worker's internal JSON converter before invoking SourceConnector::alterOffsets.

  • I've also added a small unit test, verified that the existing offsets API related integration tests are passing, and tested this patch out manually with the FileStreamSourceConnector.

Committer Checklist (excluded from commit message)

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

for (Map.Entry<Map<String, ?>, Map<String, ?>> entry : originalOffsets.entrySet()) {
OffsetUtils.validateFormat(entry.getKey());
OffsetUtils.validateFormat(entry.getValue());
byte[] serializedKey = internalKeyConverter.fromConnectData("", null, entry.getKey());
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This should be safe to do because the OffsetStorageReaderImpl also serializes the connector / task specified source partition before retrieving its corresponding source offset. The difference here is that there is an extra ser / deser hop although that shouldn't cause issues. So, for instance:

Map<String, Object> p1 = Collections.singletonMap("partition_key", 10);
Map<String, Object> p2 = Collections.singletonMap("partition_key", 10L);

ByteBuffer serializedP1 = ByteBuffer.wrap(converter.fromConnectData("", null, p1));
ByteBuffer serializedP2 = ByteBuffer.wrap(converter.fromConnectData("", null, p2));

assertTrue(serializedP1.equals(serializedP2));

Copy link
Contributor

@C0urante C0urante left a comment

Choose a reason for hiding this comment

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

Thanks Yash! Looks great, some minor thoughts and then this should be good to go.

Copy link
Contributor

@C0urante C0urante 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 Yash!

@C0urante C0urante merged commit 2b19b73 into apache:trunk Jul 14, 2023
1 check failed
Cerchie pushed a commit to Cerchie/kafka that referenced this pull request Jul 25, 2023
…eConnector::alterOffsets (apache#14003)

Reviewers: Chris Egerton <chrise@aiven.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
3 participants