Repository navigation
Allow ability to specify retain key ordering in functions #7647
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -138,11 +138,16 @@ public static FunctionDetails convert(FunctionConfig functionConfig, ClassLoader | |
| }); | ||
| } | ||
|
|
||
| // Set subscription type based on ordering and EFFECTIVELY_ONCE semantics | ||
| Function.SubscriptionType subType = ((functionConfig.getRetainOrdering() != null && functionConfig.getRetainOrdering()) | ||
| || FunctionConfig.ProcessingGuarantees.EFFECTIVELY_ONCE.equals(functionConfig.getProcessingGuarantees())) | ||
| ? Function.SubscriptionType.FAILOVER | ||
| : Function.SubscriptionType.SHARED; | ||
| // Set subscription type | ||
| Function.SubscriptionType subType; | ||
| if ((functionConfig.getRetainOrdering() != null && functionConfig.getRetainOrdering()) | ||
| || FunctionConfig.ProcessingGuarantees.EFFECTIVELY_ONCE.equals(functionConfig.getProcessingGuarantees())) { | ||
| subType = Function.SubscriptionType.FAILOVER; | ||
| } else if (functionConfig.getRetainKeyOrdering() != null && functionConfig.getRetainKeyOrdering()) { | ||
| subType = Function.SubscriptionType.KEY_SHARED; | ||
| } else { | ||
| subType = Function.SubscriptionType.SHARED; | ||
| } | ||
| sourceSpecBuilder.setSubscriptionType(subType); | ||
|
|
||
| if (isNotBlank(functionConfig.getSubName())) { | ||
|
|
@@ -214,6 +219,12 @@ public static FunctionDetails convert(FunctionConfig functionConfig, ClassLoader | |
| functionDetailsBuilder.setProcessingGuarantees( | ||
| FunctionCommon.convertProcessingGuarantee(functionConfig.getProcessingGuarantees())); | ||
| } | ||
| if (functionConfig.getRetainKeyOrdering() != null) { | ||
| functionDetailsBuilder.setRetainKeyOrdering(functionConfig.getRetainKeyOrdering()); | ||
| } | ||
| if (functionConfig.getRetainOrdering() != null) { | ||
| functionDetailsBuilder.setRetainOrdering(functionConfig.getRetainOrdering()); | ||
| } | ||
|
|
||
| if (functionConfig.getMaxMessageRetries() != null && functionConfig.getMaxMessageRetries() >= 0) { | ||
| Function.RetryDetails.Builder retryBuilder = Function.RetryDetails.newBuilder(); | ||
|
|
@@ -315,13 +326,9 @@ public static FunctionConfig convertFromDetails(FunctionDetails functionDetails) | |
| if (!isEmpty(functionDetails.getSource().getSubscriptionName())) { | ||
| functionConfig.setSubName(functionDetails.getSource().getSubscriptionName()); | ||
| } | ||
| if (functionDetails.getSource().getSubscriptionType() == Function.SubscriptionType.FAILOVER) { | ||
| functionConfig.setRetainOrdering(true); | ||
| functionConfig.setProcessingGuarantees(FunctionConfig.ProcessingGuarantees.EFFECTIVELY_ONCE); | ||
| } else { | ||
| functionConfig.setRetainOrdering(false); | ||
| functionConfig.setProcessingGuarantees(FunctionConfig.ProcessingGuarantees.ATLEAST_ONCE); | ||
| } | ||
| functionConfig.setRetainOrdering(functionDetails.getRetainOrdering()); | ||
| functionConfig.setRetainKeyOrdering(functionDetails.getRetainKeyOrdering()); | ||
|
|
||
| functionConfig.setCleanupSubscription(functionDetails.getSource().getCleanupSubscription()); | ||
| functionConfig.setAutoAck(functionDetails.getAutoAck()); | ||
| if (functionDetails.getSource().getTimeoutMs() != 0) { | ||
|
|
@@ -341,7 +348,6 @@ public static FunctionConfig convertFromDetails(FunctionDetails functionDetails) | |
| } | ||
| functionConfig.setForwardSourceMessageProperty(functionDetails.getSink().getForwardSourceMessageProperty()); | ||
| functionConfig.setRuntime(FunctionCommon.convertRuntime(functionDetails.getRuntime())); | ||
| functionConfig.setProcessingGuarantees(FunctionCommon.convertProcessingGuarantee(functionDetails.getProcessingGuarantees())); | ||
| if (functionDetails.hasRetryDetails()) { | ||
| functionConfig.setMaxMessageRetries(functionDetails.getRetryDetails().getMaxMessageRetries()); | ||
| if (!isEmpty(functionDetails.getRetryDetails().getDeadLetterTopic())) { | ||
|
|
@@ -532,6 +538,10 @@ private static void doPythonChecks(FunctionConfig functionConfig) { | |
| if (functionConfig.getMaxMessageRetries() != null && functionConfig.getMaxMessageRetries() >= 0) { | ||
| throw new IllegalArgumentException("Message retries not yet supported in python"); | ||
| } | ||
|
|
||
| if (functionConfig.getRetainKeyOrdering() != null && functionConfig.getRetainKeyOrdering()) { | ||
| throw new IllegalArgumentException("Retain Key Orderering not yet supported in python"); | ||
| } | ||
| } | ||
|
|
||
| private static void doGolangChecks(FunctionConfig functionConfig) { | ||
|
|
@@ -546,6 +556,10 @@ private static void doGolangChecks(FunctionConfig functionConfig) { | |
| if (functionConfig.getMaxMessageRetries() != null && functionConfig.getMaxMessageRetries() >= 0) { | ||
| throw new IllegalArgumentException("Message retries not yet supported in Go function"); | ||
| } | ||
|
|
||
| if (functionConfig.getRetainKeyOrdering() != null && functionConfig.getRetainKeyOrdering()) { | ||
| throw new IllegalArgumentException("Retain Key Orderering not yet supported in Go function"); | ||
| } | ||
| } | ||
|
|
||
| private static void verifyNoTopicClash(Collection<String> inputTopics, String outputTopic) throws IllegalArgumentException { | ||
|
|
@@ -639,6 +653,16 @@ private static void doCommonChecks(FunctionConfig functionConfig) { | |
| if ((functionConfig.getMaxMessageRetries() == null || functionConfig.getMaxMessageRetries() < 0) && !org.apache.commons.lang3.StringUtils.isEmpty(functionConfig.getDeadLetterTopic())) { | ||
| throw new IllegalArgumentException("Dead Letter Topic specified, however max retries is set to infinity"); | ||
| } | ||
| if (functionConfig.getRetainKeyOrdering() != null | ||
| && functionConfig.getRetainKeyOrdering() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you also check whether retain ordering is set? |
||
| && functionConfig.getProcessingGuarantees() != null | ||
| && functionConfig.getProcessingGuarantees() == FunctionConfig.ProcessingGuarantees.EFFECTIVELY_ONCE) { | ||
| throw new IllegalArgumentException("When effectively once processing guarantee is specified, retain Key ordering cannot be set"); | ||
| } | ||
| if (functionConfig.getRetainKeyOrdering() != null && functionConfig.getRetainKeyOrdering() | ||
| && functionConfig.getRetainOrdering() != null && functionConfig.getRetainOrdering()) { | ||
| throw new IllegalArgumentException("Only one of retain ordering or retain key ordering can be set"); | ||
| } | ||
|
|
||
| if (!isEmpty(functionConfig.getPy()) && !org.apache.pulsar.common.functions.Utils.isFunctionPackageUrlSupported(functionConfig.getPy()) | ||
| && functionConfig.getPy().startsWith(BUILTIN)) { | ||
|
|
@@ -804,6 +828,9 @@ public static FunctionConfig validateUpdate(FunctionConfig existingConfig, Funct | |
| if (newConfig.getRetainOrdering() != null && !newConfig.getRetainOrdering().equals(existingConfig.getRetainOrdering())) { | ||
| throw new IllegalArgumentException("Retain Ordering cannot be altered"); | ||
| } | ||
| if (newConfig.getRetainKeyOrdering() != null && !newConfig.getRetainKeyOrdering().equals(existingConfig.getRetainKeyOrdering())) { | ||
| throw new IllegalArgumentException("Retain Key Ordering cannot be altered"); | ||
| } | ||
| if (!StringUtils.isEmpty(newConfig.getOutput())) { | ||
| mergedConfig.setOutput(newConfig.getOutput()); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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