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

VDiff: Support a max diff time for tables #14786

Merged
merged 22 commits into from
Dec 27, 2023

Conversation

mattlord
Copy link
Contributor

@mattlord mattlord commented Dec 15, 2023

Description

This PR adds a VDiff create flag called --max-diff-duration which allows a user to limit the maximum runtime for a single table diff run (the table diff can span N runs). This allows a user to further limit the impact of a VDiff on their production systems. Please see the issue for more information on the use case.

Click here to see a simple manual test:
./101_initial_cluster.sh

mysql < ../common/insert_commerce_data.sql

./201_customer_tablets.sh

./202_move_tables.sh

for i in {1..21}; do
  mysql commerce -e "insert into customer (email) values ('${RANDOM}_person_${RANDOM}@planetscale.com'); insert into customer (email) select email from customer"
done

sleep 180

vtctldclient vdiff --target-keyspace customer --workflow commerce2customer create --max-diff-duration 10s --update-table-stats

while true; do
  results=$(vtctldclient vdiff --target-keyspace customer --workflow commerce2customer show last)
  echo "${results}"
  if echo "${results}" | grep -q "State:        completed"; then
    echo "#################### DONE ####################"
    vtctldclient vdiff --target-keyspace customer --workflow commerce2customer show last --verbose
    break
  fi
done

command mysql -u root --socket=${VTDATAROOT}/vt_0000000201/mysql.sock vt_customer -e "select count(*) as corder_rows from corder; select count(*) as customer_rows from customer;"

let primaryuid=$(vtctldclient GetTablets --keyspace=customer --tablet-type=primary | awk '{print $1}' | cut -d "-" -f2)+0
echo

curl -s localhost:15${primaryuid}/debug/vars | grep -i VDiffRestarted

Final results being:

VDiff Summary for customer.commerce2customer (dbc99b78-dfac-4b80-a789-d01fac7f152d)
State:        completed
RowsCompared: 14680067
HasMismatch:  false
StartedAt:    2023-12-15 00:37:39
CompletedAt:  2023-12-15 00:39:03

Table corder:
	State:            completed
	ProcessedRows:    5
	MatchingRows:     5

Table customer:
	State:            completed
	ProcessedRows:    14680062
	MatchingRows:     14680062

Use "--format=json" for more detailed output.

+-------------+
| corder_rows |
+-------------+
|           5 |
+-------------+
+---------------+
| customer_rows |
+---------------+
|      14680062 |
+---------------+

"VDiffRestartedTableDiffsCount": {"customer": 2},

Related Issue(s)

Checklist

  • "Backport to:" labels have been added if this change should be back-ported
  • Tests were added
  • Did the new or modified tests pass consistently locally and on the CI
  • Documentation: vtctldclient docs will automatically be added

Copy link
Contributor

vitess-bot bot commented Dec 15, 2023

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 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 15, 2023
@github-actions github-actions bot added this to the v19.0.0 milestone Dec 15, 2023
@mattlord mattlord added Type: Enhancement Logical improvement (somewhere between a bug and feature) Component: VReplication labels Dec 15, 2023
@mattlord mattlord force-pushed the vdiff_restart_option branch from aa66f26 to 67d55a9 Compare December 15, 2023 00:42
@mattlord mattlord force-pushed the vdiff_restart_option branch from 2967b12 to 78b7915 Compare December 21, 2023 18:23
Signed-off-by: Matt Lord <[email protected]>
@mattlord mattlord force-pushed the vdiff_restart_option branch from 78b7915 to e75bad7 Compare December 21, 2023 18:24
@mattlord mattlord removed the NeedsWebsiteDocsUpdate What it says label Dec 21, 2023
Copy link
Contributor

@ajm188 ajm188 left a comment

Choose a reason for hiding this comment

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

lgtm! just a few questions that shouldn't affect mergability

go/cmd/vtctldclient/command/vreplication/vdiff/vdiff.go Outdated Show resolved Hide resolved
@@ -267,6 +318,7 @@ func testCLIFlagHandling(t *testing.T, targetKs, workflowName string, cell *Cell
AutoRetry: true,
UpdateTableStats: true,
TimeoutSeconds: 60,
MaxDiffSeconds: 333,
Copy link
Contributor

Choose a reason for hiding this comment

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

333 seems like an oddly-specific duration to me ... is there a reason you went with this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Only in that I needed to pick something specific and this is the random number I typed. 🙂

@@ -52,6 +52,9 @@ import (
// how long to wait for background operations to complete
var BackgroundOperationTimeout = topo.RemoteOperationTimeout * 4

var ErrMaxDiffDurationExceeded = vterrors.Errorf(vtrpcpb.Code_DEADLINE_EXCEEDED, "table diff was stopped due to exceeding the max-diff-duration time")
Copy link
Contributor

Choose a reason for hiding this comment

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

nice

@@ -621,6 +621,7 @@ message VDiffCoreOptions {
int64 timeout_seconds = 6;
int64 max_extra_rows_to_compare = 7;
bool update_table_stats = 8;
int64 max_diff_seconds = 9;
Copy link
Contributor

Choose a reason for hiding this comment

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

this is more a general question, since the other duration-type in this message is also int64: is there a reason we do the "int as seconds" thing here rather than using vttime.Duration like we do in vtctldata and others?

(also extremely nit-picky and GH won't let me comment on the line, but i'm spotting a double-space:

- int64  max_rows = 3;
+ int64 max_rows = 3;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought about that too, but vttime is a struct with a seconds and nanoseconds value and in this case I only cared about the seconds so just used that part of it. I'm fine changing it back though too.

I'll fix the spacing. Thanks!

Copy link
Contributor

Choose a reason for hiding this comment

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

i'm good with the consistency! (i.e. don't change it)

@mattlord mattlord merged commit 4bb84ed into vitessio:main Dec 27, 2023
107 checks passed
@mattlord mattlord deleted the vdiff_restart_option branch December 27, 2023 15:37
mattlord added a commit to planetscale/vitess that referenced this pull request Dec 27, 2023
We merged these two PRs concurrently and thus
ended up with a breakage:
  - vitessio#14735
  - vitessio#14786

This PR addresses that issue by using a locally
scoped vtgate connection according to the newly
established model.

Signed-off-by: Matt Lord <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: VReplication Type: Enhancement Logical improvement (somewhere between a bug and feature)
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Feature Request: VDiff to support periodically refreshing its DB snapshots to limit impact
3 participants