Skip to content

Allow ability to specify retain key ordering in functions - #7647

Merged
srkukarni merged 3 commits into
apache:masterfrom
srkukarni:key_shared_function
Jul 24, 2020
Merged

srkukarni merged 3 commits into
apache:masterfrom
srkukarni:key_shared_function

Conversation

@srkukarni

Copy link
Copy Markdown
Contributor

(If this PR fixes a github issue, please add Fixes #<xyz>.)

Fixes #

(or if this PR is one task of a github issue, please add Master Issue: #<xyz> to link to the master issue.)

Master Issue: #

Motivation

Just like retainOrdering, sometimes applications want to retain ordering over the message keys. This pr adds support to that.

Modifications

Describe the modifications you've done.

Verifying this change

  • Make sure that the change passes the CI checks.

(Please pick either of the following options)

This change is a trivial rework / code cleanup without any test coverage.

(or)

This change is already covered by existing tests, such as (please describe tests).

(or)

This change added tests and can be verified as follows:

(example:)

  • Added integration tests for end-to-end deployment with large payloads (10MB)
  • Extended integration test for recovery after broker failure

Does this pull request potentially affect one of the following parts:

If yes was chosen, please highlight the changes

  • Dependencies (does it add or upgrade a dependency): (yes / no)
  • The public API: (yes / no)
  • The schema: (yes / no / don't know)
  • The default values of configurations: (yes / no)
  • The wire protocol: (yes / no)
  • The rest endpoints: (yes / no)
  • The admin cli options: (yes / no)
  • Anything that affects deployment: (yes / no / don't know)

Documentation

  • Does this pull request introduce a new feature? (yes / no)
  • If yes, how is the feature documented? (not applicable / docs / JavaDocs / not documented)
  • If a feature is not applicable for documentation, explain why?
  • If a feature is not documented yet in this PR, please create a followup issue for adding the documentation

@srkukarni srkukarni added this to the 2.7.0 milestone Jul 23, 2020
@srkukarni
srkukarni requested a review from jerrypeng July 23, 2020 18:50
@srkukarni srkukarni self-assigned this Jul 23, 2020
functionConfig.setRetainOrdering(true);
functionConfig.setRetainKeyOrdering(false);
functionConfig.setProcessingGuarantees(FunctionConfig.ProcessingGuarantees.EFFECTIVELY_ONCE);
} else if (functionDetails.getSource().getSubscriptionType() == Function.SubscriptionType.KEY_SHARED) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We also need to do this in SinkConfigUtils

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.

That can be added later.

} else if (functionDetails.getSource().getSubscriptionType() == Function.SubscriptionType.KEY_SHARED) {
functionConfig.setRetainOrdering(false);
functionConfig.setRetainKeyOrdering(true);
functionConfig.setProcessingGuarantees(FunctionConfig.ProcessingGuarantees.ATLEAST_ONCE);

@jerrypeng jerrypeng Jul 23, 2020 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why are we assuming ATLEAST_ONCE here? A user can set the processing guarantee to be at most once and still set the retain ordering to be true

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.

Yes. Even the existing code is broken in that regard. I will fix that

Function.SubscriptionType subType = ((functionConfig.getRetainOrdering() != null && functionConfig.getRetainOrdering())
|| FunctionConfig.ProcessingGuarantees.EFFECTIVELY_ONCE.equals(functionConfig.getProcessingGuarantees()))
? Function.SubscriptionType.FAILOVER
: (functionConfig.getRetainKeyOrdering() != null && functionConfig.getRetainKeyOrdering())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we re-organize this giant conditional statement to be more readable?

if (effectively-once) {
subType = Failover
} else if (retain order) {
subType = failover
} else if (retain key order) {
subType = shared_key
} else {
subType = shared
}

throw new IllegalArgumentException("Dead Letter Topic specified, however max retries is set to infinity");
}
if (functionConfig.getRetainKeyOrdering() != null
&& functionConfig.getRetainKeyOrdering()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I would remove this stanza. We should return an error if the retain order or retain key ordering is set at all

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can you also check whether retain ordering is set?

private String logTopic;
private ProcessingGuarantees processingGuarantees;
private Boolean retainOrdering;
private Boolean retainKeyOrdering;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we add some comments here for retainOrdering and retainKeyOrdering so people understand what they do and what the difference between the two is?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

also need to add this for SinkConfig

@@ -317,9 +319,15 @@ public static FunctionConfig convertFromDetails(FunctionDetails functionDetails)
}
if (functionDetails.getSource().getSubscriptionType() == Function.SubscriptionType.FAILOVER) {

@jerrypeng jerrypeng Jul 23, 2020 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This whole conditional statement doesn't seem right to me. Why are se setting the processing guarantee by looking at what the subscription is? We already setting the processing guarantee in a previous line:

https://github.com/apache/pulsar/pull/7647/files#diff-239e167c18ea8591c85432948ab5040aL297

@srkukarni

Copy link
Copy Markdown
Contributor Author

@jerrypeng addressed your comments. PTAL

@srkukarni
srkukarni merged commit ff4c3f6 into apache:master Jul 24, 2020
@srkukarni
srkukarni deleted the key_shared_function branch July 24, 2020 20:31
lbenc135 pushed a commit to lbenc135/pulsar that referenced this pull request Jul 25, 2020
* Allow ability to specify retain key ordering in functions

* Address comments

Co-authored-by: Sanjeev Kulkarni <[email protected]>
(cherry picked from commit ff4c3f6)
jerrypeng pushed a commit to jerrypeng/incubator-pulsar that referenced this pull request Jul 28, 2020
* Allow ability to specify retain key ordering in functions

* Address comments

Co-authored-by: Sanjeev Kulkarni <[email protected]>
huangdx0726 pushed a commit to huangdx0726/pulsar that referenced this pull request Aug 24, 2020
* Allow ability to specify retain key ordering in functions

* Address comments

Co-authored-by: Sanjeev Kulkarni <[email protected]>
sijie pushed a commit that referenced this pull request Dec 11, 2020
Signed-off-by: xiaolong.ran <[email protected]>

Fixes #6527 

### Motivation

We already support `key_shared` mode on Pulsar Functions in #7647, However, this option is not exposed in the command line parameters, so users currently cannot use this function.

### Modifications

In this pull request, we expose this cmd flag of `--retain-key-ordering` and add the docs for this.

### Verifying this change

The original test can cover this option, so, in this change, no relevant code is added
shyamvyas5 pushed a commit to pandio-com/pulsar that referenced this pull request Sep 14, 2021
Signed-off-by: xiaolong.ran <[email protected]>

Fixes apache#6527

### Motivation

We already support `key_shared` mode on Pulsar Functions in apache#7647, However, this option is not exposed in the command line parameters, so users currently cannot use this function.

### Modifications

In this pull request, we expose this cmd flag of `--retain-key-ordering` and add the docs for this.

### Verifying this change

The original test can cover this option, so, in this change, no relevant code is added

(cherry picked from commit 8150da8)
shyamvyas5 pushed a commit to pandio-com/pulsar that referenced this pull request Dec 20, 2021
Signed-off-by: xiaolong.ran <[email protected]>

Fixes apache#6527

### Motivation

We already support `key_shared` mode on Pulsar Functions in apache#7647, However, this option is not exposed in the command line parameters, so users currently cannot use this function.

### Modifications

In this pull request, we expose this cmd flag of `--retain-key-ordering` and add the docs for this.

### Verifying this change

The original test can cover this option, so, in this change, no relevant code is added

(cherry picked from commit 8150da8)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants