Skip to content

tm init: publish displayState#6641

Closed
deepthi wants to merge 2 commits intovitessio:masterfrom
planetscale:ds-tm-init
Closed

tm init: publish displayState#6641
deepthi wants to merge 2 commits intovitessio:masterfrom
planetscale:ds-tm-init

Conversation

@deepthi
Copy link
Copy Markdown
Collaborator

@deepthi deepthi commented Aug 28, 2020

Also, do not change type to RESTORE if not actually performing a restore.

Signed-off-by: deepthi deepthi@planetscale.com

…ctually performing a restore

Signed-off-by: deepthi <deepthi@planetscale.com>
@deepthi deepthi changed the title tm init: publish displayState, do not change type to RESTORE if not a… tm init: publish displayState Aug 28, 2020
@deepthi deepthi requested review from enisoc and sougou August 28, 2020 01:25
Copy link
Copy Markdown
Contributor

@sougou sougou left a comment

Choose a reason for hiding this comment

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

One question. Everything else looks good.

backupManifest, err = mysqlctl.Restore(ctx, params)
if waitForBackupInterval == 0 {
break
if mysqlctl.ShouldRestore(ctx, params) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can you see if this will read better if the check was moved to handleRestore in tm_init.go?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Better to keep it here so that calls from other call-sites also benefit from this change.

Signed-off-by: deepthi <deepthi@planetscale.com>
@deepthi deepthi marked this pull request as ready for review August 28, 2020 19:36

func (tm *TabletManager) restoreDataLocked(ctx context.Context, logger logutil.Logger, waitForBackupInterval time.Duration, deleteBeforeRestore bool) error {

tablet := tm.Tablet()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@sougou said yesterday that we shouldn't be using tm.Tablet() (display state) for programmatic decision making. Did we change our minds about that principle, or is this more of a temporary workaround until we can do a more thorough audit of all uses?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

We found that it is being used in too many places, so it is better to make sure that is returns the most up-to-date state.

// ShouldRestore checks whether a database with tables already exists
// and returns whether a restore action should be performed
func ShouldRestore(ctx context.Context, params RestoreParams) bool {
if !params.DeleteBeforeRestore {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Now that this is in a function, it might be easier to read like:

if params.DeleteBeforeRestore || RestoreWasInterrupted(params.Cnf) {
  return true
}

// check other stuff


// ShouldRestore checks whether a database with tables already exists
// and returns whether a restore action should be performed
func ShouldRestore(ctx context.Context, params RestoreParams) bool {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'd feel better if we returned (bool, error) so the caller can distinguish between "we should restore" and "we failed to determine whether we should restore". That's how Restore() itself currently works. Is there a reason you thought this one should be different?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Also would it make sense for Restore() to call ShouldRestore()?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I went back and forth between returning an error or not. Since you feel that is better, I'll change it.

ok, _ := checkNoDB(ctx, params.Mysqld, params.DbName)
if !ok {
params.Logger.Infof("Auto-restore is enabled, but mysqld already contains data. Assuming vttablet was just restarted.")
_ = PopulateMetadataTables(params.Mysqld, params.LocalMetadata, params.DbName)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It seems unexpected that a function called ShouldRestore would have side effects like this. Unless ShouldRestore is called from many places, I'd suggest moving the call to PopulateMetadataTables to the call site so the either/or logic is clearer: either we restore, or we merely populate metadata.

backupManifest, err = mysqlctl.Restore(ctx, params)
if waitForBackupInterval == 0 {
break
if mysqlctl.ShouldRestore(ctx, params) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I feel like this would read better as an early return since we really want to skip the rest of the function.

if !mysqlctl.ShouldRestore(ctx, params) {
  // Just populate metadata and then return.
}

// Do actual restore.

@deepthi
Copy link
Copy Markdown
Collaborator Author

deepthi commented Aug 29, 2020

Closing this, I'll open two separate PRs, one for the TM changes and one for the restore changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants