Skip to content

Commit

Permalink
rollback from pre_migrate to online if migration task failed
Browse files Browse the repository at this point in the history
  • Loading branch information
yangzhe1991 committed Sep 6, 2015
1 parent 1ce681a commit 8c31053
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
13 changes: 13 additions & 0 deletions cmd/cconfig/migrate_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,26 @@ 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()
log.Infof("migration finished: %+v", t.MigrateTaskInfo)
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
Expand Down
2 changes: 1 addition & 1 deletion pkg/models/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion pkg/models/server_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down

0 comments on commit 8c31053

Please sign in to comment.