Skip to content

Commit

Permalink
skip pre_migrate if slot is already migrating
Browse files Browse the repository at this point in the history
  • Loading branch information
yangzhe1991 committed Sep 11, 2015
1 parent b4dc5cd commit 1eaeb08
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 15 deletions.
1 change: 1 addition & 0 deletions cmd/cconfig/migrate_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ func (t *MigrateTask) migrateSingleSlot(slotId int, to int) error {
return nil
}


// modify slot status
if err := s.SetMigrateStatus(t.zkConn, from, to); err != nil {
log.ErrorErrorf(err, "set migrate status failed")
Expand Down
41 changes: 26 additions & 15 deletions pkg/models/slot.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,16 +189,16 @@ func (s *Slot) SetMigrateStatus(zkConn zkhelper.Conn, fromGroup, toGroup int) er
if fromGroup < 0 || toGroup < 0 {
return errors.Errorf("invalid group id, from %d, to %d", fromGroup, toGroup)
}
// wait until all proxy confirmed
s.State.Status = SLOT_STATUS_PRE_MIGRATE
err := s.Update(zkConn)
if err != nil {
return errors.Trace(err)
}
err = NewAction(zkConn, s.ProductName, ACTION_TYPE_SLOT_PREMIGRATE, s, "", true)
if err != nil {
return errors.Trace(err)

// skip pre_migrate if slot is already migrating
if s.State.Status != SLOT_STATUS_MIGRATE {
s.State.Status = SLOT_STATUS_PRE_MIGRATE
err := s.Update(zkConn)
if err != nil {
return errors.Trace(err)
}
}

s.State.Status = SLOT_STATUS_MIGRATE
s.State.MigrateStatus.From = fromGroup
s.State.MigrateStatus.To = toGroup
Expand Down Expand Up @@ -230,11 +230,22 @@ func (s *Slot) Update(zkConn zkhelper.Conn) error {
return errors.Trace(err)
}

if s.State.Status == SLOT_STATUS_MIGRATE {
err = NewAction(zkConn, s.ProductName, ACTION_TYPE_SLOT_MIGRATE, s, "", true)
} else {
err = NewAction(zkConn, s.ProductName, ACTION_TYPE_SLOT_CHANGED, s, "", true)
switch s.State.Status {
case SLOT_STATUS_MIGRATE:
{
err = NewAction(zkConn, s.ProductName, ACTION_TYPE_SLOT_MIGRATE, s, "", true)
}
case SLOT_STATUS_PRE_MIGRATE:
{
err = NewAction(zkConn, s.ProductName, ACTION_TYPE_SLOT_PREMIGRATE, s, "", true)
}
default:
{
err = NewAction(zkConn, s.ProductName, ACTION_TYPE_SLOT_CHANGED, s, "", true)
}
}

return errors.Trace(err)
if err != nil {
return errors.Trace(err)
}
return nil
}

2 comments on commit 1eaeb08

@williamjie
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

请教下,这个是说,正在迁移中,禁止再次迁移? 保证迁移的唯一性?

@yangzhe1991
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

是已经迁移中的slot如果因为dashboard重启了重新执行迁移的话不需要先pre_migrate了

Please sign in to comment.