Skip to content

Commit

Permalink
allow skip writing commit index
Browse files Browse the repository at this point in the history
Signed-off-by: Jay Lee <[email protected]>
  • Loading branch information
BusyJay committed Aug 27, 2021
1 parent e4425c8 commit 2b4fa7f
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
2 changes: 2 additions & 0 deletions components/raftstore/src/store/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ pub struct Config {
pub apply_yield_duration: ReadableDuration,
#[config(skip)]
pub disable_kv_wal: bool,
pub skip_write_commit_index: bool,
pub enable_propose_batch: bool,
pub skip_header: bool,

Expand Down Expand Up @@ -265,6 +266,7 @@ impl Default for Config {
dev_assert: false,
apply_yield_duration: ReadableDuration::millis(500),
disable_kv_wal: false,
skip_write_commit_index: false,
enable_propose_batch: true,
skip_header: false,

Expand Down
5 changes: 5 additions & 0 deletions components/raftstore/src/store/fsm/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,11 @@ where
fn set_sync_log(&mut self, sync: bool) {
self.sync_log = sync;
}

#[inline]
fn skip_write_commit_index(&self) -> bool {
self.cfg.skip_write_commit_index
}
}

impl<EK, ER, T> PollContext<EK, ER, T>
Expand Down
13 changes: 12 additions & 1 deletion components/raftstore/src/store/peer_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,7 @@ where
fn raft_wb_mut(&mut self) -> &mut WR;
fn sync_log(&self) -> bool;
fn set_sync_log(&mut self, sync: bool);
fn skip_write_commit_index(&self) -> bool;
}

fn storage_error<E>(error: E) -> raft::Error
Expand Down Expand Up @@ -1549,9 +1550,16 @@ where
ctx.raft_state.set_hard_state(hs.clone());
}
}
let new_commit = ctx.raft_state.get_hard_state().get_commit();
if ready_ctx.skip_write_commit_index() {
let old_commit = self.raft_state.get_hard_state().get_commit();
ctx.raft_state.mut_hard_state().set_commit(old_commit);
}
let skip_write = ctx.raft_state == self.raft_state;
ctx.raft_state.mut_hard_state().set_commit(new_commit);

// Save raft state if it has changed or there is a snapshot.
if ctx.raft_state != self.raft_state || snapshot_index > 0 {
if !skip_write || snapshot_index > 0 {
ctx.save_raft_state_to(ready_ctx.raft_wb_mut())?;
if snapshot_index > 0 {
// in case of restart happen when we just write region state to Applying,
Expand Down Expand Up @@ -1950,6 +1958,9 @@ mod tests {
fn set_sync_log(&mut self, sync: bool) {
self.sync_log = sync;
}
fn skip_write_commit_index(&self) -> bool {
false
}
}

fn new_storage_from_ents(
Expand Down
1 change: 1 addition & 0 deletions tests/integrations/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ fn test_serde_custom_tikv_config() {
future_poll_size: 2,
hibernate_regions: false,
disable_kv_wal: true,
skip_write_commit_index: false,
dev_assert: true,
apply_yield_duration: ReadableDuration::millis(333),
perf_level: PerfLevel::EnableTime,
Expand Down

0 comments on commit 2b4fa7f

Please sign in to comment.