Пример #1
0
// Operate on a backup tablet. Shutdown mysqld and copy the data files aside.
func (ta *TabletActor) snapshot(actionNode *actionnode.ActionNode) error {
	args := actionNode.Args.(*actionnode.SnapshotArgs)

	tablet, err := ta.ts.GetTablet(ta.tabletAlias)
	if err != nil {
		return err
	}

	if tablet.Type != topo.TYPE_BACKUP {
		return fmt.Errorf("expected backup type, not %v: %v", tablet.Type, ta.tabletAlias)
	}

	filename, slaveStartRequired, readOnly, err := ta.mysqld.CreateSnapshot(tablet.DbName(), tablet.Addr(), false, args.Concurrency, args.ServerMode, ta.hookExtraEnv())
	if err != nil {
		return err
	}

	sr := &actionnode.SnapshotReply{ManifestPath: filename, SlaveStartRequired: slaveStartRequired, ReadOnly: readOnly}
	if tablet.Parent.Uid == topo.NO_TABLET {
		// If this is a master, this will be the new parent.
		// FIXME(msolomon) this doesn't work in hierarchical replication.
		sr.ParentAlias = tablet.Alias
	} else {
		sr.ParentAlias = tablet.Parent
	}
	actionNode.Reply = sr
	return nil
}
Пример #2
0
func (ta *TabletActor) multiSnapshot(actionNode *actionnode.ActionNode) error {
	args := actionNode.Args.(*actionnode.MultiSnapshotArgs)

	tablet, err := ta.ts.GetTablet(ta.tabletAlias)
	if err != nil {
		return err
	}
	ki, err := ta.ts.GetKeyspace(tablet.Keyspace)
	if err != nil {
		return err
	}

	if tablet.Type != topo.TYPE_BACKUP {
		return fmt.Errorf("expected backup type, not %v: %v", tablet.Type, ta.tabletAlias)
	}

	filenames, err := ta.mysqld.CreateMultiSnapshot(args.KeyRanges, tablet.DbName(), ki.ShardingColumnName, ki.ShardingColumnType, tablet.Addr(), false, args.Concurrency, args.Tables, args.SkipSlaveRestart, args.MaximumFilesize, ta.hookExtraEnv())
	if err != nil {
		return err
	}

	sr := &actionnode.MultiSnapshotReply{ManifestPaths: filenames}
	if tablet.Parent.Uid == topo.NO_TABLET {
		// If this is a master, this will be the new parent.
		// FIXME(msolomon) this doens't work in hierarchical replication.
		sr.ParentAlias = tablet.Alias
	} else {
		sr.ParentAlias = tablet.Parent
	}
	actionNode.Reply = sr
	return nil
}
Пример #3
0
func (ta *TabletActor) executeHook(actionNode *actionnode.ActionNode) (err error) {
	// FIXME(msolomon) shouldn't the reply get distilled into an error?
	h := actionNode.Args.(*hook.Hook)
	topotools.ConfigureTabletHook(h, ta.tabletAlias)
	actionNode.Reply = h.Execute()
	return nil
}
Пример #4
0
func (ta *TabletActor) reparentPosition(actionNode *actionnode.ActionNode) error {
	slavePos := actionNode.Args.(*myproto.ReplicationPosition)

	replicationState, waitPosition, timePromoted, err := ta.mysqld.ReparentPosition(slavePos)
	if err != nil {
		return err
	}
	rsd := new(actionnode.RestartSlaveData)
	rsd.ReplicationState = replicationState
	rsd.TimePromoted = timePromoted
	rsd.WaitPosition = waitPosition
	rsd.Parent = ta.tabletAlias
	log.V(6).Infof("reparentPosition %v", rsd.String())
	actionNode.Reply = rsd
	return nil
}
Пример #5
0
func (ta *TabletActor) applySchema(actionNode *actionnode.ActionNode) error {
	sc := actionNode.Args.(*myproto.SchemaChange)

	// read the tablet to get the dbname
	tablet, err := ta.ts.GetTablet(ta.tabletAlias)
	if err != nil {
		return err
	}

	// and apply the change
	scr, err := ta.mysqld.ApplySchemaChange(tablet.DbName(), sc)
	if err != nil {
		return err
	}
	actionNode.Reply = scr
	return nil
}
Пример #6
0
func (ta *TabletActor) preflightSchema(actionNode *actionnode.ActionNode) error {
	change := actionNode.Args.(*string)

	// read the tablet to get the dbname
	tablet, err := ta.ts.GetTablet(ta.tabletAlias)
	if err != nil {
		return err
	}

	// and preflight the change
	scr, err := ta.mysqld.PreflightSchemaChange(tablet.DbName(), *change)
	if err != nil {
		return err
	}
	actionNode.Reply = scr
	return nil
}
Пример #7
0
func (ta *TabletActor) promoteSlave(actionNode *actionnode.ActionNode) error {
	tablet, err := ta.ts.GetTablet(ta.tabletAlias)
	if err != nil {
		return err
	}

	// Perform the action.
	rsd := &actionnode.RestartSlaveData{Parent: tablet.Alias, Force: (tablet.Parent.Uid == topo.NO_TABLET)}
	rsd.ReplicationState, rsd.WaitPosition, rsd.TimePromoted, err = ta.mysqld.PromoteSlave(false, ta.hookExtraEnv())
	if err != nil {
		return err
	}
	log.Infof("PromoteSlave %v", rsd.String())
	actionNode.Reply = rsd

	return updateReplicationGraphForPromotedSlave(ta.ts, tablet)
}