| 79 | } |
| 80 | |
| 81 | func (ctx *context) toSlot(m *models.SlotMapping, p *models.Proxy) *models.Slot { |
| 82 | slot := &models.Slot{ |
| 83 | Id: m.Id, |
| 84 | Locked: ctx.isSlotLocked(m), |
| 85 | |
| 86 | ForwardMethod: ctx.method, |
| 87 | } |
| 88 | switch m.Action.State { |
| 89 | case models.ActionNothing, models.ActionPending: |
| 90 | slot.BackendAddr = ctx.getGroupMaster(m.GroupId) |
| 91 | slot.BackendAddrGroupId = m.GroupId |
| 92 | slot.ReplicaGroups = ctx.toReplicaGroups(m.GroupId, p) |
| 93 | case models.ActionPreparing: |
| 94 | slot.BackendAddr = ctx.getGroupMaster(m.GroupId) |
| 95 | slot.BackendAddrGroupId = m.GroupId |
| 96 | case models.ActionPrepared: |
| 97 | fallthrough |
| 98 | case models.ActionMigrating: |
| 99 | slot.BackendAddr = ctx.getGroupMaster(m.Action.TargetId) |
| 100 | slot.BackendAddrGroupId = m.Action.TargetId |
| 101 | slot.MigrateFrom = ctx.getGroupMaster(m.GroupId) |
| 102 | slot.MigrateFromGroupId = m.GroupId |
| 103 | case models.ActionFinished: |
| 104 | slot.BackendAddr = ctx.getGroupMaster(m.Action.TargetId) |
| 105 | slot.BackendAddrGroupId = m.Action.TargetId |
| 106 | default: |
| 107 | log.Panicf("slot-[%d] action state is invalid:\n%s", m.Id, m.Encode()) |
| 108 | } |
| 109 | return slot |
| 110 | } |
| 111 | |
| 112 | func (ctx *context) lookupIPAddr(addr string) net.IP { |
| 113 | ctx.hosts.Lock() |