-
Notifications
You must be signed in to change notification settings - Fork 188
relay/syncer: relay notifies syncer of new write to reduce sync latency #2225
Conversation
[REVIEW NOTIFICATION] This pull request has been approved by:
To complete the pull request process, please ask the reviewers in the list to review by filling The full list of commands accepted by this bot can be found here. Reviewer can indicate their review by submitting an approval review. |
/cc @lichunzhu |
// OnEvent implements relay.Listener | ||
// only syncer unit of subtask need to be notified, but it's much simpler and less error-prone to manage it here | ||
// as relay event need to broadcast to every syncer(most subtask have a syncer). | ||
func (h *subTaskHolder) OnEvent(e *replication.BinlogEvent) { |
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.
seems e *replication.BinlogEvent
is not used here, why we need this param ?
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 a event
listener
the parameter is not used now, but it's added for completeness(observer pattern), may used later.
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.
func (h *subTaskHolder) OnEvent(e *replication.BinlogEvent) { | |
func (h *subTaskHolder) OnEvent(_ *replication.BinlogEvent) { |
we parse from the last position, so parseFile in it would be better if we can keep the written size of each binlog file, so we'll know whether it's ended, maybe we can add it later. |
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 control path looks a bit long to me.
Relay receives a new event -> Subtask holder -> Relay reader
The way I expect it to work is that notifications are only coordinated within the relay module, and the subtask holder only needs to request a reader from the relay.
Is this PR a transitional design or a final solution?
@@ -44,12 +46,22 @@ const ( | |||
waitRelayCatchupTimeout = 30 * time.Second | |||
) | |||
|
|||
type relayNotifier struct { | |||
// ch with size = 1, we only need to be notified whether binlog file of relay changed, not how many times | |||
ch chan interface{} |
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.
ch chan interface{} | |
ch chan struct{} |
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.
no gains
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 has some cost to convert struct{}{} to interface{}
i think it should be separate into
this PR is for optimizing latency with relay on, don't want to introduce too much refactoring |
seems a BUG revealed in CI |
it's an unstable case, not a bug. it happens when we
it's hard to reproduce this locally(add sleep(30 ms) after each relay write do reproduce it.) |
/run-unit-tests |
maybe we can add some msg in workaround such as |
@@ -44,12 +46,22 @@ const ( | |||
waitRelayCatchupTimeout = 30 * time.Second | |||
) | |||
|
|||
type relayNotifier struct { | |||
// ch with size = 1, we only need to be notified whether binlog file of relay changed, not how many times | |||
ch chan interface{} |
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 has some cost to convert struct{}{} to interface{}
// OnEvent implements relay.Listener | ||
// only syncer unit of subtask need to be notified, but it's much simpler and less error-prone to manage it here | ||
// as relay event need to broadcast to every syncer(most subtask have a syncer). | ||
func (h *subTaskHolder) OnEvent(e *replication.BinlogEvent) { |
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.
func (h *subTaskHolder) OnEvent(e *replication.BinlogEvent) { | |
func (h *subTaskHolder) OnEvent(_ *replication.BinlogEvent) { |
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 except for the unresolved comments
/merge |
This pull request has been accepted and is ready to merge. Commit hash: 99b2ed7
|
In response to a cherrypick label: new pull request created: #2269. |
What problem does this PR solve?
What is changed and how it works?
Listener
function to relay, it notifies after writing events successfullyEventNotifier
to local binlog reader(used by syncer), and changepolling file change
towaiting on write events
to reduce sync latencyCheck List
Tests