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

[improve][client] PIP-407 Add newMessage with schema and transactions #23942

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

omarkj
Copy link
Contributor

@omarkj omarkj commented Feb 6, 2025

Pulsar Client allows callers to create messages with a schema or a transaction, but not both.

This commit adds a new method in the producer that allows callers to create a message with both a schema and transaction.

  • Dependencies (add or upgrade a dependency)
  • The public API
  • The schema
  • The default values of configurations
  • The threading model
  • The binary protocol
  • The REST endpoints
  • The admin CLI options
  • The metrics
  • Anything that affects deployment

Documentation

  • doc
  • doc-required
  • doc-not-needed
  • doc-complete

@github-actions github-actions bot added the doc Your PR contains doc changes, no matter whether the changes are in markdown or code files. label Feb 6, 2025
@dao-jun
Copy link
Member

dao-jun commented Feb 7, 2025

@omarkj
Copy link
Contributor Author

omarkj commented Feb 7, 2025

PIP PR filed here: #23950, will follow those guidelines by emailing out to the thread soon, etc.

Pulsar Client allows callers to create messages with a schema or a transaction, but
not both. This commit adds a new method in the producer that allows callers to create
a message with both a schema and transaction.
@omarkj omarkj force-pushed the producer-new-message-schema-txn branch from d77ad02 to 59dd60a Compare February 10, 2025 19:16
@omarkj omarkj requested a review from BewareMyPower February 10, 2025 22:35
@lhotari lhotari added this to the 4.1.0 milestone Feb 28, 2025
@lhotari lhotari added area/client type/feature The PR added a new feature or issue requested a new feature area/transaction labels Feb 28, 2025
Copy link
Member

@lhotari lhotari left a comment

Choose a reason for hiding this comment

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

LGTM

@lhotari
Copy link
Member

lhotari commented Feb 28, 2025

@BewareMyPower @dao-jun The PIP has been approved and merged, https://github.com/apache/pulsar/blob/master/pip/pip-407.md . PTAL and review

Comment on lines +147 to +148
<V> TypedMessageBuilder<V> newMessage(Schema<V> schema,
Transaction txn);
Copy link
Member

Choose a reason for hiding this comment

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

I have a concern about backward compatibility with this interface change. Adding a new method without a default implementation will break source compatibility for any custom implementations of the Producer interface.
While it might be uncommon for users to implement this interface directly, it could happen in testing scenarios or custom proxy implementations. Java source compatibility rules require all implementors to provide all interface methods.

We could address the source compatibility issue by adding a default implementation:

Suggested change
<V> TypedMessageBuilder<V> newMessage(Schema<V> schema,
Transaction txn);
default <V> TypedMessageBuilder<V> newMessage(Schema<V> schema, Transaction txn) {
// to retain source compatibilty of Producer interface for implementors of the Producer interface
throw new UnsupportedOperationException(
String.format("Method not implemented in: %s", getClass().getName()));
}

The benefit of making it source compatible is that we could also backport this change to the 4.0.x client without introducing breaking changes.

Copy link
Contributor

Choose a reason for hiding this comment

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

Do we really need to backport this change to 4.0.x client? LTS releases should not introduce such new APIs even if it does not break compatibility.

Copy link
Contributor

Choose a reason for hiding this comment

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

Once it's ported to 4.0.x, the forward compatibility will be broken. According to #15966, we should also guarantee the downgrade compatibility

Copy link
Contributor

Choose a reason for hiding this comment

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

Resolve this conversation. We can open another thread for the backport topic. For a new feature, adding a new non-default method should be accepted

Copy link
Member

Choose a reason for hiding this comment

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

Do we really need to backport this change to 4.0.x client? LTS releases should not introduce such new APIs even if it does not break compatibility.

This is a feature which would benefit existing 4.0.x users. By making the solution compatible without introducing breaking changes to the interface, we could deliver this feature to 4.0.x users immediately. Obviously there's the question whether we need to do this or not.

Copy link
Contributor

Choose a reason for hiding this comment

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

I reviewed the PIP-175 and LTS releases recently again. PIP-175 mainly talked about the server side compatibility. Regarding the client side,

Note that this consideration is separate from the compatibility between clients and brokers, where we never break compatibility. The oldest available Pulsar client can still talk with the newest Pulsar broker, and vice versa, a new client, will be perfectly fine with an older broker (except the new features won't be working).

From the existing definitions, it's acceptable to cherry-pick this client-side feature for 4.0.x. It does not break any compatibility: with this new API, the latest 4.0.x client can still access an older broker (that supports transaction).

The only question is the source compatibility you mentioned by making it default. Could you show a concrete example for how could a non-default new method affect users?

@codecov-commenter
Copy link

codecov-commenter commented Mar 3, 2025

Codecov Report

Attention: Patch coverage is 66.66667% with 1 line in your changes missing coverage. Please review.

Project coverage is 74.21%. Comparing base (bbc6224) to head (c9b0771).
Report is 946 commits behind head on master.

Files with missing lines Patch % Lines
...va/org/apache/pulsar/client/impl/ProducerBase.java 66.66% 0 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff              @@
##             master   #23942      +/-   ##
============================================
+ Coverage     73.57%   74.21%   +0.64%     
+ Complexity    32624    32392     -232     
============================================
  Files          1877     1861      -16     
  Lines        139502   144173    +4671     
  Branches      15299    16421    +1122     
============================================
+ Hits         102638   107001    +4363     
+ Misses        28908    28737     -171     
- Partials       7956     8435     +479     
Flag Coverage Δ
inttests 26.74% <0.00%> (+2.15%) ⬆️
systests 23.11% <0.00%> (-1.22%) ⬇️
unittests 73.72% <66.66%> (+0.87%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...va/org/apache/pulsar/client/impl/ProducerBase.java 81.48% <66.66%> (+2.63%) ⬆️

... and 1052 files with indirect coverage changes

@lhotari lhotari changed the title [improve][client] Add newMessage with schema and transactions [improve][client] PIP-407 Add newMessage with schema and transactions Mar 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/client area/transaction doc Your PR contains doc changes, no matter whether the changes are in markdown or code files. ready-to-test type/feature The PR added a new feature or issue requested a new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants