-
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
replication: Add mysql::serialization based Gtid Log Event #990
replication: Add mysql::serialization based Gtid Log Event #990
Conversation
@serprex if you're interested, maybe you could review this PR? |
return errors.New("failed to get transaction_length field") | ||
} | ||
|
||
// TODO: add and test commit_group_ticket |
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.
TODO
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.
I haven't yet been able to generate any events with an actual commit_group_ticket
.
I first tried with binlog_group_commit_sync_delay=...
but that didn't make any difference.
Then looking at the code I noticed that this has to do with Group Replication (part of InnoDB Cluster), So I setup a cluster with 3 sandbox instances... but that also didn't give me any events for testing.
Looks like this might also be known as BGC (Binlog Group Commit) tickets.
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.
still reviewing, I hope I can find some spare time soon
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.
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (2)
replication/event.go:516
- Consider handling the error returned by uuid.FromBytes(e.SID) instead of discarding it to ensure that invalid SID values are caught.
u, _ := uuid.FromBytes(e.SID)
replication/event.go:554
- [nitpick] For consistency with GTIDEvent, consider renaming GtidTaggedLogEvent to GTIDTaggedLogEvent.
type GtidTaggedLogEvent struct {
return f.Value | ||
} | ||
|
||
func Unmarshal(data []byte, v interface{}) error { |
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.
it's better to split this function into two dedicated functions for Message and Format? I don't understand why they are merged. seems not shared many logic
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.
If you compare it to json.Unmarshal()
that also doesn't have different functions depending on the type (array, string, object, etc).
I think I like to keep it like this.
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.
rest lgtm
serialization/serialization.go
Outdated
pos++ | ||
var n uint64 | ||
var err error | ||
switch f := m.Fields[i].Type.(type) { |
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.
It's more like a golang-style to let every type (FieldIntFixed
, FieldUintVar
, ...) implement an interface with decode
method. So this type-switch can be replaced by
n, err := m.Fields[i].Type.decode(data, pos)
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.
This almost works now:
diff --git a/serialization/serialization.go b/serialization/serialization.go
index 2b71d76..29ff5ed 100644
--- a/serialization/serialization.go
+++ b/serialization/serialization.go
@@ -69,6 +69,7 @@ type Field struct {
// FieldType represents a `type_field`
type FieldType interface {
fmt.Stringer
+ decode(data []byte, pos uint64) (uint64, error)
}
// FieldIntFixed is for values with a fixed length.
@@ -221,35 +222,9 @@ func Unmarshal(data []byte, v interface{}) error {
}
m.Fields[i].ID = int(data[pos] >> 1)
pos++
- var n uint64
- var err error
- switch f := m.Fields[i].Type.(type) {
- case FieldIntFixed:
- n, err = f.decode(data, pos)
- if err != nil {
- return err
- }
- m.Fields[i].Type = f
- case FieldUintVar:
- n, err = f.decode(data, pos)
- if err != nil {
- return err
- }
- m.Fields[i].Type = f
- case FieldIntVar:
- n, err = f.decode(data, pos)
- if err != nil {
- return err
- }
- m.Fields[i].Type = f
- case FieldString:
- n, err = f.decode(data, pos)
- if err != nil {
- return err
- }
- m.Fields[i].Type = f
- default:
- return fmt.Errorf("unsupported field type: %T", m.Fields[i].Type)
+ n, err := m.Fields[i].Type.decode(data, pos)
+ if err != nil {
+ return err
}
pos = n
}
Gives me this:
serialization_test.go:238:12: cannot use FieldIntFixed{…} (value of type FieldIntFixed) as FieldType value in struct literal: FieldIntFixed does not implement FieldType (method decode has pointer receiver)
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.
Oh I see that's because decode
will change itself so it should has a pointer receiver. In other words *FieldIntFixed
implements FieldType
interface. So we should assign *FieldIntFixed
like
diff --git i/replication/event.go w/replication/event.go
index f2056e7..500587f 100644
--- i/replication/event.go
+++ w/replication/event.go
@@ -561,7 +561,7 @@ func (e *GtidTaggedLogEvent) Decode(data []byte) error {
Fields: []serialization.Field{
{
Name: "gtid_flags",
- Type: serialization.FieldIntFixed{
+ Type: &serialization.FieldIntFixed{
Length: 1,
},
},
Do you it's acceptable? In this way we also don't need to assign back to Type
field like line 237
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.
This doesn't seem to work. I thried this: dveeden@7a58236
It flags f.Value = ...
as unused write. Should we return it instead?
The switch also checks for valid field types, without the switch that's not done anymore.
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.
I'll try to provide a valid diff today
Co-authored-by: Copilot <[email protected]>
Hi @dveeden would you like me to directly modify your PR based on my comments? |
I plan to apply those changes today. If more changes is needed after today you can either modify this PR directly or send a PR for my branch. |
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.
rest lgtm
serialization/serialization.go
Outdated
pos++ | ||
var n uint64 | ||
var err error | ||
switch f := m.Fields[i].Type.(type) { |
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.
Oh I see that's because decode
will change itself so it should has a pointer receiver. In other words *FieldIntFixed
implements FieldType
interface. So we should assign *FieldIntFixed
like
diff --git i/replication/event.go w/replication/event.go
index f2056e7..500587f 100644
--- i/replication/event.go
+++ w/replication/event.go
@@ -561,7 +561,7 @@ func (e *GtidTaggedLogEvent) Decode(data []byte) error {
Fields: []serialization.Field{
{
Name: "gtid_flags",
- Type: serialization.FieldIntFixed{
+ Type: &serialization.FieldIntFixed{
Length: 1,
},
},
Do you it's acceptable? In this way we also don't need to assign back to Type
field like line 237
Co-authored-by: lance6716 <[email protected]>
Co-authored-by: lance6716 <[email protected]>
Signed-off-by: lance6716 <[email protected]>
Signed-off-by: lance6716 <[email protected]>
Signed-off-by: lance6716 <[email protected]>
Closes #845
With
mysqlbinlog
:With
go-mysqlbinlog
(decoding a similar, but not identical event):