From 2b4fa7fbe0bf475b8d1376ed544684920773f601 Mon Sep 17 00:00:00 2001 From: Jay Lee Date: Sat, 28 Aug 2021 01:24:17 +0800 Subject: [PATCH] allow skip writing commit index Signed-off-by: Jay Lee --- components/raftstore/src/store/config.rs | 2 ++ components/raftstore/src/store/fsm/store.rs | 5 +++++ components/raftstore/src/store/peer_storage.rs | 13 ++++++++++++- tests/integrations/config/mod.rs | 1 + 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/components/raftstore/src/store/config.rs b/components/raftstore/src/store/config.rs index 7b3a1ddf96e..30aefdecd30 100644 --- a/components/raftstore/src/store/config.rs +++ b/components/raftstore/src/store/config.rs @@ -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, @@ -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, diff --git a/components/raftstore/src/store/fsm/store.rs b/components/raftstore/src/store/fsm/store.rs index fa147aa5cb6..64a8b2b2487 100644 --- a/components/raftstore/src/store/fsm/store.rs +++ b/components/raftstore/src/store/fsm/store.rs @@ -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 PollContext diff --git a/components/raftstore/src/store/peer_storage.rs b/components/raftstore/src/store/peer_storage.rs index 54cc955f8ec..7991e020c99 100644 --- a/components/raftstore/src/store/peer_storage.rs +++ b/components/raftstore/src/store/peer_storage.rs @@ -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(error: E) -> raft::Error @@ -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, @@ -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( diff --git a/tests/integrations/config/mod.rs b/tests/integrations/config/mod.rs index 90f7a46edcc..3f95a2f8953 100644 --- a/tests/integrations/config/mod.rs +++ b/tests/integrations/config/mod.rs @@ -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,