Repository navigation
[fix][tableview] Pass nil to listeners on tombstone messages instead of the zero value - #1567
Open
zjxxzjwang wants to merge 1 commit into
Open
zjxxzjwang wants to merge 1 commit into
zjxxzjwang wants to merge 1 commit into
Conversation
…of the zero value
Contributor
Author
|
@crossoverJie Hello, can you help me review this PR. |
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.
[fix][tableview] Pass nil to listeners on tombstone messages instead of the zero value
Motivation
TableViewImpl.handleMessagepasses the deserialized payload to every registeredlistener. For tombstone messages (empty payload),
payloadis created viareflect.New(SchemaValueType)but is never populated byGetSchemaValue,so listeners end up receiving the type's zero value
(e.g.
MyStruct{},"",0,*T(nil-indirect)).This has two concrete problems:
Ambiguous semantics. Listeners cannot distinguish between:
Any downstream logic that reacts to deletions (cache eviction, state
machine transitions, metrics) is forced to also consult
tv.dataunder its own lock, which is both racy and unergonomic.
Inconsistent with the Java client. The Java
TableViewImplexplicitly delivers
nullto listeners on tombstones. The Go clientsilently diverged from that contract.
Minimal reproducer before the fix:
Modifications
pulsar/table_view_impl.go, refactoredhandleMessageto compute a singlevaluevariable and pass it to all listeners:len(msg.Payload()) == 0): delete the key fromtv.dataand setvalue = nil.payload, setvalue = reflect.Indirect(payload).Interface(), and store it intv.data.valueinstead of re-reading anunconditionally-created
payload, so tombstones consistently delivernil.tv.datacontents, lock scope, or any other public method.Verifying this change
This change added tests and can be verified as follows:
TestHandleMessageListenerValueinpulsar/table_view_test.go.It is a pure unit test (no broker required) that drives
handleMessagedirectly and asserts the listener contract on three cases:
tv.datais updated accordingly.nil(not thetype zero value) and the key is removed from
tv.data.nil.TestPublishNilValuecontinues to pass,confirming that end-to-end tombstone handling against a real broker is
unaffected.
Run locally:
go test -run TestHandleMessageListenerValue -count=1 -v ./pulsar/Does this pull request potentially affect one of the following parts:
listeners registered via
ForEachAndListennow receivenilinstead ofthe schema type's zero value when a tombstone (empty-payload message)
arrives. Callers that previously relied on receiving a zero value
without a nil check must update their listener to handle
nilas adeletion signal. This brings the Go client in line with the Java
TableViewImplcontract.Documentation
This is a bug fix that aligns the Go
TableViewlistener semanticswith the already-documented Java client behavior. The GoDoc on
ForEachAndListencan optionally be updated in a follow-up to call outthe
nilconvention for tombstones.issue for adding the documentation: n/a