Skip to content

Commit 5edb28f

Browse files
committed
Make leader forget about acked bytes if acked entries reduces due to message refusal.
1 parent dc113a9 commit 5edb28f

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/raft.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,10 +453,12 @@ static void raft_beat(raft_t r, int dst) {
453453
if (p->acked.entries < RAFT_LOG_FIRST_INDEX(r)) {
454454
// The peer has woken up from anabiosis. Send the first
455455
// log entry (which is usually a snapshot).
456+
debug("sending the snapshot to %d\n", dst);
456457
sendindex = RAFT_LOG_FIRST_INDEX(r);
457458
assert(RAFT_LOG(r, sendindex).snapshot);
458459
} else {
459460
// The peer is a bit behind. Send an update.
461+
debug("sending update %d snapshot to %d\n", p->acked.entries, dst);
460462
sendindex = p->acked.entries;
461463
}
462464
m->snapshot = RAFT_LOG(r, sendindex).snapshot;
@@ -474,9 +476,11 @@ static void raft_beat(raft_t r, int dst) {
474476
m->empty = false;
475477
m->offset = p->acked.bytes;
476478
m->len = min(r->config.chunk_len, m->totallen - m->offset);
479+
assert(m->len > 0);
477480
memcpy(m->data, e->update.data + m->offset, m->len);
478481
} else {
479482
// The peer is up to date. Send an empty heartbeat.
483+
debug("sending empty heartbeat to %d\n", dst);
480484
m->empty = true;
481485
m->len = 0;
482486
}
@@ -815,6 +819,7 @@ static void raft_handle_update(raft_t r, raft_msg_update_t *m) {
815819
);
816820
raft_peer_t *p = r->peers + sender;
817821
p->acked.entries = r->log.acked;
822+
p->acked.bytes = 0;
818823
}
819824

820825
if (!m->empty) {
@@ -888,7 +893,7 @@ static void raft_handle_done(raft_t r, raft_msg_done_t *m) {
888893
peer->applied = m->applied;
889894

890895
if (m->success) {
891-
debug("[from %d] ============= done\n", sender);
896+
debug("[from %d] ============= done (%d, %d)\n", sender, m->progress.entries, m->progress.bytes);
892897
peer->acked = m->progress;
893898
peer->silent_ms = 0;
894899
} else {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy