vitessio / vitess

Vitess is a database clustering system for horizontal scaling of MySQL.
http://vitess.io
Apache License 2.0
18.47k stars 2.09k forks source link

Support specifying expected primary in ERS #16852

Open timvaillancourt opened 1 day ago

timvaillancourt commented 1 day ago

Description

This PR allows a EmergencyReparentShard request to contain the alias of the primary we expect to be the current primary for the action to succeed. If this alias is incorrect or stale, the reparent fails with an error indicating there is a failed precondition/mismatch.

This is useful to prevent races between external automation that runs EmergencyReparentShard and Vitess (vtorc and vtctld), which may reparent a shard in the time external automation is creating/processing it's own reparent request. With this support added, automation with a stale view of the world will encounter an error instead of triggering another reparent

In the future, Vitess could use this field internally to be more explicit but because everything uses shard locks, it should never encounter a mismatch

Related Issue(s)

Resolves https://github.com/vitessio/vitess/issues/16430

Checklist

Deployment Notes

vitess-bot[bot] commented 1 day ago

Review Checklist

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

General

Tests

Documentation

New flags

If a workflow is added or modified:

Backward compatibility

codecov[bot] commented 1 day ago

Codecov Report

Attention: Patch coverage is 53.84615% with 6 lines in your changes missing coverage. Please review.

Project coverage is 69.43%. Comparing base (2e2b223) to head (c0abfdc). Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
go/cmd/vtctldclient/command/reparents.go 14.28% 6 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #16852 +/- ## ======================================= Coverage 69.43% 69.43% ======================================= Files 1571 1571 Lines 203021 203080 +59 ======================================= + Hits 140970 141013 +43 - Misses 62051 62067 +16 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

mattlord commented 1 day ago

You'll want to add support for this in the client command, no? Here: go/cmd/vtctldclient/command/reparents.go

timvaillancourt commented 1 day ago

You'll want to add support for this in the client command, no? Here: go/cmd/vtctldclient/command/reparents.go

@mattlord oh thanks, yes I'll add support for the CLI binary πŸ‘πŸ‘€

timvaillancourt commented 1 day ago

Added:

tvaillancourt@tvailla-ltmxctu vitess % ./bin/vtctldclient EmergencyReparentShard --help 2>&1 | grep expected-primary
      --expected-primary string          Alias of a tablet that must be the current primary in order for the reparent to be processed.

πŸ‘