[fix][fn] Honour retainOrdering and retainKeyOrdering in the Go function runtime - #26414
Merged
david-streamlio merged 2 commits intoAug 25, 2026
Merged
Conversation
13 tasks
7 tasks
…ion runtime setupConsumer picked the subscription type from SubscriptionType alone. RetainOrdering and RetainKeyOrdering appeared nowhere in pulsar-function-go outside the generated protobuf, so both were accepted by pulsar-admin, reported back by functions get, carried into the instance and then dropped. The consequence for retainKeyOrdering is a correctness one rather than a missing feature: the function ran on a Shared subscription, so messages sharing a key were distributed across instances and processed concurrently - exactly the guarantee the flag exists to provide. Nothing failed and nothing logged; the ordering was simply absent. Extract resolveSubscriptionType and apply both flags after the explicit SubscriptionType, matching the Java and Python runtimes. retainOrdering selects Failover, retainKeyOrdering selects KeyShared, and ordering wins when both are set - the precedence python_instance.py applies in its if/elif. EFFECTIVELY_ONCE needs no arm: instanceConf.go refuses it before an instance is built. The helper takes the three fields rather than FunctionDetails so it can be tested directly and so it does not copy a protobuf message by value, which go vet reports as copying a lock. Fixes apache#26405 Master Issue: apache#26404
Resolves a conflict in pulsar-function-go/pf/instance.go with apache#26415 (negativeAckRedeliveryDelayMs), which landed on master and added resolveNackRedeliveryDelay at the same insertion point ahead of setupConsumer. Both helpers are kept. setupConsumer now resolves the subscription type through resolveSubscriptionType and the redelivery delay through resolveNackRedeliveryDelay, and all four Subscribe call sites carry both.
david-streamlio
force-pushed
the
fix-go-fn-ordering
branch
from
August 24, 2026 22:11
c7b8b38 to
2873de9
Compare
merlimat
approved these changes
Aug 24, 2026
10 tasks
nodece
pushed a commit
to ascentstream/pulsar
that referenced
this pull request
Aug 31, 2026
…ion runtime (apache#26414) (cherry picked from commit 0897616)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #26405
Master Issue: #26404
Motivation
The Go runtime picked the subscription type from one field:
RetainOrderingandRetainKeyOrderingappeared nowhere inpulsar-function-gooutside the generatedpbpackage, so both were accepted bypulsar-admin, reported back byfunctions get, carried into the instance in the protobuf, and dropped.For
retainKeyOrderingthat is a correctness problem rather than a missing feature. This is accepted:and the function runs on a Shared subscription, so messages sharing a key are distributed across instances and processed concurrently — precisely the guarantee the flag exists to provide. Nothing fails, nothing is logged, and the only symptom is out-of-order processing observed downstream.
The Python runtime applies both (
python_instance.py:147-151), as does Java.Modifications
Extract
resolveSubscriptionTypeand apply the ordering flags after the explicitSubscriptionType:retainOrdering→FailoverretainKeyOrdering→KeySharedpython_instance.pyapplies in itsif/elifEFFECTIVELY_ONCEneeds no arm here:instanceConf.go:137refuses it before an instance is built.The helper takes the three fields rather than a
FunctionDetailsso it is directly testable and so it does not copy a protobuf message by value —go vetreports that as copying a lock, and the version of this change that passed the struct added three new warnings on top of the three already present on master.Verifying this change
This change added tests and can be verified as follows:
pf/subscriptionType_test.go: the Shared default; an explicit Failover;retainOrderingselecting Failover;retainKeyOrderingselecting KeyShared; ordering winning when both are set; andretainKeyOrderingoverriding an explicit Failover.go build ./...and the fullgo test ./pf/pass;go vetreports the same three pre-existing lock-copy warnings as master and no new ones.Does this pull request potentially affect one of the following parts:
Deployment note. A Go function already deployed with
--retain-orderingor--retain-key-orderingchanges subscription type on the next restart — Shared to Failover or KeyShared respectively. That is the configured behaviour taking effect for the first time, but it is a change for anyone who set the flag, observed Shared behaviour and adapted to it. A function that sets neither flag is unaffected.Documentation
doc-requireddoc-not-neededdocdoc-completeBoth options are already documented; this makes the Go runtime honour them.