-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscheduler_op_leader.go
47 lines (38 loc) · 1.15 KB
/
scheduler_op_leader.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package prophet
import (
"fmt"
)
func newTransferLeaderAggregationOp(cfg *Cfg, target *ResourceRuntime, newLeader *Peer) Operator {
transferLeader := newTransferLeaderOperator(target.meta.ID(), target.leaderPeer, newLeader)
return newAggregationOp(cfg, target, transferLeader)
}
type transferLeaderOperator struct {
Name string `json:"name"`
ID uint64 `json:"id"`
OldLeader *Peer `json:"oldLeader"`
NewLeader *Peer `json:"newLeader"`
}
func newTransferLeaderOperator(id uint64, oldLeader, newLeader *Peer) Operator {
return &transferLeaderOperator{
Name: "transfer_leader",
ID: id,
OldLeader: oldLeader,
NewLeader: newLeader,
}
}
func (op *transferLeaderOperator) String() string {
return fmt.Sprintf("%+v", *op)
}
func (op *transferLeaderOperator) ResourceID() uint64 {
return op.ID
}
func (op *transferLeaderOperator) ResourceKind() ResourceKind {
return LeaderKind
}
func (op *transferLeaderOperator) Do(info *ResourceRuntime) (*resourceHeartbeatRsp, bool) {
// Check if operator is finished.
if info.leaderPeer.ID == op.NewLeader.ID {
return nil, true
}
return newChangeLeaderRsp(op.ID, op.NewLeader), false
}