Skip to content

Commit

Permalink
Fix: The snapshot installation blindly applies config to the server. (#…
Browse files Browse the repository at this point in the history
…566)

* Fix: The snapshot installation blindly applies config to the server.

If the server was previously in the member set which was captured in the config of
this snapshot, then the peer will appear to have "caught_up" in ::reconfigure. I do
not believe there is value in rolling back the config just to reapply it later once
log_sync occurs. `::commit_conf` performs a similar check.

* Simplify

* [Update PR] Leave a log when snapshot config is skipped

---------

Co-authored-by: Jung-Sang Ahn <[email protected]>
  • Loading branch information
szmyd and greensky00 authored Jan 23, 2025
1 parent cf80969 commit f9c7462
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/handle_snapshot_sync.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ limitations under the License.

#include "raft_server.hxx"

#include "cluster_config.hxx"
#include "context.hxx"
#include "error_code.hxx"
#include "event_awaiter.hxx"
Expand Down Expand Up @@ -565,10 +566,22 @@ bool raft_server::handle_snapshot_sync_req(snapshot_sync_req& req, std::unique_l
// LCOV_EXCL_STOP
}

reconfigure(req.get_snapshot().get_last_config());

auto snap_conf = req.get_snapshot().get_last_config();
ptr<cluster_config> c_conf = get_config();
ctx_->state_mgr_->save_config(*c_conf);
if (snap_conf->get_log_idx() > c_conf->get_log_idx()) {
ctx_->state_mgr_->save_config(*snap_conf);
reconfigure(snap_conf);
c_conf = get_config();
} else {
p_in("snapshot config idx %" PRIu64 " prev idx %" PRIu64
" is not newer than "
"current config idx %" PRIu64 " prev idx %" PRIu64
", will not apply it",
snap_conf->get_log_idx(),
snap_conf->get_prev_log_idx(),
c_conf->get_log_idx(),
c_conf->get_prev_log_idx());
}

precommit_index_ = req.get_snapshot().get_last_log_idx();
sm_commit_index_ = req.get_snapshot().get_last_log_idx();
Expand Down

0 comments on commit f9c7462

Please sign in to comment.