Skip to content

Commit

Permalink
Merge pull request #6004 from planetscale/init-tablet-logging
Browse files Browse the repository at this point in the history
log during init tablet
  • Loading branch information
harshit-gangal authored Apr 3, 2020
2 parents e57c4e5 + cb5097e commit 87c8c0f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
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

0 comments on commit 87c8c0f

Please sign in to comment.