Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,11 @@ public enum Runtime {
private String outputSerdeClassName;
private String logTopic;
private ProcessingGuarantees processingGuarantees;
// Do we want function instances to process data in the same order as in the input topics
// This essentially means that every partition of input topic is consumed by only one instance
private Boolean retainOrdering;
// Do we want the same function instance to process all data keyed by the input topic's message key
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

private Boolean forwardSourceMessageProperty;
private Map<String, Object> userConfig;
// This is a map of secretName(aka how the secret is going to be
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,9 @@ private void setupInput(ContextImpl contextImpl) throws Exception {
case FAILOVER:
pulsarSourceConfig.setSubscriptionType(SubscriptionType.Failover);
break;
case KEY_SHARED:
pulsarSourceConfig.setSubscriptionType(SubscriptionType.Key_Shared);
break;
default:
pulsarSourceConfig.setSubscriptionType(SubscriptionType.Shared);
break;
Expand Down
3 changes: 3 additions & 0 deletions pulsar-functions/proto/src/main/proto/Function.proto
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ enum ProcessingGuarantees {
enum SubscriptionType {
SHARED = 0;
FAILOVER = 1;
KEY_SHARED = 2;
}

enum SubscriptionPosition {
Expand Down Expand Up @@ -84,6 +85,8 @@ message FunctionDetails {
/* If specified, this will refer to an archive that is
* already present in the server */
string builtin = 20;
bool retainOrdering = 21;
bool retainKeyOrdering = 22;
}

message ConsumerSpec {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())) {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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) {
Expand All @@ -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())) {
Expand Down Expand Up @@ -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) {
Expand All @@ -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 {
Expand Down Expand Up @@ -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()

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?

&& 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)) {
Expand Down Expand Up @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public void testConvertBackFidelity() {
functionConfig.setRuntime(FunctionConfig.Runtime.JAVA);
functionConfig.setProcessingGuarantees(FunctionConfig.ProcessingGuarantees.ATLEAST_ONCE);
functionConfig.setRetainOrdering(false);
functionConfig.setRetainKeyOrdering(false);
functionConfig.setForwardSourceMessageProperty(true);
functionConfig.setUserConfig(new HashMap<>());
functionConfig.setAutoAck(true);
Expand Down Expand Up @@ -94,6 +95,7 @@ public void testConvertWindow() {
functionConfig.setRuntime(FunctionConfig.Runtime.JAVA);
functionConfig.setProcessingGuarantees(FunctionConfig.ProcessingGuarantees.ATLEAST_ONCE);
functionConfig.setRetainOrdering(false);
functionConfig.setRetainKeyOrdering(false);
functionConfig.setForwardSourceMessageProperty(true);
functionConfig.setUserConfig(new HashMap<>());
functionConfig.setAutoAck(true);
Expand Down Expand Up @@ -232,6 +234,13 @@ public void testMergeDifferentRetainOrdering() {
FunctionConfigUtils.validateUpdate(functionConfig, newFunctionConfig);
}

@Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "Retain Key Ordering cannot be altered")
public void testMergeDifferentRetainKeyOrdering() {
FunctionConfig functionConfig = createFunctionConfig();
FunctionConfig newFunctionConfig = createUpdatedFunctionConfig("retainKeyOrdering", true);
FunctionConfigUtils.validateUpdate(functionConfig, newFunctionConfig);
}

@Test
public void testMergeDifferentUserConfig() {
FunctionConfig functionConfig = createFunctionConfig();
Expand Down Expand Up @@ -423,6 +432,7 @@ private FunctionConfig createFunctionConfig() {
functionConfig.setRuntime(FunctionConfig.Runtime.JAVA);
functionConfig.setProcessingGuarantees(FunctionConfig.ProcessingGuarantees.ATLEAST_ONCE);
functionConfig.setRetainOrdering(false);
functionConfig.setRetainKeyOrdering(false);
functionConfig.setForwardSourceMessageProperty(false);
functionConfig.setUserConfig(new HashMap<>());
functionConfig.setAutoAck(true);
Expand Down