eBay / NuRaft

C++ implementation of Raft core logic as a replication library
Apache License 2.0
1.02k stars 241 forks source link

Checking parameters #385

Closed JackyWoo closed 2 years ago

JackyWoo commented 2 years ago

Check election timeout lower and upper bound.

JackyWoo commented 2 years ago

Trigger some test errors. I try to fix in #386, pls correct me if there is something wrong.

greensky00 commented 2 years ago

Election timeouts and heartbeat in that test were set on purpose. That test does not use a "real" timer but artificially coordinates the timing to produce the edge cases that can hardly happen in the real world.

I'd rather add a flag for test mode in raft_Server.

    /**
     * If `true`, test mode is enabled.
     */
    std::atomic<bool> test_mode_flag_;

    /**
     * Set the test mode.
     * 
     * @param to Test mode.
     */
    void set_test_mode(bool to) {
        test_mode_flag_ = to;
    }

and do the auto adjustment only when the test mod is false:

if (test_mode_flag_) {
    if (params->heart_beat_interval_ >= params->election_timeout_lower_bound_) 
    ...
}

Also, enable the flag here: https://github.com/eBay/NuRaft/blob/1c2587f159775a4924573db64ffac5c973230761/tests/unit/raft_package_fake.hxx#L90