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

LookupVindex: Implement internalize command for lookup vindexes #17429

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

Conversation

beingnoble03
Copy link
Member

@beingnoble03 beingnoble03 commented Dec 24, 2024

Description

This PR

  • Implements the internalize and complete command for lookup vindexes
  • Also, modifies the externalize command where we stop the workflow and mark it as frozen instead of deleting it.
  • complete command checks if the lookup vindex is externalized, and if it has an owner, it deletes the workflow.
  • internalize command starts the frozen streams (if there's an owner) and sets the write_only vindex param back to true (which was deleted when lookup vindex was externalized.)

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 Dec 24, 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 24, 2024
@github-actions github-actions bot added this to the v22.0.0 milestone Dec 24, 2024
Copy link

codecov bot commented Dec 29, 2024

Codecov Report

Attention: Patch coverage is 53.20755% with 124 lines in your changes missing coverage. Please review.

Project coverage is 67.67%. Comparing base (9383943) to head (18b7de1).
Report is 19 commits behind head on main.

Files with missing lines Patch % Lines
.../command/vreplication/lookupvindex/lookupvindex.go 12.50% 56 Missing ⚠️
go/vt/vtctl/grpcvtctldserver/server.go 0.00% 24 Missing ⚠️
go/vt/vtctl/workflow/server.go 82.30% 20 Missing ⚠️
go/vt/vtctl/grpcvtctldclient/client_gen.go 0.00% 10 Missing ⚠️
go/vt/vtctl/workflow/lookup_vindex.go 76.47% 8 Missing ⚠️
go/vt/vtctl/localvtctldclient/client_gen.go 0.00% 4 Missing ⚠️
go/vt/vtctl/workflow/utils.go 81.81% 2 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##             main   #17429    +/-   ##
========================================
  Coverage   67.67%   67.67%            
========================================
  Files        1583     1584     +1     
  Lines      254363   254703   +340     
========================================
+ Hits       172140   172376   +236     
- Misses      82223    82327   +104     

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

@beingnoble03 beingnoble03 added Type: 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 Dec 30, 2024
@beingnoble03 beingnoble03 marked this pull request as ready for review December 30, 2024 06:30
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 good! I only had some minor comments and suggestions. Let me know what you think.

@@ -158,7 +178,7 @@ var (
// externalize makes a LookupVindexExternalize call to a vtctld.
externalize = &cobra.Command{
Use: "externalize",
Short: "Externalize the Lookup Vindex. If the Vindex has an owner the VReplication workflow will also be deleted.",
Short: "Externalize the Lookup Vindex. If the Vindex has an owner the VReplication workflow will also be stopped.",
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be challenging or problematic to add a --delete flag for externalize for those that want to retain the old behavior? Then we can continue using the WorkflowDeleted response field too.

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 👍

Comment on lines 253 to 255
if resp.WorkflowDeleted {
output = output + fmt.Sprintf(" and the %s VReplication workflow has been deleted", baseOptions.Name)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it would also be nice to note when it was NOT deleted and why as the user is likely going to want to follow-up on this at some point.

Nit, but I don't think we need to specify the name yet again here, we can instead say and the VReplication workflow...

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 👍

Comment on lines 332 to 333
if resp.WorkflowStarted {
output = output + fmt.Sprintf(" and the %s VReplication workflow has been started", baseOptions.Name)
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comments here from the complete command.

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.

@@ -127,6 +127,9 @@ const (
lockTablesCycles = 2
// Time to wait between LOCK TABLES cycles on the sources during SwitchWrites.
lockTablesCycleDelay = time.Duration(100 * time.Millisecond)

SqlFreezeWorkflow = "update _vt.vreplication set message = '%s' where db_name=%s and workflow=%s"
Copy link
Contributor

Choose a reason for hiding this comment

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

We can set the message directly here using the const as we always want to freeze it with the query.

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.

Comment on lines +560 to +561
// LookupVindexComplete checks if the lookup vindex has been externalized,
// and if the vindex has an owner, it deletes the workflow.
Copy link
Contributor

Choose a reason for hiding this comment

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

I think that the criteria should be the lookup vindex backfill workflow is "done", meaning it was externalized, which in turn means that it's no longer write_only and it has an owner (the source table).

Copy link
Member Author

Choose a reason for hiding this comment

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

Same comment about the validateExternalized()

Comment on lines 749 to 760
// Stop the workflow.
_, err = s.tmc.UpdateVReplicationWorkflow(ctx, tabletInfo.Tablet, &tabletmanagerdatapb.UpdateVReplicationWorkflowRequest{
Workflow: req.Name,
State: ptr.Of(binlogdatapb.VReplicationWorkflowState_Stopped),
})
if err != nil {
return vterrors.Wrapf(err, "failed to stop workflow %s on shard %s/%s", req.Name, tabletInfo.Keyspace, tabletInfo.Shard)
}
// Mark workflow as frozen.
query := fmt.Sprintf(SqlFreezeWorkflow, Frozen,
encodeString(tabletInfo.DbName()), encodeString(req.Name))
_, err = s.tmc.VReplicationExec(ctx, tabletInfo.Tablet, query)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think that we should update the message in the UpdateVReplicationWorkflow call above, which means we'll have to add support for that to the RPC as an optional proto field.

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 for this! This is much cleaner now.

Comment on lines +777 to +778
// LookupVindexInternalize internalizes a lookup vindex. If the vindex has an
// owner then the stopped workflow will also be started.
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's also worth checking that it does not have the write_only flag set as well.

I think it's worth defining what it means for a vindex to be externalized as 1) having an owner 2) having write_only == false, so that we can check for that everywhere using a function.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added check for write_only, but shouldn't we check if all the streams are running if it's an unowned vindex, and all the streams are stopped if it's an owned vindex? Added validateExternalized() func for this, please have a look.

Please let me know if that's the right thing?

@beingnoble03 beingnoble03 force-pushed the lookup-vindex-internalize branch from 54753a4 to ee296d2 Compare January 8, 2025 21:51
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.

Feature Request: LookupVindex has no internalize command (equivalent to ReverseTraffic)
3 participants