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: Add reference-tables to existing materialize workflow #17804

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

beingnoble03
Copy link
Member

@beingnoble03 beingnoble03 commented Feb 15, 2025

Description

This PR adds MaterializeAddTables in VtctldServer. This can be used to add tables to an existing VReplication MoveTables/Materialize workflow. It adds binlogsource rules in the existing workflow streams, and inserts the copy state row in _vt.copy_state and restarts the workflow. Also adds a add-reference-tables sub-command for materialize command, which can be used as following:

vtctldclient Materialize --target-keyspace=customer --workflow=w1 add-reference-tables --tables="corder,customer"

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

Deployment Notes

Copy link
Contributor

vitess-bot bot commented Feb 15, 2025

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 Feb 15, 2025
@github-actions github-actions bot added this to the v22.0.0 milestone Feb 15, 2025
Copy link

codecov bot commented Feb 15, 2025

Codecov Report

Attention: Patch coverage is 66.91176% with 90 lines in your changes missing coverage. Please review.

Project coverage is 67.46%. Comparing base (4c27ea8) to head (268e7de).
Report is 45 commits behind head on main.

Files with missing lines Patch % Lines
go/vt/vtctl/workflow/server.go 76.96% 38 Missing ⚠️
...nt/command/vreplication/materialize/materialize.go 17.39% 19 Missing ⚠️
go/vt/vtctl/grpcvtctldserver/server.go 0.00% 12 Missing ⚠️
go/vt/vtctl/workflow/materializer.go 83.92% 9 Missing ⚠️
go/vt/vtctl/grpcvtctldclient/client_gen.go 0.00% 5 Missing ⚠️
...vttablet/tabletmanager/vreplication/vreplicator.go 50.00% 3 Missing ⚠️
go/vt/vtctl/localvtctldclient/client_gen.go 0.00% 2 Missing ⚠️
go/vt/vttablet/tabletmanager/rpc_vreplication.go 33.33% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #17804      +/-   ##
==========================================
- Coverage   67.97%   67.46%   -0.51%     
==========================================
  Files        1586     1594       +8     
  Lines      255195   259200    +4005     
==========================================
+ Hits       173468   174874    +1406     
- Misses      81727    84326    +2599     

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

@beingnoble03 beingnoble03 force-pushed the add-tables-materialize branch from ed0f3e9 to 7d4356f Compare February 17, 2025 07:04
@beingnoble03 beingnoble03 force-pushed the add-tables-materialize branch from 7d4356f to 5b317c5 Compare February 17, 2025 19:43
@beingnoble03 beingnoble03 force-pushed the add-tables-materialize branch from 7b4c750 to bdc7309 Compare February 18, 2025 11:15
@beingnoble03 beingnoble03 added Type: Enhancement Logical improvement (somewhere between a bug and feature) Component: VReplication and removed NeedsDescriptionUpdate The description is not clear or comprehensive enough, and needs work NeedsWebsiteDocsUpdate What it says NeedsIssue A linked issue is missing for this Pull Request NeedsBackportReason If backport labels have been applied to a PR, a justification is required labels Feb 22, 2025
Copy link
Contributor

@mattlord mattlord left a comment

Choose a reason for hiding this comment

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

This is looking really good! Please let me know what you think about my comments.


// addReferenceTables makes a MaterializeAddTables gRPC call to a vtctld.
addReferenceTables = &cobra.Command{
Use: "add-reference-tables --tables='table1,table2'",
Copy link
Contributor

@mattlord mattlord Feb 27, 2025

Choose a reason for hiding this comment

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

This command name follows flag name conventions. It should be addreferencetables instead.

I wonder why we should limit this to reference tables? I know that was the use case in the feature request but the same underlying issues apply to any materialized table, no? Toward that end, I think it might be nice to have:
materialize --target-keyspace=commerce --workflow=foo update --add-tables 'table1,table2'

Then in the future we could support other updates such as removing tables.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sounds good! But, do you think we should also add a TableSettings flag for this?

sourceKeyspace string
workflowType binlogdatapb.VReplicationWorkflowType
)

Copy link
Contributor

Choose a reason for hiding this comment

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

We need to get a named workflow lock and a target keyspace lock here. Otherwise there's no concurrency control in place and behavior is undefined.

Copy link
Member Author

Choose a reason for hiding this comment

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

done, thanks!

Comment on lines 894 to 900
mu.Lock()
if len(res.Streams) > 0 && sourceKeyspace == "" {
sourceKeyspace = res.Streams[0].Bls.Keyspace
}
workflowType = res.WorkflowType
readVReplicationWorkflowResp[tablet.Shard] = res
mu.Unlock()
Copy link
Contributor

@mattlord mattlord Feb 27, 2025

Choose a reason for hiding this comment

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

Nit, but IMO it's worth using a closure here to be sure the mutex is unlocked using a defer (e.g. you get a panic between the lock and unlock, and that panic is recovered up the call stack, but then we don't unlock the mutex — although in this specific case it would be fine since this mutex would go out of scope in that case).

		func() {
			mu.Lock()
			defer mu.Unlock()
			if len(res.Streams) > 0 && sourceKeyspace == "" {
				sourceKeyspace = res.Streams[0].Bls.Keyspace
			}
			workflowType = res.WorkflowType
			readVReplicationWorkflowResp[tablet.Shard] = res
		}()

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah, right! done.

}
// We only allow adding tables for MoveTables and Materialize workflows.
if workflowType != binlogdatapb.VReplicationWorkflowType_Materialize &&
workflowType != binlogdatapb.VReplicationWorkflowType_MoveTables {
Copy link
Contributor

Choose a reason for hiding this comment

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

OK, so we can support adding tables to a MoveTables workflow later too 👍 . It's another reason why I think we should probably use the update sub-command as noted above.

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah, MaterializeAddTables() still works for both MoveTables and Materialize, only thing that's missing is the sub-command for the movetables.

return err
}

mu.Lock()
Copy link
Contributor

Choose a reason for hiding this comment

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

Same note here about using a closure. I also wonder if it's worth making readVReplicationWorkflowResp an atomic map/pointer.

Query: []byte(buf.String()),
})
if err != nil {
return vterrors.Wrapf(err, "failed to insert tables copy state for workflow %s on shard %s/%s", req.Workflow, req.Keyspace, tablet.Shard)
Copy link
Contributor

Choose a reason for hiding this comment

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

Any reason not to include the table name here?

Copy link
Member Author

Choose a reason for hiding this comment

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

we are using multiple value insert here, doesn't look like we can point out the specific table. moreover, we are wrapping the error so it can help i think.

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
None yet
Development

Successfully merging this pull request may close these issues.

Feature Request: ability to update Materialize workflow with new reference tables
2 participants