|
|
@@ -50,26 +50,25 @@ func newReadOnly(option ReadOnlyOption) *readOnly {
|
|
|
// the read only request.
|
|
|
// `m` is the original read only request message from the local or remote node.
|
|
|
func (ro *readOnly) addRequest(index uint64, m pb.Message) {
|
|
|
- ctx := string(m.Entries[0].Data)
|
|
|
- if _, ok := ro.pendingReadIndex[ctx]; ok {
|
|
|
+ s := string(m.Entries[0].Data)
|
|
|
+ if _, ok := ro.pendingReadIndex[s]; ok {
|
|
|
return
|
|
|
}
|
|
|
- ro.pendingReadIndex[ctx] = &readIndexStatus{index: index, req: m, acks: make(map[uint64]struct{})}
|
|
|
- ro.readIndexQueue = append(ro.readIndexQueue, ctx)
|
|
|
+ ro.pendingReadIndex[s] = &readIndexStatus{index: index, req: m, acks: make(map[uint64]struct{})}
|
|
|
+ ro.readIndexQueue = append(ro.readIndexQueue, s)
|
|
|
}
|
|
|
|
|
|
// recvAck notifies the readonly struct that the raft state machine received
|
|
|
// an acknowledgment of the heartbeat that attached with the read only request
|
|
|
// context.
|
|
|
-func (ro *readOnly) recvAck(m pb.Message) int {
|
|
|
- rs, ok := ro.pendingReadIndex[string(m.Context)]
|
|
|
+func (ro *readOnly) recvAck(id uint64, context []byte) map[uint64]struct{} {
|
|
|
+ rs, ok := ro.pendingReadIndex[string(context)]
|
|
|
if !ok {
|
|
|
- return 0
|
|
|
+ return nil
|
|
|
}
|
|
|
|
|
|
- rs.acks[m.From] = struct{}{}
|
|
|
- // add one to include an ack from local node
|
|
|
- return len(rs.acks) + 1
|
|
|
+ rs.acks[id] = struct{}{}
|
|
|
+ return rs.acks
|
|
|
}
|
|
|
|
|
|
// advance advances the read only request queue kept by the readonly struct.
|