mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
raft: add 'TransferLeadership' to Node interface
This commit is contained in:
parent
f4141f0f51
commit
e64ef3f261
12
raft/node.go
12
raft/node.go
@ -144,6 +144,9 @@ type Node interface {
|
|||||||
// to match MemoryStorage.Compact.
|
// to match MemoryStorage.Compact.
|
||||||
ApplyConfChange(cc pb.ConfChange) *pb.ConfState
|
ApplyConfChange(cc pb.ConfChange) *pb.ConfState
|
||||||
|
|
||||||
|
// TransferLeadership attempts to transfer leadership to the given transferee.
|
||||||
|
TransferLeadership(ctx context.Context, lead, transferee uint64)
|
||||||
|
|
||||||
// ReadIndex request a read state. The read state will be set in the ready.
|
// ReadIndex request a read state. The read state will be set in the ready.
|
||||||
// Read state has a read index. Once the application advances further than the read
|
// Read state has a read index. Once the application advances further than the read
|
||||||
// index, any linearizable read requests issued before the read request can be
|
// index, any linearizable read requests issued before the read request can be
|
||||||
@ -485,6 +488,15 @@ func (n *node) ReportSnapshot(id uint64, status SnapshotStatus) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (n *node) TransferLeadership(ctx context.Context, lead, transferee uint64) {
|
||||||
|
select {
|
||||||
|
// manually set 'from' and 'to', so that leader can voluntarily transfers its leadership
|
||||||
|
case n.recvc <- pb.Message{Type: pb.MsgTransferLeader, From: transferee, To: lead}:
|
||||||
|
case <-n.done:
|
||||||
|
case <-ctx.Done():
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (n *node) ReadIndex(ctx context.Context, rctx []byte) error {
|
func (n *node) ReadIndex(ctx context.Context, rctx []byte) error {
|
||||||
return n.step(ctx, pb.Message{Type: pb.MsgReadIndex, Entries: []pb.Entry{{Data: rctx}}})
|
return n.step(ctx, pb.Message{Type: pb.MsgReadIndex, Entries: []pb.Entry{{Data: rctx}}})
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user