func NewSlave(reqChan *RequestChan, bin *binlog.BinLog, mc *config.MasterConfig, adminPwd string) *slave { var slv = new(slave) slv.reqChan = reqChan slv.bin = bin slv.mc = mc slv.mi = mc.GetMaster() slv.adminPwd = adminPwd return slv }
func clearSlaveOldData(conf *config.Config, mc *config.MasterConfig) error { var err error m := mc.GetMaster() // Normal slave if len(m.MasterAddr) > 0 && !m.Migration { // Check whether need to clear old data if m.Status != ctrl.SlaveNeedClear && m.Status != ctrl.SlaveClear { return nil } err = mc.SetStatus(ctrl.SlaveClear) if err != nil { return err } // Move binlog & table to backup in case you need the old data var backupDir = BackupDirName(conf) err = os.RemoveAll(backupDir) if err != nil { return err } err = os.MkdirAll(backupDir, os.ModeDir|os.ModePerm) if err != nil { return err } var binlogDir = BinLogDirName(conf) log.Println("Move directory binlog to backup") err = os.Rename(binlogDir, backupDir+"/binlog") if err != nil { return err } var tableDir = TableDirName(conf) log.Println("Move directory table to backup") err = os.Rename(tableDir, backupDir+"/table") if err != nil { return err } err = mc.SetStatus(ctrl.SlaveInit) if err != nil { return err } } return nil }
func NewWriteAccess(replication bool, mc *config.MasterConfig) *WriteAccess { hasMaster, migration, slotId := mc.GetMasterSlot() return &WriteAccess{replication, hasMaster, migration, slotId} }