Skip to content

Commit a7142ed

Browse files
committed
Fix 'is applied' check when asking about current node.
1 parent 7c7795c commit a7142ed

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/raft.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,7 @@ static int raft_apply(raft_t raft) {
318318
raft_log_t *l = &raft->log;
319319
while (l->applied < l->acked) {
320320
raft_entry_t *e = &RAFT_LOG(raft, l->applied);
321+
assert(e->update.len == e->bytes);
321322
raft->config.applier(raft->config.userdata, e->update, false);
322323
raft->log.applied++;
323324
applied_now++;
@@ -661,6 +662,7 @@ int raft_emit(raft_t r, raft_update_t update) {
661662
assert(e->update.len == 0);
662663
assert(e->update.data == NULL);
663664
e->update.len = update.len;
665+
e->bytes = update.len;
664666
e->update.data = malloc(update.len);
665667
memcpy(e->update.data, update.data, update.len);
666668
r->log.size++;
@@ -671,9 +673,16 @@ int raft_emit(raft_t r, raft_update_t update) {
671673
}
672674

673675
bool raft_applied(raft_t r, int id, int index) {
674-
raft_peer_t *p = r->peers + id;
675-
if (!p->up) return false;
676-
return p->applied >= index;
676+
if (r->me == id)
677+
{
678+
return r->log.applied >= index;
679+
}
680+
else
681+
{
682+
raft_peer_t *p = r->peers + id;
683+
if (!p->up) return false;
684+
return p->applied >= index;
685+
}
677686
}
678687

679688
static bool raft_restore(raft_t r, int previndex, raft_entry_t *e) {

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