Skip to content

Commit

Permalink
fix applied upper bound (#543)
Browse files Browse the repository at this point in the history
Signed-off-by: glorv <glorvs@163.com>
  • Loading branch information
glorv committed Apr 3, 2024
1 parent 3cfa667 commit a76fb6e
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/raft_log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,14 +322,15 @@ impl<T: Storage> RaftLog<T> {
if idx == 0 {
return;
}
if idx > self.applied_index_upper_bound() || idx < self.applied {
// NOTE: here we must use `commmitted` instead of `min(committed, perssited + max_apply_unpersisted_log_limit)`
// as the uppper bound because the `max_apply_unpersisted_log_limit` can be adjusted dynamically.
if idx > self.committed || idx < self.applied {
fatal!(
self.unstable.logger,
"applied({}) is out of range [prev_applied({}), min(committed({}), persisted({}))]",
"applied({}) is out of range [prev_applied({}), committed({})]",
idx,
self.applied,
self.committed,
self.persisted,
)
}
self.applied_to_unchecked(idx);
Expand Down Expand Up @@ -1250,6 +1251,8 @@ mod test {
(5, 5, 5, 0, None),
(5, 7, 7, UNLIMITED, Some(&ents[2..4])),
(7, 7, 7, UNLIMITED, None),
// test applied can be bigger than `persisted + limit`(when limit is changed)
(8, 6, 8, 0, None),
];
for (i, &(applied, persisted, committed, limit, ref expect_entries)) in
tests.iter().enumerate()
Expand Down

0 comments on commit a76fb6e

Please sign in to comment.