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

Rebuild SrvVSchema during InitTablet. #6276

Merged
merged 1 commit into from
Jun 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go/vt/topo/shard.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ func (ts *Server) GetOrCreateShard(ctx context.Context, keyspace, shard, cell st

// make sure a valid vschema has been loaded
log.Info("EnsureVSchema %s/%s", keyspace, shard)
if err = ts.EnsureVSchema(ctx, keyspace, []string{cell}); err != nil {
if err = ts.EnsureVSchema(ctx, keyspace); err != nil {
return nil, vterrors.Wrapf(err, "EnsureVSchema(%v) failed", keyspace)
}

Expand Down
8 changes: 1 addition & 7 deletions go/vt/topo/vschema.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (ts *Server) GetVSchema(ctx context.Context, keyspace string) (*vschemapb.K
}

// EnsureVSchema makes sure that a vschema is present for this keyspace or creates a blank one if it is missing
func (ts *Server) EnsureVSchema(ctx context.Context, keyspace string, cells []string) error {
func (ts *Server) EnsureVSchema(ctx context.Context, keyspace string) error {
vschema, err := ts.GetVSchema(ctx, keyspace)
if err != nil && !IsErrType(err, NoNode) {
log.Info("error in getting vschema for keyspace %s: %v", keyspace, err)
Expand All @@ -88,12 +88,6 @@ func (ts *Server) EnsureVSchema(ctx context.Context, keyspace string, cells []st
return err
}
}

err = ts.RebuildSrvVSchema(ctx, cells)
if err != nil {
log.Errorf("could not rebuild SrvVschema after creating keyspace: %v", err)
return err
}
return nil
}

Expand Down
18 changes: 7 additions & 11 deletions go/vt/vtctl/vtctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -1666,18 +1666,14 @@ func commandCreateKeyspace(ctx context.Context, wr *wrangler.Wrangler, subFlags
wr.Logger().Infof("keyspace %v already exists (ignoring error with -force)", keyspace)
err = nil
}
if err != nil {
return err
}

if !*allowEmptyVSchema {
cells, err := wr.TopoServer().GetKnownCells(ctx)
if err != nil {
return fmt.Errorf("GetKnownCells failed: %v", err)
if err := wr.TopoServer().EnsureVSchema(ctx, keyspace); err != nil {
return err
}

err = wr.TopoServer().EnsureVSchema(ctx, keyspace, cells)
}

if err != nil {
return err
}

if ktype == topodatapb.KeyspaceType_SNAPSHOT {
Expand All @@ -1703,9 +1699,9 @@ func commandCreateKeyspace(ctx context.Context, wr *wrangler.Wrangler, subFlags
wr.Logger().Infof("error from SaveVSchema %v:%v", vs, err)
return err
}
return wr.TopoServer().RebuildSrvVSchema(ctx, []string{} /* cells */)
}
return nil

return wr.TopoServer().RebuildSrvVSchema(ctx, []string{} /* cells */)
}

func commandDeleteKeyspace(ctx context.Context, wr *wrangler.Wrangler, subFlags *flag.FlagSet, args []string) error {
Expand Down
24 changes: 22 additions & 2 deletions go/vt/vttablet/tabletmanager/init_tablet.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,30 @@ func (agent *ActionAgent) InitTablet(port, gRPCPort int32) error {
case err == nil:
// NOOP
case topo.IsErrType(err, topo.NoNode):
// try to RebuildKeyspace here but ignore errors if it fails
// Try to RebuildKeyspace here but ignore errors if it fails.
// It will fail until at least one tablet is up for every shard.
topotools.RebuildKeyspace(ctx, logutil.NewConsoleLogger(), agent.TopoServer, *initKeyspace, []string{agent.TabletAlias.Cell})
default:
return vterrors.Wrap(err, "InitTablet failed to read srvKeyspace")
return vterrors.Wrap(err, "InitTablet failed to read SrvKeyspace")
}

// Rebuild vschema graph if this is the first tablet in this keyspace/cell.
srvVSchema, err := agent.TopoServer.GetSrvVSchema(ctx, agent.TabletAlias.Cell)
switch {
case err == nil:
// Check if vschema was rebuilt after the initial creation of the keyspace.
if _, keyspaceExists := srvVSchema.GetKeyspaces()[*initKeyspace]; !keyspaceExists {
Copy link
Contributor

Choose a reason for hiding this comment

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

Doesn't this also need a RebuildKeyspaceGraph?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't understand. Are you saying if a keyspace is missing from SrvVSchema, it implies that RebuildKeyspace has not run for that keyspace?

Copy link
Contributor

Choose a reason for hiding this comment

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

That's what I thought.

Copy link
Member Author

Choose a reason for hiding this comment

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

I thought that SrvKeyspace and SrvVSchema were completely independent. I'll double check.

Copy link
Contributor

Choose a reason for hiding this comment

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

You're probably right. I think they are independent.
But I also think that a missing SrvKeyspace is going to be a problem. And now that I think about it, there are some workflows where this has led to odd errors.
However, I think that's an orthogonal issue, and it's better to resolve that separately.

if err := agent.TopoServer.RebuildSrvVSchema(ctx, []string{agent.TabletAlias.Cell}); err != nil {
return vterrors.Wrap(err, "InitTablet failed to RebuildSrvVSchema")
}
}
case topo.IsErrType(err, topo.NoNode):
// There is no SrvSchema in this cell at all, so we definitely need to rebuild.
if err := agent.TopoServer.RebuildSrvVSchema(ctx, []string{agent.TabletAlias.Cell}); err != nil {
return vterrors.Wrap(err, "InitTablet failed to RebuildSrvVSchema")
}
default:
return vterrors.Wrap(err, "InitTablet failed to read SrvVSchema")
}

log.Infof("Initializing the tablet for type %v", tabletType)
Expand Down