Esempio n. 1
0
func main() {
	defer func() {
		if panicErr := recover(); panicErr != nil {
			log.Fatalf("panic: %v", tb.Errorf("%v", panicErr))
		}
	}()

	flag.Parse()
	args := flag.Args()
	if len(args) != 0 {
		flag.Usage()
		os.Exit(1)
	}

	if *fromTopo == "" || *toTopo == "" {
		log.Fatalf("Need both from and to topo")
	}

	fromTS := topo.GetServerByName(*fromTopo)
	toTS := topo.GetServerByName(*toTopo)

	if *doKeyspaces {
		helpers.CopyKeyspaces(fromTS, toTS)
	}
	if *doShards {
		helpers.CopyShards(fromTS, toTS, *deleteKeyspaceShards)
	}
	if *doShardReplications {
		helpers.CopyShardReplications(fromTS, toTS)
	}
	if *doTablets {
		helpers.CopyTablets(fromTS, toTS)
	}
}
Esempio n. 2
0
func doRecover(err interface{}, recoverAll bool) {
	if err == nil {
		return
	}

	switch code := err.(type) {
	case exitCode:
		exitFunc(int(code))
	default:
		if recoverAll {
			log.Errorf("panic: %v", tb.Errorf("%v", err))
			exitFunc(255)
		} else {
			panic(err)
		}
	}
}
Esempio n. 3
0
func main() {
	defer func() {
		if panicErr := recover(); panicErr != nil {
			relog.Fatal("panic: %v", tb.Errorf("%v", panicErr))
		}
	}()

	flag.Parse()
	args := flag.Args()
	if len(args) != 0 {
		flag.Usage()
		os.Exit(1)
	}

	logLevel, err := relog.LogNameToLogLevel(*logLevel)
	if err != nil {
		relog.Fatal("%v", err)
	}
	relog.SetLevel(logLevel)

	if *fromTopo == "" || *toTopo == "" {
		relog.Fatal("Need both from and to topo")
	}

	fromTS := topo.GetServerByName(*fromTopo)
	toTS := topo.GetServerByName(*toTopo)

	if *doKeyspaces {
		topotools.CopyKeyspaces(fromTS, toTS)
	}
	if *doShards {
		topotools.CopyShards(fromTS, toTS, *deleteKeyspaceShards)
	}
	if *doTablets {
		topotools.CopyTablets(fromTS, toTS)
	}
}
Esempio n. 4
0
func (ta *TabletActor) dispatchAction(actionNode *ActionNode) (err error) {
	defer func() {
		if x := recover(); x != nil {
			err = tb.Errorf("dispatchAction panic %v", x)
		}
	}()

	switch actionNode.Action {
	case TABLET_ACTION_BREAK_SLAVES:
		err = ta.mysqld.BreakSlaves()
	case TABLET_ACTION_CHANGE_TYPE:
		err = ta.changeType(actionNode)
	case TABLET_ACTION_DEMOTE_MASTER:
		err = ta.demoteMaster()
	case TABLET_ACTION_MASTER_POSITION:
		err = ta.masterPosition(actionNode)
	case TABLET_ACTION_MULTI_SNAPSHOT:
		err = ta.multiSnapshot(actionNode)
	case TABLET_ACTION_MULTI_RESTORE:
		err = ta.multiRestore(actionNode)
	case TABLET_ACTION_PING:
		// Just an end-to-end verification that we got the message.
		err = nil
	case TABLET_ACTION_PROMOTE_SLAVE:
		err = ta.promoteSlave(actionNode)
	case TABLET_ACTION_SLAVE_WAS_PROMOTED:
		err = ta.slaveWasPromoted(actionNode)
	case TABLET_ACTION_RESTART_SLAVE:
		err = ta.restartSlave(actionNode)
	case TABLET_ACTION_SLAVE_WAS_RESTARTED:
		err = ta.slaveWasRestarted(actionNode)
	case TABLET_ACTION_RESERVE_FOR_RESTORE:
		err = ta.reserveForRestore(actionNode)
	case TABLET_ACTION_RESTORE:
		err = ta.restore(actionNode)
	case TABLET_ACTION_SCRAP:
		err = ta.scrap()
	case TABLET_ACTION_GET_SCHEMA:
		err = ta.getSchema(actionNode)
	case TABLET_ACTION_PREFLIGHT_SCHEMA:
		err = ta.preflightSchema(actionNode)
	case TABLET_ACTION_APPLY_SCHEMA:
		err = ta.applySchema(actionNode)
	case TABLET_ACTION_EXECUTE_HOOK:
		err = ta.executeHook(actionNode)
	case TABLET_ACTION_GET_SLAVES:
		err = ta.getSlaves(actionNode)
	case TABLET_ACTION_SET_RDONLY:
		err = ta.setReadOnly(true)
	case TABLET_ACTION_SET_RDWR:
		err = ta.setReadOnly(false)
	case TABLET_ACTION_SLEEP:
		err = ta.sleep(actionNode)
	case TABLET_ACTION_SLAVE_POSITION:
		err = ta.slavePosition(actionNode)
	case TABLET_ACTION_REPARENT_POSITION:
		err = ta.reparentPosition(actionNode)
	case TABLET_ACTION_SNAPSHOT:
		err = ta.snapshot(actionNode)
	case TABLET_ACTION_SNAPSHOT_SOURCE_END:
		err = ta.snapshotSourceEnd(actionNode)
	case TABLET_ACTION_STOP_SLAVE:
		err = ta.mysqld.StopSlave()
	case TABLET_ACTION_WAIT_SLAVE_POSITION:
		err = ta.waitSlavePosition(actionNode)
	default:
		err = TabletActorError("invalid action: " + actionNode.Action)
	}

	return
}
Esempio n. 5
0
func (ta *TabletActor) dispatchAction(actionNode *actionnode.ActionNode) (err error) {
	defer func() {
		if x := recover(); x != nil {
			err = tb.Errorf("dispatchAction panic %v", x)
		}
	}()

	switch actionNode.Action {
	case actionnode.TABLET_ACTION_BREAK_SLAVES:
		err = ta.mysqld.BreakSlaves()
	case actionnode.TABLET_ACTION_CHANGE_TYPE:
		err = ta.changeType(actionNode)
	case actionnode.TABLET_ACTION_DEMOTE_MASTER:
		err = ta.demoteMaster()
	case actionnode.TABLET_ACTION_MULTI_SNAPSHOT:
		err = ta.multiSnapshot(actionNode)
	case actionnode.TABLET_ACTION_MULTI_RESTORE:
		err = ta.multiRestore(actionNode)
	case actionnode.TABLET_ACTION_PING:
		// Just an end-to-end verification that we got the message.
		err = nil
	case actionnode.TABLET_ACTION_PROMOTE_SLAVE:
		err = ta.promoteSlave(actionNode)
	case actionnode.TABLET_ACTION_SLAVE_WAS_PROMOTED:
		err = SlaveWasPromoted(ta.ts, ta.tabletAlias)
	case actionnode.TABLET_ACTION_RESTART_SLAVE:
		err = ta.restartSlave(actionNode)
	case actionnode.TABLET_ACTION_SLAVE_WAS_RESTARTED:
		err = SlaveWasRestarted(ta.ts, ta.tabletAlias, actionNode.Args.(*actionnode.SlaveWasRestartedArgs))
	case actionnode.TABLET_ACTION_RESERVE_FOR_RESTORE:
		err = ta.reserveForRestore(actionNode)
	case actionnode.TABLET_ACTION_RESTORE:
		err = ta.restore(actionNode)
	case actionnode.TABLET_ACTION_SCRAP:
		err = ta.scrap()
	case actionnode.TABLET_ACTION_PREFLIGHT_SCHEMA:
		err = ta.preflightSchema(actionNode)
	case actionnode.TABLET_ACTION_APPLY_SCHEMA:
		err = ta.applySchema(actionNode)
	case actionnode.TABLET_ACTION_EXECUTE_HOOK:
		err = ta.executeHook(actionNode)
	case actionnode.TABLET_ACTION_SET_RDONLY:
		err = ta.setReadOnly(true)
	case actionnode.TABLET_ACTION_SET_RDWR:
		err = ta.setReadOnly(false)
	case actionnode.TABLET_ACTION_SLEEP:
		err = ta.sleep(actionNode)
	case actionnode.TABLET_ACTION_REPARENT_POSITION:
		err = ta.reparentPosition(actionNode)
	case actionnode.TABLET_ACTION_SNAPSHOT:
		err = ta.snapshot(actionNode)
	case actionnode.TABLET_ACTION_SNAPSHOT_SOURCE_END:
		err = ta.snapshotSourceEnd(actionNode)

	case actionnode.TABLET_ACTION_SET_BLACKLISTED_TABLES,
		actionnode.TABLET_ACTION_GET_SCHEMA,
		actionnode.TABLET_ACTION_RELOAD_SCHEMA,
		actionnode.TABLET_ACTION_GET_PERMISSIONS,
		actionnode.TABLET_ACTION_SLAVE_POSITION,
		actionnode.TABLET_ACTION_WAIT_SLAVE_POSITION,
		actionnode.TABLET_ACTION_MASTER_POSITION,
		actionnode.TABLET_ACTION_STOP_SLAVE,
		actionnode.TABLET_ACTION_STOP_SLAVE_MINIMUM,
		actionnode.TABLET_ACTION_START_SLAVE,
		actionnode.TABLET_ACTION_GET_SLAVES,
		actionnode.TABLET_ACTION_WAIT_BLP_POSITION,
		actionnode.TABLET_ACTION_STOP_BLP,
		actionnode.TABLET_ACTION_START_BLP,
		actionnode.TABLET_ACTION_RUN_BLP_UNTIL:
		err = TabletActorError("Operation " + actionNode.Action + "  only supported as RPC")
	default:
		err = TabletActorError("invalid action: " + actionNode.Action)
	}

	return
}