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

VReplication: Enable VPlayerBatching in unit tests #17339

Merged
merged 5 commits into from
Dec 6, 2024

Conversation

mattlord
Copy link
Contributor

@mattlord mattlord commented Dec 5, 2024

Description

This is a quick follow-up to #17166. When working on that, I did not realize that the unit test framework was explicitly disabling all experimental flags and thus we were not testing the new flag/default behavior. This PR removes that vttablet.DefaultVReplicationConfig.ExperimentalFlags = 0 line in framework_test.go and adjusts the unit test expectations accordingly.

In working on this, it surfaced an issue with an extraneous BEGIN being used when in batching mode that was also corrected in vdbclient.go. Similarly, the unit tests surfaced an extraneous state update that was corrected here in vreplicator.go. Lastly, it also updates the vplayer so that batching is only done when in the running/replicating phase as intended.

Related Issue(s)

Checklist

  • "Backport to:" labels have been added if this change should be back-ported to release branches
  • If this change is to be back-ported to previous releases, a justification is included in the PR description
  • Tests were added or are not required
  • Did the new or modified tests pass consistently locally and on CI?
  • Documentation was added or is not required

Copy link
Contributor

vitess-bot bot commented Dec 5, 2024

Review Checklist

Hello reviewers! 👋 Please follow this checklist when reviewing this Pull Request.

General

  • Ensure that the Pull Request has a descriptive title.
  • Ensure there is a link to an issue (except for internal cleanup and flaky test fixes), new features should have an RFC that documents use cases and test cases.

Tests

  • Bug fixes should have at least one unit or end-to-end test, enhancement and new features should have a sufficient number of tests.

Documentation

  • Apply the release notes (needs details) label if users need to know about this change.
  • New features should be documented.
  • There should be some code comments as to why things are implemented the way they are.
  • There should be a comment at the top of each new or modified test to explain what the test does.

New flags

  • Is this flag really necessary?
  • Flag names must be clear and intuitive, use dashes (-), and have a clear help text.

If a workflow is added or modified:

  • Each item in Jobs should be named in order to mark it as required.
  • If the workflow needs to be marked as required, the maintainer team must be notified.

Backward compatibility

  • Protobuf changes should be wire-compatible.
  • Changes to _vt tables and RPCs need to be backward compatible.
  • RPC changes should be compatible with vitess-operator
  • If a flag is removed, then it should also be removed from vitess-operator and arewefastyet, if used there.
  • vtctl command output order should be stable and awk-able.

@vitess-bot vitess-bot bot added NeedsBackportReason If backport labels have been applied to a PR, a justification is required NeedsDescriptionUpdate The description is not clear or comprehensive enough, and needs work NeedsIssue A linked issue is missing for this Pull Request NeedsWebsiteDocsUpdate What it says labels Dec 5, 2024
@github-actions github-actions bot added this to the v22.0.0 milestone Dec 5, 2024
@mattlord mattlord removed NeedsWebsiteDocsUpdate What it says NeedsBackportReason If backport labels have been applied to a PR, a justification is required labels Dec 5, 2024
@mattlord mattlord force-pushed the vplayerbatching_unit_tests branch from 22b1c1d to f8a3fad Compare December 5, 2024 02:12
@mattlord mattlord removed NeedsDescriptionUpdate The description is not clear or comprehensive enough, and needs work NeedsIssue A linked issue is missing for this Pull Request labels Dec 5, 2024
@mattlord mattlord marked this pull request as ready for review December 5, 2024 02:16
@@ -141,7 +141,6 @@ func setup(ctx context.Context) (func(), int) {
resetBinlogClient()

vttablet.InitVReplicationConfigDefaults()
vttablet.DefaultVReplicationConfig.ExperimentalFlags = 0
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is where the flags were disabled for all of the unit tests and I did not notice it previously.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If we want this PR to be able to stand on its own, I could change this line to vttablet.DefaultVReplicationConfig.ExperimentalFlags = 7 rather than removing it.

Copy link

codecov bot commented Dec 5, 2024

Codecov Report

Attention: Patch coverage is 81.81818% with 4 lines in your changes missing coverage. Please review.

Project coverage is 67.42%. Comparing base (2da3893) to head (26f93d4).
Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
...t/vttablet/tabletmanager/vreplication/vdbclient.go 83.33% 2 Missing ⚠️
...vttablet/tabletmanager/vreplication/vreplicator.go 75.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #17339      +/-   ##
==========================================
- Coverage   67.42%   67.42%   -0.01%     
==========================================
  Files        1575     1576       +1     
  Lines      253324   253429     +105     
==========================================
+ Hits       170816   170873      +57     
- Misses      82508    82556      +48     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@mattlord mattlord marked this pull request as draft December 5, 2024 03:07
@mattlord mattlord force-pushed the vplayerbatching_unit_tests branch 4 times, most recently from e552d3c to fc4187d Compare December 5, 2024 04:12
@mattlord mattlord marked this pull request as ready for review December 5, 2024 04:34
@mattlord mattlord force-pushed the vplayerbatching_unit_tests branch from fc4187d to e1d2649 Compare December 5, 2024 04:45
// starts with the BEGIN and ends with the COMMIT, so we
// do not send a BEGIN down the wire ahead of time.
vc.queriesPos = int64(len(vc.queries))
vc.batchSize = 6 // begin and semicolon
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like it's not new here and moved, but should we avoid the magic constant here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's not a magic constant, it's just the known length of "begin;"

Signed-off-by: Matt Lord <[email protected]>
Comment on lines +511 to +518
// If we're batching a transaction, then include the state update
// in the current transaction batch.
if vr.dbClient.InTransaction && vr.dbClient.maxBatchSize > 0 {
vr.dbClient.AddQueryToTrxBatch(query)
} else { // Otherwise, send it down the wire
if _, err := vr.dbClient.ExecuteFetch(query, 1); err != nil {
return fmt.Errorf("could not set state: %v: %v", query, err)
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the fix for the noted extraneous state update that surfaced in the unit tests. This caused no known issues, but was unnecessary and corrected here.

// starts with the BEGIN and ends with the COMMIT, so we
// do not send a BEGIN down the wire ahead of time.
vc.queriesPos = int64(len(vc.queries))
vc.batchSize = 6 // begin and semicolon
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's make it clearer in the comment:

Suggested change
vc.batchSize = 6 // begin and semicolon
vc.batchSize = 6 // equal to `len("begin;")`

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed it here: 26f93d4

Comment on lines +61 to +72
if vc.maxBatchSize > 0 {
// We are batching the contents of the transaction, which
// starts with the BEGIN and ends with the COMMIT, so we
// do not send a BEGIN down the wire ahead of time.
vc.queriesPos = int64(len(vc.queries))
vc.batchSize = beginStmtLen
} else {
// We're not batching so we start the transaction here
// by sending the BEGIN down the wire.
if err := vc.DBClient.Begin(); err != nil {
return err
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the fix for the noted extraneous BEGIN that surfaced in the unit tests. This was harmless, but also unnecessary and corrected here.

@mattlord mattlord merged commit f9acb77 into vitessio:main Dec 6, 2024
100 checks passed
@mattlord mattlord deleted the vplayerbatching_unit_tests branch December 6, 2024 14:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants