vtctl: Remove old, now unused, ApplySchemaShard code.

This commit is contained in:
Michael Berlin 2016-01-12 00:50:42 +01:00
Родитель 1a714be962
Коммит 00117b48ff
3 изменённых файлов: 0 добавлений и 142 удалений

Просмотреть файл

@ -180,9 +180,6 @@ const (
// shard-wide actions.
ShardActionCheck = "CheckShard"
// ShardActionApplySchema applies a schema change on an entire shard
ShardActionApplySchema = "ApplySchemaShard"
// ShardActionSetServedTypes changes the ServedTypes inside a shard
ShardActionSetServedTypes = "SetShardServedTypes"

Просмотреть файл

@ -26,12 +26,6 @@ type SlaveWasRestartedArgs struct {
// shard action node structures
// ApplySchemaShardArgs is the payload for ApplySchemaShard
type ApplySchemaShardArgs struct {
MasterTabletAlias *topodatapb.TabletAlias
Change string
}
// SetShardServedTypesArgs is the payload for SetShardServedTypes
type SetShardServedTypesArgs struct {
Cells []string
@ -96,17 +90,6 @@ func CheckShard() *ActionNode {
}).SetGuid()
}
// ApplySchemaShard returns an ActionNode
func ApplySchemaShard(masterTabletAlias *topodatapb.TabletAlias, change string) *ActionNode {
return (&ActionNode{
Action: ShardActionApplySchema,
Args: &ApplySchemaShardArgs{
MasterTabletAlias: masterTabletAlias,
Change: change,
},
}).SetGuid()
}
// SetShardServedTypes returns an ActionNode
func SetShardServedTypes(cells []string, servedType topodatapb.TabletType) *ActionNode {
return (&ActionNode{

Просмотреть файл

@ -9,7 +9,6 @@ import (
"fmt"
"html/template"
"sort"
"strings"
"sync"
"time"
@ -195,127 +194,6 @@ func (wr *Wrangler) PreflightSchema(ctx context.Context, tabletAlias *topodatapb
return wr.tmc.PreflightSchema(ctx, ti, change)
}
// ApplySchema will apply a schema change on the remote tablet.
func (wr *Wrangler) ApplySchema(ctx context.Context, tabletAlias *topodatapb.TabletAlias, sc *tmutils.SchemaChange) (*tmutils.SchemaChangeResult, error) {
ti, err := wr.ts.GetTablet(ctx, tabletAlias)
if err != nil {
return nil, err
}
return wr.tmc.ApplySchema(ctx, ti, sc)
}
// ApplySchemaShard applies a schema change on a shard.
func (wr *Wrangler) ApplySchemaShard(ctx context.Context, keyspace, shard, change string, newParentTabletAlias *topodatapb.TabletAlias, force bool, waitSlaveTimeout time.Duration) (*tmutils.SchemaChangeResult, error) {
// read the shard
shardInfo, err := wr.ts.GetShard(ctx, keyspace, shard)
if err != nil {
return nil, err
}
// preflight on the master, to get baseline
// this assumes the master doesn't have the schema upgrade applied
// If the master does, and some slaves don't, may have to
// fix them manually one at a time, or re-clone them.
// we do this outside of the shard lock because we can.
log.Infof("Running Preflight on Master %v", shardInfo.MasterAlias)
if err != nil {
return nil, err
}
preflight, err := wr.PreflightSchema(ctx, shardInfo.MasterAlias, change)
if err != nil {
return nil, err
}
return wr.lockAndApplySchemaShard(ctx, shardInfo, preflight, keyspace, shard, shardInfo.MasterAlias, change, newParentTabletAlias, force, waitSlaveTimeout)
}
func (wr *Wrangler) lockAndApplySchemaShard(ctx context.Context, shardInfo *topo.ShardInfo, preflight *tmutils.SchemaChangeResult, keyspace, shard string, masterTabletAlias *topodatapb.TabletAlias, change string, newParentTabletAlias *topodatapb.TabletAlias, force bool, waitSlaveTimeout time.Duration) (*tmutils.SchemaChangeResult, error) {
// get a shard lock
actionNode := actionnode.ApplySchemaShard(masterTabletAlias, change)
lockPath, err := wr.lockShard(ctx, keyspace, shard, actionNode)
if err != nil {
return nil, err
}
scr, err := wr.applySchemaShard(ctx, shardInfo, preflight, masterTabletAlias, change, newParentTabletAlias, force, waitSlaveTimeout)
return scr, wr.unlockShard(ctx, keyspace, shard, actionNode, lockPath, err)
}
// tabletStatus is a local structure used to keep track of what we're doing
type tabletStatus struct {
ti *topo.TabletInfo
lastError error
beforeSchema *tabletmanagerdatapb.SchemaDefinition
}
func (wr *Wrangler) applySchemaShard(ctx context.Context, shardInfo *topo.ShardInfo, preflight *tmutils.SchemaChangeResult, masterTabletAlias *topodatapb.TabletAlias, change string, newParentTabletAlias *topodatapb.TabletAlias, force bool, waitSlaveTimeout time.Duration) (*tmutils.SchemaChangeResult, error) {
// find all the shards we need to handle
aliases, err := wr.ts.FindAllTabletAliasesInShard(ctx, shardInfo.Keyspace(), shardInfo.ShardName())
if err != nil {
return nil, err
}
// build the array of tabletStatus we're going to use
statusArray := make([]*tabletStatus, 0, len(aliases)-1)
for _, alias := range aliases {
if alias == masterTabletAlias {
// we skip the master
continue
}
ti, err := wr.ts.GetTablet(ctx, alias)
if err != nil {
return nil, err
}
statusArray = append(statusArray, &tabletStatus{ti: ti})
}
// get schema on all tablets.
log.Infof("Getting schema on all tablets for shard %v/%v", shardInfo.Keyspace(), shardInfo.ShardName())
wg := &sync.WaitGroup{}
for _, status := range statusArray {
wg.Add(1)
go func(status *tabletStatus) {
status.beforeSchema, status.lastError = wr.tmc.GetSchema(ctx, status.ti, nil, nil, false)
wg.Done()
}(status)
}
wg.Wait()
// quick check for errors
for _, status := range statusArray {
if status.lastError != nil {
return nil, fmt.Errorf("Error getting schema on tablet %v: %v", status.ti.AliasString(), status.lastError)
}
}
// check all tablets have the same schema as the master's
// BeforeSchema. If not, we shouldn't proceed
log.Infof("Checking schema on all tablets")
for _, status := range statusArray {
diffs := tmutils.DiffSchemaToArray("master", preflight.BeforeSchema, topoproto.TabletAliasString(status.ti.Alias), status.beforeSchema)
if len(diffs) > 0 {
if force {
log.Warningf("Tablet %v has inconsistent schema, ignoring: %v", status.ti.AliasString(), strings.Join(diffs, "\n"))
} else {
return nil, fmt.Errorf("Tablet %v has inconsistent schema: %v", status.ti.AliasString(), strings.Join(diffs, "\n"))
}
}
}
// we're good, just send to the master
log.Infof("Applying schema change to master")
sc := &tmutils.SchemaChange{
SQL: change,
Force: force,
AllowReplication: true,
BeforeSchema: preflight.BeforeSchema,
AfterSchema: preflight.AfterSchema,
}
return wr.ApplySchema(ctx, masterTabletAlias, sc)
}
// ApplySchemaKeyspace applies a schema change to an entire keyspace.
// take a keyspace lock to do this.
// first we will validate the Preflight works the same on all shard masters