-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Give RowsEvent
a method to inspect the underlying event type.
#1016
base: master
Are you sure you want to change the base?
Give RowsEvent
a method to inspect the underlying event type.
#1016
Conversation
It's currently impossible to figure out what kind of operation led to a `RowsEvent`; multiple results indicate an `UPDATE`, but there's no way to differentiate an `INSERT` from a `DELETE`.
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.
nit: It's better to add a separate type RowsEventType
? Because I think the new methods of this PR can be used like
if e.IsInsert() {
...
} else if e.IsUpdate {
...
}
...
e.eventType
will be checked for many times.
replication/row_event.go
Outdated
@@ -1120,6 +1120,18 @@ func (e *RowsEvent) Decode(data []byte) error { | |||
return e.DecodeData(pos, data) | |||
} | |||
|
|||
func (e *RowsEvent) IsInsert() bool { |
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.
Yes currently RowsEvent
has no public type information. You can know the type from EventHeader
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.
Indeed. The problem is mostly that once casted to RowsEvent
, it is impossible to inspect an event type - this unnecessarily complicates code needing to handle rows events based on operation type.
It also means consumers need to deal with raw event types (f.ex. UPDATE_ROWS_EVENTv01
vs UPDATE_ROWS_EVENTv2
) which should be kept an implementation detail.
The type data is available thou, we just need to cleanly make it public.
Does this work correctly with compressed binlog events in MySQL? |
…e public RowsEvent type.
Sure 😄 I was mostly following the existing style for |
Not sure tbh. The change covers all binlog versions currently handled by the module, so if compressed binlogs are already supported, then yes. |
RowsEvent
methods to inspect the underlying event type.RowsEvent
a method to inspect the underlying event type.
These are in |
Ah, those a dedicated event type and won't be affected by this change then. |
For TransactionPayloadEvent, I see that it still holds sub-events like normal BinlogEvent go-mysql/replication/transaction_payload_event.go Lines 29 to 35 in 567aa59
And the events are decoded like it's in a normal code path go-mysql/replication/transaction_payload_event.go Lines 144 to 148 in 567aa59
The problem is we didn't have a unit test to verify it, like capturing the wire data and decoding the TransactionPayloadEvent. I'll consider add such unit test later. |
It's currently impossible to figure out what kind of operation led to a
RowsEvent
😞Multiple results indicate an
UPDATE
, but there's no way to differentiate anINSERT
from aDELETE
.This PR implements a new method to determine the event type, regardless of version and/or engine.