Skip to content

Comments

MINOR: Improve ValueTimestampHeader Serdes#21515

Open
mjsax wants to merge 2 commits intoapache:trunkfrom
mjsax:minor-improve-valuetimestampheader-serdes
Open

MINOR: Improve ValueTimestampHeader Serdes#21515
mjsax wants to merge 2 commits intoapache:trunkfrom
mjsax:minor-improve-valuetimestampheader-serdes

Conversation

@mjsax
Copy link
Member

@mjsax mjsax commented Feb 19, 2026

This PR disallows to pass in Headers objects into serialize() and
deserializer() to ensure we don't accidentally introduce bugs in our own
code.

It also fixes a small bug, and now correctly passed Headers into the
value deserizlier.

Co-authored-by: Uladzislau Blok blokv75@gmail.com Reviewers: Alieh
Saeedi asaeedi@confluent.io, TengYao Chi frankvicky@apache.org

@mjsax mjsax added the streams label Feb 19, 2026
@github-actions github-actions bot added the small Small PRs label Feb 19, 2026

@Override
public ValueTimestampHeaders<V> deserialize(final String topic, final Headers headers, final byte[] valueTimestampHeaders) {
throw new UnsupportedOperationException("Headers are encoded inside `valueTimestampHeaders` byte[] array and cannot be passed as parameter. Use `deserialize(String topic, byte[] valueTimestampHeaders)` instead.");
Copy link
Member Author

Choose a reason for hiding this comment

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

Frankly, I am not 100% if this is a too restrictive check?

We could also check if header == null || headers.toArray().size == 0 and allow the call for this case? Same for the serializer. Thoughts?

Copy link
Contributor

@aliehsaeedii aliehsaeedii left a comment

Choose a reason for hiding this comment

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

What is the worries here? 1) We call this method while the passed headers is different with the headers encoded in valueTimestampHeaders? or 2) the general ambiguty of having two headers?
if we are more concerned with 2nd issue, we must be explicit about API misuse and throw exception anyway, but here we generally are breaking Liskov Substitution Principle.

@mjsax
Copy link
Member Author

mjsax commented Feb 19, 2026

The concern is both of the points you mentioned. -- And yes, I agree that it's not ideal... But it might be "ok-ish", given that these classes an KS internal only?

@aliehsaeedii
Copy link
Contributor

The concern is both of the points you mentioned. -- And yes, I agree that it's not ideal... But it might be "ok-ish", given that these classes an KS internal only?

Ok, so let’s go ahead and be strict and throw an exception anyway, since we know this method should never be called. Thanks for being so thorough.

Copy link
Contributor

@frankvicky frankvicky left a comment

Choose a reason for hiding this comment

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

This changes make sense but I wondering that we already have a default impl in the interface which will invoke deserialize(String, Object). Do we need this override?

    default T deserialize(String topic, Headers headers, byte[] data) {
        return deserialize(topic, data);
    }

@mjsax
Copy link
Member Author

mjsax commented Feb 20, 2026

@frankvicky -- You are right; technically we don't need the overload given the default impl. The idea was to make it explicit on the class itself, that both methods are not supported (also guards us for the case, that the default impl would get changed; even if I don't expect this to happen as would raise backward compatibility questions).

This PR disallows to pass in Headers objects into serialize() and deserializer() to ensure we don't accidentally introduce bugs in our own code.
@mjsax mjsax force-pushed the minor-improve-valuetimestampheader-serdes branch from 7ae9de0 to aa7e381 Compare February 20, 2026 23:20
final byte[] bytes = readBytes(buffer, buffer.remaining());

return deserializer.deserialize("", bytes);
return deserializer.deserialize("", headers, bytes);
Copy link
Member Author

Choose a reason for hiding this comment

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

One more fix... @UladzislauBlok pointed me to it! Great find.

Base on this, I am wondering about "lazy header deserialization" idea... Left a comment on https://issues.apache.org/jira/browse/KAFKA-20155

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