Skip to content
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

relay: add async/batch relay writer #7580

Merged
merged 22 commits into from
Nov 29, 2022
Merged

Conversation

GMHDBJD
Copy link
Contributor

@GMHDBJD GMHDBJD commented Nov 10, 2022

What problem does this PR solve?

Issue Number: ref #4287

What is changed and how it works?

  • async write relay log
  • write relay log in batch(1MB)

Check List

Tests

  • Unit test

Questions

Will it cause performance regression or break compatibility?
Do you need to update user documentation, design documentation or monitoring documentation?

Release note

None

@ti-chi-bot
Copy link
Member

ti-chi-bot commented Nov 10, 2022

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • D3Hunter
  • lance6716

To complete the pull request process, please ask the reviewers in the list to review by filling /cc @reviewer in the comment.
After your PR has acquired the required number of LGTMs, you can assign this pull request to the committer in the list by filling /assign @committer in the comment to help you merge this pull request.

The full list of commands accepted by this bot can be found here.

Reviewer can indicate their review by submitting an approval review.
Reviewer can cancel approval by submitting a request changes review.

@ti-chi-bot ti-chi-bot added release-note-none Denotes a PR that doesn't merit a release note. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Nov 10, 2022
@GMHDBJD
Copy link
Contributor Author

GMHDBJD commented Nov 10, 2022

/run-all-tests

@GMHDBJD
Copy link
Contributor Author

GMHDBJD commented Nov 11, 2022

/run-all-tests

@GMHDBJD GMHDBJD added status/ptal Could you please take a look? area/dm Issues or PRs related to DM. labels Nov 16, 2022
@GMHDBJD
Copy link
Contributor Author

GMHDBJD commented Nov 18, 2022

/run-all-tests

@GMHDBJD
Copy link
Contributor Author

GMHDBJD commented Nov 22, 2022

/run-all-tests

Copy link
Contributor

@lance6716 lance6716 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to accept all comments if it's negligible in performance

dm/relay/binlog_writer.go Outdated Show resolved Hide resolved
if w.file == nil {
return terror.ErrRelayWriterNotOpened.Delegate(errors.New("file not opened"))
}
w.input <- rawData
w.offset.Add(int64(len(rawData)))
return w.Error()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since every Write need to check Error, Error is a hot function and we'd better using fast implementation. I prefer atomic variable like using atomic.Error and CAS to replace nil to an error

dm/relay/binlog_writer.go Show resolved Hide resolved
dm/relay/binlog_writer.go Outdated Show resolved Hide resolved
Copy link
Contributor

@D3Hunter D3Hunter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rest lgtm

dm/relay/binlog_writer.go Show resolved Hide resolved
if w.file == nil {
return terror.ErrRelayWriterNotOpened.Delegate(errors.New("file not opened"))
}
w.input <- rawData
w.offset.Add(int64(len(rawData)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BinlogReader will use this offset to check whether there's need to re-parse binlog, maybe move it after we actual write data.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we use offset to check whether hole exist, so cannot update it later.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fileOffset := w.out.Offset()

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use another offset?

}
n, err := w.file.Write(buf.Bytes())
if err != nil {
w.err.CompareAndSwap(nil, terror.ErrBinlogWriterWriteDataLen.Delegate(err, n))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry seems the nil for CAS is not what I expected

func TestCAS(t *testing.T) {
	var nilErr error
	e := atomic.NewError(nil)
	e.Store(nilErr)
	require.NoError(t, e.Load())
	ok := e.CompareAndSwap(nilErr, errors.New("test"))
	require.True(t, ok)
}

Can we use the nilErr variable or simply Store? but in the latter we will store the last error not the first one.

@ti-chi-bot ti-chi-bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Nov 28, 2022
}

if w.file == nil {
w.err.CompareAndSwap(nilErr, terror.ErrRelayWriterNotOpened.Delegate(errors.New("file not opened")))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we simply use Generate() rather than Delegate?

@@ -145,6 +152,10 @@ func (w *FileWriter) handleFormatDescriptionEvent(ev *replication.BinlogEvent) (
if err != nil {
return WResult{}, terror.Annotatef(err, "write binlog file header for %s", fullName)
}
err = w.Flush()
if err != nil {
return WResult{}, terror.Annotatef(err, "write binlog file header for %s", fullName)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return WResult{}, terror.Annotatef(err, "write binlog file header for %s", fullName)
return WResult{}, terror.Annotatef(err, "flush binlog file for %s", fullName)

@ti-chi-bot ti-chi-bot added the status/LGT1 Indicates that a PR has LGTM 1. label Nov 28, 2022
@ti-chi-bot ti-chi-bot added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Nov 29, 2022
@GMHDBJD
Copy link
Contributor Author

GMHDBJD commented Nov 29, 2022

/merge

@ti-chi-bot
Copy link
Member

This pull request has been accepted and is ready to merge.

Commit hash: 71a7896

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Nov 29, 2022
@GMHDBJD
Copy link
Contributor Author

GMHDBJD commented Nov 29, 2022

/run-dm-integration-test

1 similar comment
@GMHDBJD
Copy link
Contributor Author

GMHDBJD commented Nov 29, 2022

/run-dm-integration-test

@ti-chi-bot ti-chi-bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed status/can-merge Indicates a PR has been approved by a committer. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Nov 29, 2022
@GMHDBJD
Copy link
Contributor Author

GMHDBJD commented Nov 29, 2022

/run-all-tests

@GMHDBJD
Copy link
Contributor Author

GMHDBJD commented Nov 29, 2022

/merge

@ti-chi-bot
Copy link
Member

This pull request has been accepted and is ready to merge.

Commit hash: 4d0a324

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Nov 29, 2022
@GMHDBJD
Copy link
Contributor Author

GMHDBJD commented Nov 29, 2022

/merge

@ti-chi-bot ti-chi-bot merged commit bac9c85 into pingcap:master Nov 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/dm Issues or PRs related to DM. release-note-none Denotes a PR that doesn't merit a release note. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2. status/ptal Could you please take a look?
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants