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

log during init tablet #6004

Merged
merged 1 commit into from
Apr 3, 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
5 changes: 5 additions & 0 deletions go/vt/topo/shard.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,28 +326,33 @@ func (ts *Server) CreateShard(ctx context.Context, keyspace, shard string) (err
// GetOrCreateShard will return the shard object, or create one if it doesn't
// already exist. Note the shard creation is protected by a keyspace Lock.
func (ts *Server) GetOrCreateShard(ctx context.Context, keyspace, shard string) (si *ShardInfo, err error) {
log.Info("GetShard %s/%s", keyspace, shard)
si, err = ts.GetShard(ctx, keyspace, shard)
if !IsErrType(err, NoNode) {
return
}

// create the keyspace, maybe it already exists
log.Info("CreateKeyspace %s/%s", keyspace, shard)
if err = ts.CreateKeyspace(ctx, keyspace, &topodatapb.Keyspace{}); err != nil && !IsErrType(err, NodeExists) {
return nil, vterrors.Wrapf(err, "CreateKeyspace(%v) failed", keyspace)
}

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

// now try to create with the lock, may already exist
log.Info("CreateShard %s/%s", keyspace, shard)
if err = ts.CreateShard(ctx, keyspace, shard); err != nil && !IsErrType(err, NodeExists) {
return nil, vterrors.Wrapf(err, "CreateShard(%v/%v) failed", keyspace, shard)
}

// try to read the shard again, maybe someone created it
// in between the original GetShard and the LockKeyspace
log.Info("GetShard %s/%s", keyspace, shard)
return ts.GetShard(ctx, keyspace, shard)
}

Expand Down
7 changes: 7 additions & 0 deletions go/vt/topo/vschema.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,15 @@ func (ts *Server) SaveVSchema(ctx context.Context, keyspace string, vschema *vsc
}

_, err = ts.globalCell.Update(ctx, nodePath, data, nil)
if err != nil {
log.Info("successfully updated vschema for keyspace %s: %v", keyspace, data)
}
return err
}

// DeleteVSchema delete the keyspace if it exists
func (ts *Server) DeleteVSchema(ctx context.Context, keyspace string) error {
log.Info("deleting vschema for keyspace %s", keyspace)
nodePath := path.Join(KeyspacesPath, keyspace, VSchemaFile)
return ts.globalCell.Delete(ctx, nodePath, nil)
}
Expand All @@ -70,6 +74,9 @@ 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) 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)
}
if vschema == nil || IsErrType(err, NoNode) {
err = ts.SaveVSchema(ctx, keyspace, &vschemapb.Keyspace{
Sharded: false,
Expand Down