-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Backup/restore: provision and restore a tablet with point-in-time recovery flags #13964
Merged
shlomi-noach
merged 16 commits into
vitessio:main
from
planetscale:provision-tablet-pitr
Sep 28, 2023
Merged
Changes from 6 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
9d68d2c
vttablet: support init flags: --restore_to_timestamp, --restore_to_po…
shlomi-noach 813b7d7
adding a 'spare' tablet, unstarted, in backup_utils
shlomi-noach e832cc2
iterate all four tablets
shlomi-noach c11af8a
--restore_to_timestamp requires --restore_from_backup ; same for __re…
shlomi-noach 1ccd02b
backup_pitr tests: reserve a third replica, only initialize and start…
shlomi-noach 2b20ce7
fixed vttablet flags test
shlomi-noach 31b6725
No need for InitTablet
shlomi-noach 029efbc
fix '--restore_to_timestamp' comment
shlomi-noach 0aae5cd
Merge branch 'main' into provision-tablet-pitr
shlomi-noach 345a252
vtcombo flags docs
shlomi-noach f376b60
dashes, not underscores
shlomi-noach b119cde
Merge branch 'main' into provision-tablet-pitr
shlomi-noach c7d1882
fix flags endtoend
shlomi-noach 4e32378
empty commit to kick ci
shlomi-noach b7cfe4d
vtctl still uses underscores
shlomi-noach 6b667ee
vtctldclient uses dashes
shlomi-noach File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,6 +61,7 @@ var ( | |
primary *cluster.Vttablet | ||
replica1 *cluster.Vttablet | ||
replica2 *cluster.Vttablet | ||
replica3 *cluster.Vttablet | ||
localCluster *cluster.LocalProcessCluster | ||
newInitDBFile string | ||
useXtrabackup bool | ||
|
@@ -90,6 +91,7 @@ var ( | |
primary key (id) | ||
) Engine=InnoDB | ||
` | ||
SetupReplica3Tablet func(extraArgs []string) (*cluster.Vttablet, error) | ||
) | ||
|
||
type CompressionDetails struct { | ||
|
@@ -170,9 +172,10 @@ func LaunchCluster(setupType int, streamMode string, stripes int, cDetails *Comp | |
0: "primary", | ||
1: "replica", | ||
2: "rdonly", | ||
3: "spare", | ||
} | ||
for i := 0; i < 3; i++ { | ||
tabletType := tabletTypes[i] | ||
|
||
createTablet := func(tabletType string) error { | ||
tablet := localCluster.NewVttabletInstance(tabletType, 0, cell) | ||
tablet.VttabletProcess = localCluster.VtprocessInstanceFromVttablet(tablet, shard.Name, keyspaceName) | ||
tablet.VttabletProcess.DbPassword = dbPassword | ||
|
@@ -182,33 +185,40 @@ func LaunchCluster(setupType int, streamMode string, stripes int, cDetails *Comp | |
if setupType == Mysqlctld { | ||
mysqlctldProcess, err := cluster.MysqlCtldProcessInstance(tablet.TabletUID, tablet.MySQLPort, localCluster.TmpDirectory) | ||
if err != nil { | ||
return 1, err | ||
return err | ||
} | ||
tablet.MysqlctldProcess = *mysqlctldProcess | ||
tablet.MysqlctldProcess.InitDBFile = newInitDBFile | ||
tablet.MysqlctldProcess.ExtraArgs = extraArgs | ||
tablet.MysqlctldProcess.Password = tablet.VttabletProcess.DbPassword | ||
if err := tablet.MysqlctldProcess.Start(); err != nil { | ||
return 1, err | ||
return err | ||
} | ||
shard.Vttablets = append(shard.Vttablets, tablet) | ||
continue | ||
return nil | ||
} | ||
|
||
mysqlctlProcess, err := cluster.MysqlCtlProcessInstance(tablet.TabletUID, tablet.MySQLPort, localCluster.TmpDirectory) | ||
if err != nil { | ||
return 1, err | ||
return err | ||
} | ||
tablet.MysqlctlProcess = *mysqlctlProcess | ||
tablet.MysqlctlProcess.InitDBFile = newInitDBFile | ||
tablet.MysqlctlProcess.ExtraArgs = extraArgs | ||
proc, err := tablet.MysqlctlProcess.StartProcess() | ||
if err != nil { | ||
return 1, err | ||
return err | ||
} | ||
mysqlProcs = append(mysqlProcs, proc) | ||
|
||
shard.Vttablets = append(shard.Vttablets, tablet) | ||
return nil | ||
} | ||
for i := 0; i < 4; i++ { | ||
tabletType := tabletTypes[i] | ||
if err := createTablet(tabletType); err != nil { | ||
return 1, err | ||
} | ||
} | ||
for _, proc := range mysqlProcs { | ||
if err := proc.Wait(); err != nil { | ||
|
@@ -218,6 +228,7 @@ func LaunchCluster(setupType int, streamMode string, stripes int, cDetails *Comp | |
primary = shard.Vttablets[0] | ||
replica1 = shard.Vttablets[1] | ||
replica2 = shard.Vttablets[2] | ||
replica3 = shard.Vttablets[3] | ||
|
||
if err := localCluster.VtctlclientProcess.InitTablet(primary, cell, keyspaceName, hostname, shard.Name); err != nil { | ||
return 1, err | ||
|
@@ -234,12 +245,23 @@ func LaunchCluster(setupType int, streamMode string, stripes int, cDetails *Comp | |
return 1, err | ||
} | ||
|
||
for _, tablet := range []*cluster.Vttablet{primary, replica1, replica2} { | ||
for _, tablet := range []*cluster.Vttablet{primary, replica1, replica2} { // we don't start replica3 yet | ||
if err := tablet.VttabletProcess.Setup(); err != nil { | ||
return 1, err | ||
} | ||
} | ||
|
||
SetupReplica3Tablet = func(extraArgs []string) (*cluster.Vttablet, error) { | ||
replica3.VttabletProcess.ExtraArgs = append(replica3.VttabletProcess.ExtraArgs, extraArgs...) | ||
if err := localCluster.VtctlclientProcess.InitTablet(replica3, cell, keyspaceName, hostname, shard.Name); err != nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should not be necessary. |
||
return replica3, err | ||
} | ||
if err := replica3.VttabletProcess.Setup(); err != nil { | ||
return replica3, err | ||
} | ||
return replica3, nil | ||
} | ||
|
||
if err := localCluster.VtctlclientProcess.InitShardPrimary(keyspaceName, shard.Name, cell, primary.TabletUID); err != nil { | ||
return 1, err | ||
} | ||
|
@@ -1140,6 +1162,8 @@ func getReplica(t *testing.T, replicaIndex int) *cluster.Vttablet { | |
return replica1 | ||
case 1: | ||
return replica2 | ||
case 2: | ||
return replica3 | ||
default: | ||
assert.Failf(t, "invalid replica index", "index=%d", replicaIndex) | ||
return nil | ||
|
@@ -1290,6 +1314,7 @@ func TestReplicaRestoreToPos(t *testing.T, replicaIndex int, restoreToPos replic | |
} | ||
require.NoErrorf(t, err, "output: %v", output) | ||
verifyTabletRestoreStats(t, replica.VttabletProcess.GetVars()) | ||
checkTabletType(t, replica1.Alias, topodata.TabletType_DRAINED) | ||
} | ||
|
||
func TestReplicaRestoreToTimestamp(t *testing.T, restoreToTimestamp time.Time, expectError string) { | ||
|
@@ -1303,6 +1328,7 @@ func TestReplicaRestoreToTimestamp(t *testing.T, restoreToTimestamp time.Time, e | |
} | ||
require.NoErrorf(t, err, "output: %v", output) | ||
verifyTabletRestoreStats(t, replica1.VttabletProcess.GetVars()) | ||
checkTabletType(t, replica1.Alias, topodata.TabletType_DRAINED) | ||
} | ||
|
||
func verifyTabletBackupStats(t *testing.T, vars map[string]any) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is there a date next to the flag name? The type should be timestamp (or something like that).
Also in a later PR, we should explore whether to combine this flag with
--restore_from_backup_ts string
if possible.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The date clarifies what
RFC3339
format looks like, and is thegolang
default template for that time format. I can remove it of course.Yeah, combining with
--restore_from_backup_ts
is an option, but might be confusing because the flag already has a different meaning and so we'd have to introduce a new flag to say how we'd want to interpret--restore_from_backup_ts
...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, actually no idea why
--restore_to_timestamp 2006-01-02T15:04:05Z07:00
!There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, yes. It's because the comment includes the text
which is interpeted as the default value/type for the variable. Editing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's why I've deferred the discussion on it 😅