本文整理汇总了Golang中github.com/youtube/vitess/go/vt/topo.FindAllTabletAliasesInShard函数的典型用法代码示例。如果您正苦于以下问题:Golang FindAllTabletAliasesInShard函数的具体用法?Golang FindAllTabletAliasesInShard怎么用?Golang FindAllTabletAliasesInShard使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了FindAllTabletAliasesInShard函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: GetTabletMapForShard
// If error is not nil, the results in the dictionary are incomplete.
func GetTabletMapForShard(ts topo.Server, keyspace, shard string) (map[topo.TabletAlias]*topo.TabletInfo, error) {
aliases, err := topo.FindAllTabletAliasesInShard(ts, keyspace, shard)
if err != nil {
return nil, err
}
return GetTabletMap(ts, aliases)
}
示例2: findTargets
// findTargets phase:
// - find one rdonly in the source shard
// - mark it as 'checker' pointing back to us
// - get the aliases of all the targets
func (vscw *VerticalSplitCloneWorker) findTargets() error {
vscw.setState(stateVSCFindTargets)
// find an appropriate endpoint in the source shard
var err error
vscw.sourceAlias, err = findChecker(vscw.wr, vscw.cleaner, vscw.cell, vscw.sourceKeyspace, "0")
if err != nil {
return fmt.Errorf("cannot find checker for %v/%v/0: %v", vscw.cell, vscw.sourceKeyspace, err)
}
vscw.wr.Logger().Infof("Using tablet %v as the source", vscw.sourceAlias)
// get the tablet info for it
vscw.sourceTablet, err = vscw.wr.TopoServer().GetTablet(vscw.sourceAlias)
if err != nil {
return fmt.Errorf("cannot read tablet %v: %v", vscw.sourceTablet, err)
}
// stop replication on it
if err := vscw.wr.TabletManagerClient().StopSlave(vscw.sourceTablet, 30*time.Second); err != nil {
return fmt.Errorf("cannot stop replication on tablet %v", vscw.sourceAlias)
}
wrangler.RecordStartSlaveAction(vscw.cleaner, vscw.sourceTablet, 30*time.Second)
action, err := wrangler.FindChangeSlaveTypeActionByTarget(vscw.cleaner, vscw.sourceAlias)
if err != nil {
return fmt.Errorf("cannot find ChangeSlaveType action for %v: %v", vscw.sourceAlias, err)
}
action.TabletType = topo.TYPE_SPARE
// find all the targets in the destination keyspace / shard
vscw.destinationAliases, err = topo.FindAllTabletAliasesInShard(vscw.wr.TopoServer(), vscw.destinationKeyspace, vscw.destinationShard)
if err != nil {
return fmt.Errorf("cannot find all target tablets in %v/%v: %v", vscw.destinationKeyspace, vscw.destinationShard, err)
}
vscw.wr.Logger().Infof("Found %v target aliases", len(vscw.destinationAliases))
// get the TabletInfo for all targets
vscw.destinationTablets, err = topo.GetTabletMap(vscw.wr.TopoServer(), vscw.destinationAliases)
if err != nil {
return fmt.Errorf("cannot read all target tablets in %v/%v: %v", vscw.destinationKeyspace, vscw.destinationShard, err)
}
// find and validate the master
for tabletAlias, ti := range vscw.destinationTablets {
if ti.Type == topo.TYPE_MASTER {
if vscw.destinationMasterAlias.IsZero() {
vscw.destinationMasterAlias = tabletAlias
} else {
return fmt.Errorf("multiple masters in destination shard: %v and %v at least", vscw.destinationMasterAlias, tabletAlias)
}
}
}
if vscw.destinationMasterAlias.IsZero() {
return fmt.Errorf("no master in destination shard")
}
return nil
}
示例3: findTargets
// findTargets phase:
// - find one rdonly in the source shard
// - mark it as 'checker' pointing back to us
// - get the aliases of all the targets
func (scw *SplitCloneWorker) findTargets() error {
scw.setState(stateSCFindTargets)
var err error
// find an appropriate endpoint in the source shards
scw.sourceAliases = make([]topo.TabletAlias, len(scw.sourceShards))
for i, si := range scw.sourceShards {
scw.sourceAliases[i], err = findChecker(scw.wr, scw.cleaner, scw.cell, si.Keyspace(), si.ShardName())
if err != nil {
return fmt.Errorf("cannot find checker for %v/%v/%v: %v", scw.cell, si.Keyspace(), si.ShardName(), err)
}
scw.wr.Logger().Infof("Using tablet %v as source for %v/%v", scw.sourceAliases[i], si.Keyspace(), si.ShardName())
}
// get the tablet info for them
scw.sourceTablets = make([]*topo.TabletInfo, len(scw.sourceAliases))
for i, alias := range scw.sourceAliases {
scw.sourceTablets[i], err = scw.wr.TopoServer().GetTablet(alias)
if err != nil {
return fmt.Errorf("cannot read tablet %v: %v", alias, err)
}
}
// find all the targets in the destination shards
scw.destinationAliases = make([][]topo.TabletAlias, len(scw.destinationShards))
scw.destinationTablets = make([]map[topo.TabletAlias]*topo.TabletInfo, len(scw.destinationShards))
scw.destinationMasterAliases = make([]topo.TabletAlias, len(scw.destinationShards))
for shardIndex, si := range scw.destinationShards {
scw.destinationAliases[shardIndex], err = topo.FindAllTabletAliasesInShard(scw.wr.TopoServer(), si.Keyspace(), si.ShardName())
if err != nil {
return fmt.Errorf("cannot find all target tablets in %v/%v: %v", si.Keyspace(), si.ShardName(), err)
}
scw.wr.Logger().Infof("Found %v target aliases in shard %v/%v", len(scw.destinationAliases[shardIndex]), si.Keyspace(), si.ShardName())
// get the TabletInfo for all targets
scw.destinationTablets[shardIndex], err = topo.GetTabletMap(scw.wr.TopoServer(), scw.destinationAliases[shardIndex])
if err != nil {
return fmt.Errorf("cannot read all target tablets in %v/%v: %v", si.Keyspace(), si.ShardName(), err)
}
// find and validate the master
for tabletAlias, ti := range scw.destinationTablets[shardIndex] {
if ti.Type == topo.TYPE_MASTER {
if scw.destinationMasterAliases[shardIndex].IsZero() {
scw.destinationMasterAliases[shardIndex] = tabletAlias
} else {
return fmt.Errorf("multiple masters in destination shard: %v and %v at least", scw.destinationMasterAliases[shardIndex], tabletAlias)
}
}
}
if scw.destinationMasterAliases[shardIndex].IsZero() {
return fmt.Errorf("no master in destination shard")
}
}
return nil
}
示例4: validateShard
// FIXME(msolomon) This validate presumes the master is up and running.
// Even when that isn't true, there are validation processes that might be valuable.
func (wr *Wrangler) validateShard(ctx context.Context, keyspace, shard string, pingTablets bool, wg *sync.WaitGroup, results chan<- error) {
shardInfo, err := wr.ts.GetShard(ctx, keyspace, shard)
if err != nil {
results <- fmt.Errorf("TopologyServer.GetShard(%v, %v) failed: %v", keyspace, shard, err)
return
}
aliases, err := topo.FindAllTabletAliasesInShard(ctx, wr.ts, keyspace, shard)
if err != nil {
results <- fmt.Errorf("TopologyServer.FindAllTabletAliasesInShard(%v, %v) failed: %v", keyspace, shard, err)
return
}
tabletMap, _ := topo.GetTabletMap(ctx, wr.ts, aliases)
var masterAlias *pb.TabletAlias
for _, alias := range aliases {
tabletInfo, ok := tabletMap[*alias]
if !ok {
results <- fmt.Errorf("tablet %v not found in map", alias)
continue
}
if tabletInfo.Type == pb.TabletType_MASTER {
if masterAlias != nil {
results <- fmt.Errorf("shard %v/%v already has master %v but found other master %v", keyspace, shard, masterAlias, alias)
} else {
masterAlias = alias
}
}
}
if masterAlias == nil {
results <- fmt.Errorf("no master for shard %v/%v", keyspace, shard)
} else if !topo.TabletAliasEqual(shardInfo.MasterAlias, masterAlias) {
results <- fmt.Errorf("master mismatch for shard %v/%v: found %v, expected %v", keyspace, shard, masterAlias, shardInfo.MasterAlias)
}
for _, alias := range aliases {
wg.Add(1)
go func(alias *pb.TabletAlias) {
defer wg.Done()
if err := topo.Validate(ctx, wr.ts, alias); err != nil {
results <- fmt.Errorf("Validate(%v) failed: %v", alias, err)
} else {
wr.Logger().Infof("tablet %v is valid", alias)
}
}(alias)
}
if pingTablets {
wr.validateReplication(ctx, shardInfo, tabletMap, results)
wr.pingTablets(ctx, tabletMap, wg, results)
}
return
}
示例5: ShardMultiRestore
func (wr *Wrangler) ShardMultiRestore(keyspace, shard string, sources []topo.TabletAlias, tables []string, concurrency, fetchConcurrency, insertTableConcurrency, fetchRetryCount int, strategy string) error {
// check parameters
if len(tables) > 0 && len(sources) > 1 {
return fmt.Errorf("ShardMultiRestore can only handle one source when tables are specified")
}
// lock the shard to perform the changes we need done
actionNode := actionnode.ShardMultiRestore(&actionnode.MultiRestoreArgs{
SrcTabletAliases: sources,
Concurrency: concurrency,
FetchConcurrency: fetchConcurrency,
InsertTableConcurrency: insertTableConcurrency,
FetchRetryCount: fetchRetryCount,
Strategy: strategy})
lockPath, err := wr.lockShard(keyspace, shard, actionNode)
if err != nil {
return err
}
mrErr := wr.SetSourceShards(keyspace, shard, sources, tables)
err = wr.unlockShard(keyspace, shard, actionNode, lockPath, mrErr)
if err != nil {
if mrErr != nil {
log.Errorf("unlockShard got error back: %v", err)
return mrErr
}
return err
}
if mrErr != nil {
return mrErr
}
// find all tablets in the shard
destTablets, err := topo.FindAllTabletAliasesInShard(wr.ts, keyspace, shard)
if err != nil {
return err
}
// now launch MultiRestore on all tablets we need to do
rec := cc.AllErrorRecorder{}
wg := sync.WaitGroup{}
for _, tabletAlias := range destTablets {
wg.Add(1)
go func(tabletAlias topo.TabletAlias) {
log.Infof("Starting multirestore on tablet %v", tabletAlias)
err := wr.MultiRestore(tabletAlias, sources, concurrency, fetchConcurrency, insertTableConcurrency, fetchRetryCount, strategy)
log.Infof("Multirestore on tablet %v is done (err=%v)", tabletAlias, err)
rec.RecordError(err)
wg.Done()
}(tabletAlias)
}
wg.Wait()
return rec.Error()
}
示例6: ValidatePermissionsKeyspace
func (wr *Wrangler) ValidatePermissionsKeyspace(keyspace string) error {
// find all the shards
shards, err := wr.ts.GetShardNames(keyspace)
if err != nil {
return err
}
// corner cases
if len(shards) == 0 {
return fmt.Errorf("No shards in keyspace %v", keyspace)
}
sort.Strings(shards)
if len(shards) == 1 {
return wr.ValidatePermissionsShard(keyspace, shards[0])
}
// find the reference permissions using the first shard's master
si, err := wr.ts.GetShard(keyspace, shards[0])
if err != nil {
return err
}
if si.MasterAlias.Uid == topo.NO_TABLET {
return fmt.Errorf("No master in shard %v/%v", keyspace, shards[0])
}
referenceAlias := si.MasterAlias
log.Infof("Gathering permissions for reference master %v", referenceAlias)
referencePermissions, err := wr.GetPermissions(si.MasterAlias)
if err != nil {
return err
}
// then diff with all tablets but master 0
er := concurrency.AllErrorRecorder{}
wg := sync.WaitGroup{}
for _, shard := range shards {
aliases, err := topo.FindAllTabletAliasesInShard(wr.ts, keyspace, shard)
if err != nil {
er.RecordError(err)
continue
}
for _, alias := range aliases {
if alias == si.MasterAlias {
continue
}
wg.Add(1)
go wr.diffPermissions(referencePermissions, referenceAlias, alias, &wg, &er)
}
}
wg.Wait()
if er.HasErrors() {
return fmt.Errorf("Permissions diffs:\n%v", er.Error().Error())
}
return nil
}
示例7: ValidateVersionKeyspace
// ValidateVersionKeyspace validates all versions are the same in all
// tablets in a keyspace
func (wr *Wrangler) ValidateVersionKeyspace(ctx context.Context, keyspace string) error {
// find all the shards
shards, err := wr.ts.GetShardNames(ctx, keyspace)
if err != nil {
return err
}
// corner cases
if len(shards) == 0 {
return fmt.Errorf("No shards in keyspace %v", keyspace)
}
sort.Strings(shards)
if len(shards) == 1 {
return wr.ValidateVersionShard(ctx, keyspace, shards[0])
}
// find the reference version using the first shard's master
si, err := wr.ts.GetShard(ctx, keyspace, shards[0])
if err != nil {
return err
}
if topo.TabletAliasIsZero(si.MasterAlias) {
return fmt.Errorf("No master in shard %v/%v", keyspace, shards[0])
}
referenceAlias := si.MasterAlias
log.Infof("Gathering version for reference master %v", topo.TabletAliasString(referenceAlias))
referenceVersion, err := wr.GetVersion(ctx, referenceAlias)
if err != nil {
return err
}
// then diff with all tablets but master 0
er := concurrency.AllErrorRecorder{}
wg := sync.WaitGroup{}
for _, shard := range shards {
aliases, err := topo.FindAllTabletAliasesInShard(ctx, wr.ts, keyspace, shard)
if err != nil {
er.RecordError(err)
continue
}
for _, alias := range aliases {
if topo.TabletAliasEqual(alias, si.MasterAlias) {
continue
}
wg.Add(1)
go wr.diffVersion(ctx, referenceVersion, referenceAlias, alias, &wg, &er)
}
}
wg.Wait()
if er.HasErrors() {
return fmt.Errorf("Version diffs:\n%v", er.Error().Error())
}
return nil
}
示例8: validateShard
// FIXME(msolomon) This validate presumes the master is up and running.
// Even when that isn't true, there are validation processes that might be valuable.
func (wr *Wrangler) validateShard(keyspace, shard string, pingTablets bool, wg *sync.WaitGroup, results chan<- vresult) {
shardInfo, err := wr.ts.GetShard(keyspace, shard)
if err != nil {
results <- vresult{keyspace + "/" + shard, err}
return
}
aliases, err := topo.FindAllTabletAliasesInShard(wr.ts, keyspace, shard)
if err != nil {
results <- vresult{keyspace + "/" + shard, err}
}
tabletMap, _ := GetTabletMap(wr.ts, aliases)
var masterAlias topo.TabletAlias
for _, alias := range aliases {
tabletInfo, ok := tabletMap[alias]
if !ok {
results <- vresult{alias.String(), fmt.Errorf("tablet not found in map")}
continue
}
if tabletInfo.Parent.Uid == topo.NO_TABLET {
if masterAlias.Cell != "" {
results <- vresult{alias.String(), fmt.Errorf("tablet already has a master %v", masterAlias)}
} else {
masterAlias = alias
}
}
}
if masterAlias.Cell == "" {
results <- vresult{keyspace + "/" + shard, fmt.Errorf("no master for shard")}
} else if shardInfo.MasterAlias != masterAlias {
results <- vresult{keyspace + "/" + shard, fmt.Errorf("master mismatch for shard: found %v, expected %v", masterAlias, shardInfo.MasterAlias)}
}
for _, alias := range aliases {
tabletReplicationPath := masterAlias.String()
if alias != masterAlias {
tabletReplicationPath += "/" + alias.String()
}
wg.Add(1)
go func(alias topo.TabletAlias) {
results <- vresult{tabletReplicationPath, topo.Validate(wr.ts, alias, tabletReplicationPath)}
wg.Done()
}(alias)
}
if pingTablets {
wr.validateReplication(shardInfo, tabletMap, results)
wr.pingTablets(tabletMap, wg, results)
}
return
}
示例9: applySchemaShard
func (wr *Wrangler) applySchemaShard(ctx context.Context, shardInfo *topo.ShardInfo, preflight *myproto.SchemaChangeResult, masterTabletAlias *pb.TabletAlias, change string, newParentTabletAlias *pb.TabletAlias, simple, force bool, waitSlaveTimeout time.Duration) (*myproto.SchemaChangeResult, error) {
// find all the shards we need to handle
aliases, err := topo.FindAllTabletAliasesInShard(ctx, wr.ts, 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.Alias, status.lastError)
}
}
// simple or complex?
if simple {
return wr.applySchemaShardSimple(ctx, statusArray, preflight, masterTabletAlias, change, force)
}
return wr.applySchemaShardComplex(ctx, statusArray, shardInfo, preflight, masterTabletAlias, change, newParentTabletAlias, force, waitSlaveTimeout)
}
示例10: GetTabletMapForShard
// GetTabletMapForShard returns the tablets for a shard. It can return
// topo.ErrPartialResult if it couldn't read all the cells, or all
// the individual tablets, in which case the map is valid, but partial.
func GetTabletMapForShard(ts topo.Server, keyspace, shard string) (map[topo.TabletAlias]*topo.TabletInfo, error) {
// if we get a partial result, we keep going. It most likely means
// a cell is out of commission.
aliases, err := topo.FindAllTabletAliasesInShard(ts, keyspace, shard)
if err != nil && err != topo.ErrPartialResult {
return nil, err
}
// get the tablets for the cells we were able to reach, forward
// topo.ErrPartialResult from FindAllTabletAliasesInShard
result, gerr := GetTabletMap(ts, aliases)
if gerr == nil && err != nil {
gerr = err
}
return result, gerr
}
示例11: validateAllTablets
// Validate all tablets in all discoverable cells, even if they are
// not in the replication graph.
func (wr *Wrangler) validateAllTablets(ctx context.Context, wg *sync.WaitGroup, results chan<- error) {
cellSet := make(map[string]bool, 16)
keyspaces, err := wr.ts.GetKeyspaces(ctx)
if err != nil {
results <- fmt.Errorf("TopologyServer.GetKeyspaces failed: %v", err)
return
}
for _, keyspace := range keyspaces {
shards, err := wr.ts.GetShardNames(ctx, keyspace)
if err != nil {
results <- fmt.Errorf("TopologyServer.GetShardNames(%v) failed: %v", keyspace, err)
return
}
for _, shard := range shards {
aliases, err := topo.FindAllTabletAliasesInShard(ctx, wr.ts, keyspace, shard)
if err != nil {
results <- fmt.Errorf("TopologyServer.FindAllTabletAliasesInShard(%v, %v) failed: %v", keyspace, shard, err)
return
}
for _, alias := range aliases {
cellSet[alias.Cell] = true
}
}
}
for cell := range cellSet {
aliases, err := wr.ts.GetTabletsByCell(ctx, cell)
if err != nil {
results <- fmt.Errorf("TopologyServer.GetTabletsByCell(%v) failed: %v", cell, err)
continue
}
for _, alias := range aliases {
wg.Add(1)
go func(alias *pb.TabletAlias) {
defer wg.Done()
if err := topo.Validate(ctx, wr.ts, alias); err != nil {
results <- fmt.Errorf("Validate(%v) failed: %v", alias, err)
} else {
wr.Logger().Infof("tablet %v is valid", alias)
}
}(alias)
}
}
}
示例12: ShardMultiRestore
func (wr *Wrangler) ShardMultiRestore(keyspace, shard string, sources []topo.TabletAlias, concurrency, fetchConcurrency, insertTableConcurrency, fetchRetryCount int, strategy string) error {
// lock the shard to perform the changes we need done
actionNode := wr.ai.ShardMultiRestore(&tm.MultiRestoreArgs{
SrcTabletAliases: sources,
Concurrency: concurrency,
FetchConcurrency: fetchConcurrency,
InsertTableConcurrency: insertTableConcurrency,
FetchRetryCount: fetchRetryCount,
Strategy: strategy})
lockPath, err := wr.lockShard(keyspace, shard, actionNode)
if err != nil {
return err
}
mrErr := wr.shardMultiRestore(keyspace, shard, sources, concurrency, fetchConcurrency, insertTableConcurrency, fetchRetryCount, strategy)
err = wr.unlockShard(keyspace, shard, actionNode, lockPath, mrErr)
if err != nil {
return err
}
if mrErr != nil {
return mrErr
}
// find all tablets in the shard
destTablets, err := topo.FindAllTabletAliasesInShard(wr.ts, keyspace, shard)
if err != nil {
return err
}
// now launch MultiRestore on all tablets we need to do
rec := cc.AllErrorRecorder{}
wg := sync.WaitGroup{}
for _, tabletAlias := range destTablets {
wg.Add(1)
go func(tabletAlias topo.TabletAlias) {
log.Infof("Starting multirestore on tablet %v", tabletAlias)
err := wr.MultiRestore(tabletAlias, sources, concurrency, fetchConcurrency, insertTableConcurrency, fetchRetryCount, strategy)
log.Infof("Multirestore on tablet %v is done (err=%v)", tabletAlias, err)
rec.RecordError(err)
wg.Done()
}(tabletAlias)
}
wg.Wait()
return rec.Error()
}
示例13: validateAllTablets
// Validate all tablets in all discoverable cells, even if they are
// not in the replication graph.
func (wr *Wrangler) validateAllTablets(wg *sync.WaitGroup, results chan<- vresult) {
cellSet := make(map[string]bool, 16)
keyspaces, err := wr.ts.GetKeyspaces()
if err != nil {
results <- vresult{"TopologyServer.GetKeyspaces", err}
return
}
for _, keyspace := range keyspaces {
shards, err := wr.ts.GetShardNames(keyspace)
if err != nil {
results <- vresult{"TopologyServer.GetShardNames(" + keyspace + ")", err}
return
}
for _, shard := range shards {
aliases, err := topo.FindAllTabletAliasesInShard(wr.ts, keyspace, shard)
if err != nil {
results <- vresult{"TopologyServer.FindAllTabletAliasesInShard(" + keyspace + "," + shard + ")", err}
return
}
for _, alias := range aliases {
cellSet[alias.Cell] = true
}
}
}
for cell := range cellSet {
aliases, err := wr.ts.GetTabletsByCell(cell)
if err != nil {
results <- vresult{"GetTabletsByCell(" + cell + ")", err}
} else {
for _, alias := range aliases {
wg.Add(1)
go func(alias topo.TabletAlias) {
results <- vresult{alias.String(), topo.Validate(wr.ts, alias)}
wg.Done()
}(alias)
}
}
}
}
示例14: resolveReloadTabletsForShard
// Does a topo lookup for a single shard, and returns:
// 1. Slice of all tablet aliases for the shard.
// 2. Map of tablet alias : tablet record for all tablets.
func resolveReloadTabletsForShard(ctx context.Context, keyspace, shard string, wr *wrangler.Wrangler) (reloadAliases []topo.TabletAlias, reloadTablets map[topo.TabletAlias]*topo.TabletInfo, err error) {
// Keep a long timeout, because we really don't want the copying to succeed, and then the worker to fail at the end.
shortCtx, cancel := context.WithTimeout(ctx, 5*time.Minute)
reloadAliases, err = topo.FindAllTabletAliasesInShard(shortCtx, wr.TopoServer(), keyspace, shard)
cancel()
if err != nil {
return nil, nil, fmt.Errorf("cannot find all reload target tablets in %v/%v: %v", keyspace, shard, err)
}
wr.Logger().Infof("Found %v reload target aliases in shard %v/%v", len(reloadAliases), keyspace, shard)
shortCtx, cancel = context.WithTimeout(ctx, 5*time.Minute)
reloadTablets, err = topo.GetTabletMap(shortCtx, wr.TopoServer(), reloadAliases)
cancel()
if err != nil {
return nil, nil, fmt.Errorf("cannot read all reload target tablets in %v/%v: %v",
keyspace, shard, err)
}
return reloadAliases, reloadTablets, nil
}
示例15: ValidateVersionShard
// ValidateVersionShard validates all versions are the same in all
// tablets in a shard
func (wr *Wrangler) ValidateVersionShard(ctx context.Context, keyspace, shard string) error {
si, err := wr.ts.GetShard(ctx, keyspace, shard)
if err != nil {
return err
}
// get version from the master, or error
if topo.TabletAliasIsZero(si.MasterAlias) {
return fmt.Errorf("No master in shard %v/%v", keyspace, shard)
}
log.Infof("Gathering version for master %v", topo.TabletAliasString(si.MasterAlias))
masterVersion, err := wr.GetVersion(ctx, si.MasterAlias)
if err != nil {
return err
}
// read all the aliases in the shard, that is all tablets that are
// replicating from the master
aliases, err := topo.FindAllTabletAliasesInShard(ctx, wr.ts, keyspace, shard)
if err != nil {
return err
}
// then diff with all slaves
er := concurrency.AllErrorRecorder{}
wg := sync.WaitGroup{}
for _, alias := range aliases {
if topo.TabletAliasEqual(alias, si.MasterAlias) {
continue
}
wg.Add(1)
go wr.diffVersion(ctx, masterVersion, si.MasterAlias, alias, &wg, &er)
}
wg.Wait()
if er.HasErrors() {
return fmt.Errorf("Version diffs:\n%v", er.Error().Error())
}
return nil
}