本文整理汇总了Golang中github.com/youtube/vitess/go/vt/topo.UpdateTablet函数的典型用法代码示例。如果您正苦于以下问题:Golang UpdateTablet函数的具体用法?Golang UpdateTablet怎么用?Golang UpdateTablet使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了UpdateTablet函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: prepareToSnapshot
// prepareToSnapshot changes the type of the tablet to backup (when
// the original type is master, it will proceed only if
// forceMasterSnapshot is true). It returns a function that will
// restore the original state.
func (wr *Wrangler) prepareToSnapshot(ti *topo.TabletInfo, forceMasterSnapshot bool) (restoreAfterSnapshot func() error, err error) {
originalType := ti.Tablet.Type
if ti.Tablet.Type == topo.TYPE_MASTER && forceMasterSnapshot {
// In this case, we don't bother recomputing the serving graph.
// All queries will have to fail anyway.
log.Infof("force change type master -> backup: %v", ti.Alias)
// There is a legitimate reason to force in the case of a single
// master.
ti.Tablet.Type = topo.TYPE_BACKUP
err = topo.UpdateTablet(wr.ts, ti)
} else {
err = wr.ChangeType(ti.Alias, topo.TYPE_BACKUP, false)
}
if err != nil {
return
}
restoreAfterSnapshot = func() (err error) {
log.Infof("change type after snapshot: %v %v", ti.Alias, originalType)
if ti.Tablet.Parent.Uid == topo.NO_TABLET && forceMasterSnapshot {
log.Infof("force change type backup -> master: %v", ti.Alias)
ti.Tablet.Type = topo.TYPE_MASTER
return topo.UpdateTablet(wr.ts, ti)
}
return wr.ChangeType(ti.Alias, originalType, false)
}
return
}
开发者ID:chinna1986,项目名称:vitess,代码行数:37,代码来源:split.go
示例2: multiRestore
func (ta *TabletActor) multiRestore(actionNode *actionnode.ActionNode) (err error) {
args := actionNode.Args.(*actionnode.MultiRestoreArgs)
// read our current tablet, verify its state
// we only support restoring to the master or spare replicas
tablet, err := ta.ts.GetTablet(ta.tabletAlias)
if err != nil {
return err
}
if tablet.Type != topo.TYPE_MASTER && tablet.Type != topo.TYPE_SPARE && tablet.Type != topo.TYPE_REPLICA && tablet.Type != topo.TYPE_RDONLY {
return fmt.Errorf("expected master, spare replica or rdonly type, not %v: %v", tablet.Type, ta.tabletAlias)
}
// get source tablets addresses
sourceAddrs := make([]*url.URL, len(args.SrcTabletAliases))
keyRanges := make([]key.KeyRange, len(args.SrcTabletAliases))
for i, alias := range args.SrcTabletAliases {
t, e := ta.ts.GetTablet(alias)
if e != nil {
return e
}
sourceAddrs[i] = &url.URL{Host: t.GetAddr(), Path: "/" + t.DbName()}
keyRanges[i], e = key.KeyRangesOverlap(tablet.KeyRange, t.KeyRange)
if e != nil {
return e
}
}
// change type to restore, no change to replication graph
originalType := tablet.Type
tablet.Type = topo.TYPE_RESTORE
err = topo.UpdateTablet(ta.ts, tablet)
if err != nil {
return err
}
// run the action, scrap if it fails
if err := ta.mysqld.MultiRestore(tablet.DbName(), keyRanges, sourceAddrs, args.Concurrency, args.FetchConcurrency, args.InsertTableConcurrency, args.FetchRetryCount, args.Strategy); err != nil {
if e := Scrap(ta.ts, ta.tabletAlias, false); e != nil {
log.Errorf("Failed to Scrap after failed RestoreFromMultiSnapshot: %v", e)
}
return err
}
// restore type back
tablet.Type = originalType
return topo.UpdateTablet(ta.ts, tablet)
}
开发者ID:rjammala,项目名称:vitess,代码行数:48,代码来源:actor.go
示例3: SnapshotSourceEnd
// SnapshotSourceEnd restores the state of the server after a
// Snapshot(server_mode =true)
// Should be called under RpcWrapLockAction.
func (agent *ActionAgent) SnapshotSourceEnd(args *actionnode.SnapshotSourceEndArgs) error {
tablet, err := agent.TopoServer.GetTablet(agent.TabletAlias)
if err != nil {
return err
}
if tablet.Type != topo.TYPE_SNAPSHOT_SOURCE {
return fmt.Errorf("expected snapshot_source type, not %v", tablet.Type)
}
if err := agent.Mysqld.SnapshotSourceEnd(args.SlaveStartRequired, args.ReadOnly, true, agent.hookExtraEnv()); err != nil {
log.Errorf("SnapshotSourceEnd failed, leaving tablet type alone: %v", err)
return err
}
// change the type back
if args.OriginalType == topo.TYPE_MASTER {
// force the master update
tablet.Tablet.Type = topo.TYPE_MASTER
err = topo.UpdateTablet(agent.TopoServer, tablet)
} else {
err = topotools.ChangeType(agent.TopoServer, tablet.Alias, args.OriginalType, make(map[string]string), true /*runHooks*/)
}
return err
}
开发者ID:plobsing,项目名称:vitess,代码行数:28,代码来源:agent_rpc_actions.go
示例4: SnapshotSourceEnd
func (wr *Wrangler) SnapshotSourceEnd(tabletAlias topo.TabletAlias, slaveStartRequired, readWrite bool, originalType topo.TabletType) (err error) {
var ti *topo.TabletInfo
ti, err = wr.ts.GetTablet(tabletAlias)
if err != nil {
return
}
var actionPath string
actionPath, err = wr.ai.SnapshotSourceEnd(tabletAlias, &tm.SnapshotSourceEndArgs{slaveStartRequired, !readWrite})
if err != nil {
return
}
// wait for completion, and save the error
err = wr.ai.WaitForCompletion(actionPath, wr.actionTimeout())
if err != nil {
log.Errorf("SnapshotSourceEnd failed (%v), leaving tablet type alone", err)
return
}
if ti.Tablet.Parent.Uid == topo.NO_TABLET {
ti.Tablet.Type = topo.TYPE_MASTER
err = topo.UpdateTablet(wr.ts, ti)
} else {
err = wr.ChangeType(ti.Alias(), originalType, false)
}
return err
}
开发者ID:johnvilsack,项目名称:golang-stuff,代码行数:29,代码来源:clone.go
示例5: ChangeType
// ChangeType changes the type of the tablet and possibly also updates
// the health informaton for it. Make this external, since these
// transitions need to be forced from time to time.
//
// - if health is nil, we don't touch the Tablet's Health record.
// - if health is an empty map, we clear the Tablet's Health record.
// - if health has values, we overwrite the Tablet's Health record.
func ChangeType(ctx context.Context, ts topo.Server, tabletAlias topo.TabletAlias, newType topo.TabletType, health map[string]string) error {
tablet, err := ts.GetTablet(ctx, tabletAlias)
if err != nil {
return err
}
if !topo.IsTrivialTypeChange(tablet.Type, newType) {
return fmt.Errorf("cannot change tablet type %v -> %v %v", tablet.Type, newType, tabletAlias)
}
tablet.Type = newType
if newType == topo.TYPE_IDLE {
tablet.Keyspace = ""
tablet.Shard = ""
tablet.KeyRange = key.KeyRange{}
tablet.Health = health
}
if health != nil {
if len(health) == 0 {
tablet.Health = nil
} else {
tablet.Health = health
}
}
return topo.UpdateTablet(ctx, ts, tablet)
}
开发者ID:pranjal5215,项目名称:vitess,代码行数:33,代码来源:tablet.go
示例6: SlaveWasRestarted
func SlaveWasRestarted(ts topo.Server, tabletAlias topo.TabletAlias, swrd *actionnode.SlaveWasRestartedArgs) error {
tablet, err := ts.GetTablet(tabletAlias)
if err != nil {
return err
}
// Once this action completes, update authoritive tablet node first.
tablet.Parent = swrd.Parent
if tablet.Type == topo.TYPE_MASTER {
tablet.Type = topo.TYPE_SPARE
tablet.State = topo.STATE_READ_ONLY
}
err = topo.UpdateTablet(ts, tablet)
if err != nil {
return err
}
// Update the new tablet location in the replication graph now that
// we've updated the tablet.
err = topo.CreateTabletReplicationData(ts, tablet.Tablet)
if err != nil && err != topo.ErrNodeExists {
return err
}
return nil
}
开发者ID:nettedfish,项目名称:vitess,代码行数:26,代码来源:actor.go
示例7: updateReplicationGraphForPromotedSlave
func (ta *TabletActor) updateReplicationGraphForPromotedSlave(tablet *topo.TabletInfo, actionNode *ActionNode) error {
// Remove tablet from the replication graph if this is not already the master.
if tablet.Parent.Uid != topo.NO_TABLET {
err := ta.ts.DeleteReplicationPath(tablet.Keyspace, tablet.Shard, tablet.ReplicationPath())
if err != nil && err != topo.ErrNoNode {
return err
}
}
// Update tablet regardless - trend towards consistency.
tablet.State = topo.STATE_READ_WRITE
tablet.Type = topo.TYPE_MASTER
tablet.Parent.Cell = ""
tablet.Parent.Uid = topo.NO_TABLET
err := topo.UpdateTablet(ta.ts, tablet)
if err != nil {
return err
}
// NOTE(msolomon) A serving graph update is required, but in order for the
// shard to be consistent the master must be scrapped first. That is
// externally coordinated by the wrangler reparent action.
// Insert the new tablet location in the replication graph now that
// we've updated the tablet.
err = ta.ts.CreateReplicationPath(tablet.Keyspace, tablet.Shard, tablet.ReplicationPath())
if err != nil && err != topo.ErrNodeExists {
return err
}
return nil
}
开发者ID:rrudduck,项目名称:golang-stuff,代码行数:30,代码来源:actor.go
示例8: updateReplicationGraphForPromotedSlave
func updateReplicationGraphForPromotedSlave(ts topo.Server, tablet *topo.TabletInfo) error {
// Remove tablet from the replication graph if this is not already the master.
if tablet.Parent.Uid != topo.NO_TABLET {
if err := topo.DeleteTabletReplicationData(ts, tablet.Tablet); err != nil && err != topo.ErrNoNode {
return err
}
}
// Update tablet regardless - trend towards consistency.
tablet.State = topo.STATE_READ_WRITE
tablet.Type = topo.TYPE_MASTER
tablet.Parent.Cell = ""
tablet.Parent.Uid = topo.NO_TABLET
tablet.Health = nil
err := topo.UpdateTablet(ts, tablet)
if err != nil {
return err
}
// NOTE(msolomon) A serving graph update is required, but in
// order for the shard to be consistent the old master must be
// scrapped first. That is externally coordinated by the
// wrangler reparent action.
// Insert the new tablet location in the replication graph now that
// we've updated the tablet.
err = topo.CreateTabletReplicationData(ts, tablet.Tablet)
if err != nil && err != topo.ErrNodeExists {
return err
}
return nil
}
开发者ID:chinna1986,项目名称:vitess,代码行数:32,代码来源:actor.go
示例9: SetBlacklistedTables
// Make this external, since these transitions need to be forced from time to time.
func SetBlacklistedTables(ts topo.Server, tabletAlias topo.TabletAlias, tables []string) error {
tablet, err := ts.GetTablet(tabletAlias)
if err != nil {
return err
}
tablet.BlacklistedTables = tables
return topo.UpdateTablet(ts, tablet)
}
开发者ID:nettedfish,项目名称:vitess,代码行数:10,代码来源:actor.go
示例10: ChangeType
// Make this external, since these transitions need to be forced from time to time.
func ChangeType(ts topo.Server, tabletAlias topo.TabletAlias, newType topo.TabletType, runHooks bool) error {
tablet, err := ts.GetTablet(tabletAlias)
if err != nil {
return err
}
if !topo.IsTrivialTypeChange(tablet.Type, newType) || !topo.IsValidTypeChange(tablet.Type, newType) {
return fmt.Errorf("cannot change tablet type %v -> %v %v", tablet.Type, newType, tabletAlias)
}
if runHooks {
// Only run the preflight_serving_type hook when
// transitioning from non-serving to serving.
if !topo.IsInServingGraph(tablet.Type) && topo.IsInServingGraph(newType) {
if err := hook.NewSimpleHook("preflight_serving_type").ExecuteOptional(); err != nil {
return err
}
}
}
tablet.Type = newType
if newType == topo.TYPE_IDLE {
if tablet.Parent.IsZero() {
si, err := ts.GetShard(tablet.Keyspace, tablet.Shard)
if err != nil {
return err
}
rec := concurrency.AllErrorRecorder{}
wg := sync.WaitGroup{}
for _, cell := range si.Cells {
wg.Add(1)
go func(cell string) {
defer wg.Done()
sri, err := ts.GetShardReplication(cell, tablet.Keyspace, tablet.Shard)
if err != nil {
log.Warningf("Cannot check cell %v for extra replication paths, assuming it's good", cell)
return
}
for _, rl := range sri.ReplicationLinks {
if rl.Parent == tabletAlias {
rec.RecordError(fmt.Errorf("Still have a ReplicationLink in cell %v", cell))
}
}
}(cell)
}
wg.Wait()
if rec.HasErrors() {
return rec.Error()
}
}
tablet.Parent = topo.TabletAlias{}
tablet.Keyspace = ""
tablet.Shard = ""
tablet.KeyRange = key.KeyRange{}
}
return topo.UpdateTablet(ts, tablet)
}
开发者ID:rjammala,项目名称:vitess,代码行数:58,代码来源:actor.go
示例11: SlaveWasRestarted
func (ta *TabletActor) SlaveWasRestarted(actionNode *ActionNode, masterAddr string) error {
swrd := actionNode.args.(*SlaveWasRestartedData)
tablet, err := ta.ts.GetTablet(ta.tabletAlias)
if err != nil {
return err
}
// Remove tablet from the replication graph.
if err := topo.DeleteTabletReplicationData(ta.ts, tablet.Tablet); err != nil && err != topo.ErrNoNode {
// FIXME(alainjobart) once we don't have replication paths
// any more, remove this extra check
if err == topo.ErrNotEmpty {
log.Infof("Failed to delete master replication path, will be caught later")
} else {
return err
}
}
// now we can check the reparent actually worked
if masterAddr == "" {
masterAddr, err = ta.mysqlDaemon.GetMasterAddr()
if err != nil {
return err
}
}
if masterAddr != swrd.ExpectedMasterAddr && masterAddr != swrd.ExpectedMasterIpAddr {
log.Errorf("slaveWasRestarted found unexpected master %v for %v (was expecting %v or %v)", masterAddr, ta.tabletAlias, swrd.ExpectedMasterAddr, swrd.ExpectedMasterIpAddr)
if swrd.ScrapStragglers {
return Scrap(ta.ts, tablet.Alias(), false)
} else {
return fmt.Errorf("Unexpected master %v for %v (was expecting %v or %v)", masterAddr, ta.tabletAlias, swrd.ExpectedMasterAddr, swrd.ExpectedMasterIpAddr)
}
}
// Once this action completes, update authoritive tablet node first.
tablet.Parent = swrd.Parent
if tablet.Type == topo.TYPE_MASTER {
tablet.Type = topo.TYPE_SPARE
tablet.State = topo.STATE_READ_ONLY
}
err = topo.UpdateTablet(ta.ts, tablet)
if err != nil {
return err
}
// Insert the new tablet location in the replication graph now that
// we've updated the tablet.
err = topo.CreateTabletReplicationData(ta.ts, tablet.Tablet)
if err != nil && err != topo.ErrNodeExists {
return err
}
return nil
}
开发者ID:ZhuoRoger,项目名称:vitess,代码行数:55,代码来源:actor.go
示例12: SetMaster
// SetMaster sets replication master, and waits for the
// reparent_journal table entry up to context timeout
func (agent *ActionAgent) SetMaster(ctx context.Context, parent topo.TabletAlias, timeCreatedNS int64, forceStartSlave bool) error {
ti, err := agent.TopoServer.GetTablet(ctx, parent)
if err != nil {
return err
}
// See if we were replicating at all, and should be replicating
wasReplicating := false
shouldbeReplicating := false
rs, err := agent.MysqlDaemon.SlaveStatus()
if err == nil && (rs.SlaveIORunning || rs.SlaveSQLRunning) {
wasReplicating = true
shouldbeReplicating = true
}
if forceStartSlave {
shouldbeReplicating = true
}
// Create the list of commands to set the master
cmds := []string{}
if wasReplicating {
cmds = append(cmds, mysqlctl.SqlStopSlave)
}
smc, err := agent.MysqlDaemon.SetMasterCommands(ti.Hostname, ti.Portmap["mysql"])
if err != nil {
return err
}
cmds = append(cmds, smc...)
if shouldbeReplicating {
cmds = append(cmds, mysqlctl.SqlStartSlave)
}
if err := agent.MysqlDaemon.ExecuteSuperQueryList(cmds); err != nil {
return err
}
// change our type to spare if we used to be the master
tablet, err := agent.TopoServer.GetTablet(ctx, agent.TabletAlias)
if err != nil {
return err
}
if tablet.Type == topo.TYPE_MASTER {
tablet.Type = topo.TYPE_SPARE
tablet.Health = nil
if err := topo.UpdateTablet(ctx, agent.TopoServer, tablet); err != nil {
return err
}
}
// if needed, wait until we get the replicated row, or our
// context times out
if !shouldbeReplicating || timeCreatedNS == 0 {
return nil
}
return agent.MysqlDaemon.WaitForReparentJournal(ctx, timeCreatedNS)
}
开发者ID:haoqoo,项目名称:vitess,代码行数:57,代码来源:agent_rpc_actions.go
示例13: Scrap
// Scrap will update the tablet type to 'Scrap', and remove it from
// the serving graph.
//
// 'force' means we are not on the tablet being scrapped, so it is
// probably dead. So if 'force' is true, we will also remove pending
// remote actions. And if 'force' is false, we also run an optional
// hook.
func Scrap(ts topo.Server, tabletAlias topo.TabletAlias, force bool) error {
tablet, err := ts.GetTablet(tabletAlias)
if err != nil {
return err
}
// If you are already scrap, skip updating replication data. It won't
// be there anyway.
wasAssigned := tablet.IsAssigned()
tablet.Type = topo.TYPE_SCRAP
tablet.Parent = topo.TabletAlias{}
// Update the tablet first, since that is canonical.
err = topo.UpdateTablet(ts, tablet)
if err != nil {
return err
}
// Remove any pending actions. Presumably forcing a scrap
// means you don't want the agent doing anything and the
// machine requires manual attention.
if force {
err := ts.PurgeTabletActions(tabletAlias, actionnode.ActionNodeCanBePurged)
if err != nil {
log.Warningf("purge actions failed: %v", err)
}
}
if wasAssigned {
err = topo.DeleteTabletReplicationData(ts, tablet.Tablet)
if err != nil {
if err == topo.ErrNoNode {
log.V(6).Infof("no ShardReplication object for cell %v", tablet.Alias.Cell)
err = nil
}
if err != nil {
log.Warningf("remove replication data for %v failed: %v", tablet.Alias, err)
}
}
}
// run a hook for final cleanup, only in non-force mode.
// (force mode executes on the vtctl side, not on the vttablet side)
if !force {
hk := hook.NewSimpleHook("postflight_scrap")
ConfigureTabletHook(hk, tablet.Alias)
if hookErr := hk.ExecuteOptional(); hookErr != nil {
// we don't want to return an error, the server
// is already in bad shape probably.
log.Warningf("Scrap: postflight_scrap failed: %v", hookErr)
}
}
return nil
}
开发者ID:kingpro,项目名称:vitess,代码行数:61,代码来源:tablet.go
示例14: slaveWasRestarted
func (ta *TabletActor) slaveWasRestarted(actionNode *ActionNode) error {
swrd := actionNode.args.(*SlaveWasRestartedData)
tablet, err := ta.ts.GetTablet(ta.tabletAlias)
if err != nil {
return err
}
// Remove tablet from the replication graph.
err = ta.ts.DeleteReplicationPath(tablet.Keyspace, tablet.Shard, tablet.ReplicationPath())
if err != nil && err != topo.ErrNoNode {
return err
}
// now we can check the reparent actually worked
masterAddr, err := ta.mysqld.GetMasterAddr()
if err != nil {
return err
}
if masterAddr != swrd.ExpectedMasterAddr && masterAddr != swrd.ExpectedMasterIpAddr {
log.Errorf("slaveWasRestarted found unexpected master %v for %v (was expecting %v or %v)", masterAddr, ta.tabletAlias, swrd.ExpectedMasterAddr, swrd.ExpectedMasterIpAddr)
if swrd.ScrapStragglers {
return Scrap(ta.ts, tablet.Alias(), false)
} else {
return fmt.Errorf("Unexpected master %v for %v (was expecting %v or %v)", masterAddr, ta.tabletAlias, swrd.ExpectedMasterAddr, swrd.ExpectedMasterIpAddr)
}
}
// Once this action completes, update authoritive tablet node first.
tablet.Parent = swrd.Parent
if tablet.Type == topo.TYPE_MASTER {
tablet.Type = topo.TYPE_SPARE
tablet.State = topo.STATE_READ_ONLY
}
err = topo.UpdateTablet(ta.ts, tablet)
if err != nil {
return err
}
// Insert the new tablet location in the replication graph now that
// we've updated the tablet.
err = ta.ts.CreateReplicationPath(tablet.Keyspace, tablet.Shard, tablet.ReplicationPath())
if err != nil && err != topo.ErrNodeExists {
return err
}
return nil
}
开发者ID:rrudduck,项目名称:golang-stuff,代码行数:48,代码来源:actor.go
示例15: demoteMaster
func (ta *TabletActor) demoteMaster() error {
_, err := ta.mysqld.DemoteMaster()
if err != nil {
return err
}
tablet, err := ta.ts.GetTablet(ta.tabletAlias)
if err != nil {
return err
}
tablet.State = topo.STATE_READ_ONLY
// NOTE(msolomon) there is no serving graph update - the master tablet will
// be replaced. Even though writes may fail, reads will succeed. It will be
// less noisy to simply leave the entry until well promote the master.
return topo.UpdateTablet(ta.ts, tablet)
}
开发者ID:rrudduck,项目名称:golang-stuff,代码行数:16,代码来源:actor.go
示例16: setReadOnly
func (ta *TabletActor) setReadOnly(rdonly bool) error {
err := ta.mysqld.SetReadOnly(rdonly)
if err != nil {
return err
}
tablet, err := ta.ts.GetTablet(ta.tabletAlias)
if err != nil {
return err
}
if rdonly {
tablet.State = topo.STATE_READ_ONLY
} else {
tablet.State = topo.STATE_READ_WRITE
}
return topo.UpdateTablet(ta.ts, tablet)
}
开发者ID:rrudduck,项目名称:golang-stuff,代码行数:17,代码来源:actor.go
示例17: SetReadOnly
// SetReadOnly makes the mysql instance read-only or read-write
// Should be called under RpcWrapLockAction.
func (agent *ActionAgent) SetReadOnly(rdonly bool) error {
err := agent.Mysqld.SetReadOnly(rdonly)
if err != nil {
return err
}
tablet, err := agent.TopoServer.GetTablet(agent.TabletAlias)
if err != nil {
return err
}
if rdonly {
tablet.State = topo.STATE_READ_ONLY
} else {
tablet.State = topo.STATE_READ_WRITE
}
return topo.UpdateTablet(agent.TopoServer, tablet)
}
开发者ID:plobsing,项目名称:vitess,代码行数:19,代码来源:agent_rpc_actions.go
示例18: SlaveWasRestarted
func SlaveWasRestarted(ts topo.Server, mysqlDaemon mysqlctl.MysqlDaemon, tabletAlias topo.TabletAlias, swrd *actionnode.SlaveWasRestartedArgs) error {
tablet, err := ts.GetTablet(tabletAlias)
if err != nil {
return err
}
// check the reparent actually worked
masterAddr, err := mysqlDaemon.GetMasterAddr()
if err != nil {
return err
}
if masterAddr != swrd.ExpectedMasterAddr && masterAddr != swrd.ExpectedMasterIpAddr {
log.Errorf("SlaveWasRestarted found unexpected master %v for %v (was expecting %v or %v)", masterAddr, tabletAlias, swrd.ExpectedMasterAddr, swrd.ExpectedMasterIpAddr)
// Disabled for now
// if swrd.ContinueOnUnexpectedMaster {
// log.Errorf("ContinueOnUnexpectedMaster is set, we keep going anyway")
// } else
if swrd.ScrapStragglers {
return Scrap(ts, tablet.Alias, false)
} else {
return fmt.Errorf("Unexpected master %v for %v (was expecting %v or %v)", masterAddr, tabletAlias, swrd.ExpectedMasterAddr, swrd.ExpectedMasterIpAddr)
}
}
// Once this action completes, update authoritive tablet node first.
tablet.Parent = swrd.Parent
if tablet.Type == topo.TYPE_MASTER {
tablet.Type = topo.TYPE_SPARE
tablet.State = topo.STATE_READ_ONLY
}
err = topo.UpdateTablet(ts, tablet)
if err != nil {
return err
}
// Update the new tablet location in the replication graph now that
// we've updated the tablet.
err = topo.CreateTabletReplicationData(ts, tablet.Tablet)
if err != nil && err != topo.ErrNodeExists {
return err
}
return nil
}
开发者ID:qinbo,项目名称:vitess,代码行数:44,代码来源:actor.go
示例19: Scrap
// Scrap will update the tablet type to 'Scrap', and remove it from
// the serving graph.
//
// 'force' means we are not on the tablet being scrapped, so it is
// probably dead. So if 'force' is true, we will also remove pending
// remote actions. And if 'force' is false, we also run an optional
// hook.
func Scrap(ctx context.Context, ts topo.Server, tabletAlias topo.TabletAlias, force bool) error {
tablet, err := ts.GetTablet(ctx, tabletAlias)
if err != nil {
return err
}
// If you are already scrap, skip updating replication data. It won't
// be there anyway.
wasAssigned := tablet.IsAssigned()
tablet.Type = topo.TYPE_SCRAP
// Update the tablet first, since that is canonical.
err = topo.UpdateTablet(ctx, ts, tablet)
if err != nil {
return err
}
if wasAssigned {
err = topo.DeleteTabletReplicationData(ctx, ts, tablet.Tablet)
if err != nil {
if err == topo.ErrNoNode {
log.V(6).Infof("no ShardReplication object for cell %v", tablet.Alias.Cell)
err = nil
}
if err != nil {
log.Warningf("remove replication data for %v failed: %v", tablet.Alias, err)
}
}
}
// run a hook for final cleanup, only in non-force mode.
// (force mode executes on the vtctl side, not on the vttablet side)
if !force {
hk := hook.NewSimpleHook("postflight_scrap")
ConfigureTabletHook(hk, tablet.Alias)
if hookErr := hk.ExecuteOptional(); hookErr != nil {
// we don't want to return an error, the server
// is already in bad shape probably.
log.Warningf("Scrap: postflight_scrap failed: %v", hookErr)
}
}
return nil
}
开发者ID:pranjal5215,项目名称:vitess,代码行数:50,代码来源:tablet.go
示例20: RestartSlavesExternal
// RestartSlavesExternal will tell all the slaves in the provided list
// that they have a new master, and also tell all the masters. The
// masters will be scrapped if they don't answer.
// We execute all the actions in parallel.
func RestartSlavesExternal(ts topo.Server, log logutil.Logger, slaveTabletMap, masterTabletMap map[topo.TabletAlias]*topo.TabletInfo, masterElectTabletAlias topo.TabletAlias, slaveWasRestarted func(*topo.TabletInfo, *actionnode.SlaveWasRestartedArgs) error) {
wg := sync.WaitGroup{}
swrd := actionnode.SlaveWasRestartedArgs{
Parent: masterElectTabletAlias,
}
log.Infof("Updating individual tablets with the right master...")
// do all the slaves
for _, ti := range slaveTabletMap {
wg.Add(1)
go func(ti *topo.TabletInfo) {
if err := slaveWasRestarted(ti, &swrd); err != nil {
log.Warningf("Slave %v had an error: %v", ti.Alias, err)
}
wg.Done()
}(ti)
}
// and do the old master and any straggler, if possible.
for _, ti := range masterTabletMap {
wg.Add(1)
go func(ti *topo.TabletInfo) {
err := slaveWasRestarted(ti, &swrd)
if err != nil {
// the old master can be annoying if left
// around in the replication graph, so if we
// can't restart it, we just scrap it.
// We don't rebuild the Shard just yet though.
log.Warningf("Old master %v is not restarting in time, forcing it to spare: %v", ti.Alias, err)
ti.Type = topo.TYPE_SPARE
ti.Parent = masterElectTabletAlias
if err := topo.UpdateTablet(ts, ti); err != nil {
log.Warningf("Failed to change old master %v to spare: %v", ti.Alias, err)
}
}
wg.Done()
}(ti)
}
wg.Wait()
}
开发者ID:plobsing,项目名称:vitess,代码行数:47,代码来源:reparent.go
注:本文中的github.com/youtube/vitess/go/vt/topo.UpdateTablet函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论