diff --git a/cmd/cconfig/migrate_task.go b/cmd/cconfig/migrate_task.go index 89da538cb..eb887978d 100644 --- a/cmd/cconfig/migrate_task.go +++ b/cmd/cconfig/migrate_task.go @@ -139,6 +139,7 @@ func (t *MigrateTask) run() error { if err != nil { log.ErrorErrorf(err, "migrate single slot failed") t.UpdateStatus(MIGRATE_TASK_ERR) + t.rollbackPremigrate() return err } t.UpdateFinish() @@ -146,6 +147,18 @@ func (t *MigrateTask) run() error { return nil } +func (t *MigrateTask) rollbackPremigrate() { + if s, err := models.GetSlot(t.zkConn, t.productName, t.SlotId); err == nil && s.State.Status == models.SLOT_STATUS_PRE_MIGRATE { + s.State.Status = models.SLOT_STATUS_ONLINE + err = s.Update(t.zkConn) + if err != nil { + log.Warn("rollback premigrate failed", err) + } else { + log.Infof("rollback slot %d from premigrate to online\n", s.Id) + } + } +} + var ErrGroupMasterNotFound = errors.New("group master not found") // will block until all keys are migrated diff --git a/pkg/models/proxy.go b/pkg/models/proxy.go index c239e2aef..875110efb 100644 --- a/pkg/models/proxy.go +++ b/pkg/models/proxy.go @@ -160,7 +160,7 @@ func SetProxyStatus(zkConn zkhelper.Conn, productName string, proxyName string, return errors.Trace(err) } for _, slot := range slots { - if slot.State.Status != SLOT_STATUS_ONLINE && slot.State.Status != SLOT_STATUS_MIGRATE{ + if slot.State.Status != SLOT_STATUS_ONLINE && slot.State.Status != SLOT_STATUS_MIGRATE { return errors.Errorf("slot %v is not online or migrate", slot) } if slot.GroupId == INVALID_ID { diff --git a/pkg/models/server_group.go b/pkg/models/server_group.go index 697049306..b6a16ed55 100644 --- a/pkg/models/server_group.go +++ b/pkg/models/server_group.go @@ -153,7 +153,7 @@ func (self *ServerGroup) Remove(zkConn zkhelper.Conn) error { if slot.GroupId == self.Id { return errors.Errorf("group %d is using by slot %d", slot.GroupId, slot.Id) } - if ((slot.State.Status == SLOT_STATUS_MIGRATE || slot.State.Status == SLOT_STATUS_PRE_MIGRATE) && slot.State.MigrateStatus.From == self.Id) { + if (slot.State.Status == SLOT_STATUS_MIGRATE || slot.State.Status == SLOT_STATUS_PRE_MIGRATE) && slot.State.MigrateStatus.From == self.Id { return errors.Errorf("slot %d has residual data remain in group %d", slot.Id, self.Id) } }