Unverified Commit 3dcf5256 authored by Ozan Tezcan's avatar Ozan Tezcan Committed by GitHub
Browse files

Revert election and request timeout config type (#107)

parent d06c7536
...@@ -1660,23 +1660,22 @@ raft_index_t raft_get_index_to_sync(raft_server_t *me); ...@@ -1660,23 +1660,22 @@ raft_index_t raft_get_index_to_sync(raft_server_t *me);
* disable-apply : Skip applying entries. Useful for testing. * disable-apply : Skip applying entries. Useful for testing.
* *
* *
* | Enum | Type | Valid values | Default | * | Enum | Type | Valid values | Default value |
* | ----------------------------- | ------------ | ------------ | ----------- | * | ----------------------------- | ---- | ---------------- | --------------- |
* | RAFT_CONFIG_ELECTION_TIMEOUT | raft_time_t | > 0 | 1000 millis | * | RAFT_CONFIG_ELECTION_TIMEOUT | int | Positive integer | 1000 millis |
* | RAFT_CONFIG_REQUEST_TIMEOUT | raft_time_t | > 0 | 200 millis | * | RAFT_CONFIG_REQUEST_TIMEOUT | int | Positive integer | 200 millis |
* | RAFT_CONFIG_AUTO_FLUSH | int | 0 or 1 | 0 | * | RAFT_CONFIG_AUTO_FLUSH | int | 0 or 1 | 0 |
* | RAFT_CONFIG_LOG_ENABLED | int | 0 or 1 | 0 | * | RAFT_CONFIG_LOG_ENABLED | int | 0 or 1 | 0 |
* | RAFT_CONFIG_NONBLOCKING_APPLY | int | 0 or 1 | 0 | * | RAFT_CONFIG_NONBLOCKING_APPLY | int | 0 or 1 | 0 |
* | RAFT_CONFIG_DISABLE_APPLY | int | 0 or 1 | 0 | * | RAFT_CONFIG_DISABLE_APPLY | int | 0 or 1 | 0 |
* *
* Example: * Example:
* *
* - Set * - Set
* raft_time_t timeout = 4000; * raft_config(raft, 1, RAFT_CONFIG_ELECTION_TIMEOUT, 4000);
* raft_config(raft, 1, RAFT_CONFIG_ELECTION_TIMEOUT, timeout);
* *
* - Get * - Get
* raft_time_t election_timeout; * int election_timeout;
* raft_config(raft, 0, RAFT_CONFIG_ELECTION_TIMEOUT, &election_timeout); * raft_config(raft, 0, RAFT_CONFIG_ELECTION_TIMEOUT, &election_timeout);
* *
* @param set 1 to set the value, 0 to get the current value. * @param set 1 to set the value, 0 to get the current value.
......
...@@ -2172,18 +2172,18 @@ int raft_config(raft_server_t *me, int set, raft_config_e config, ...) ...@@ -2172,18 +2172,18 @@ int raft_config(raft_server_t *me, int set, raft_config_e config, ...)
switch (config) { switch (config) {
case RAFT_CONFIG_ELECTION_TIMEOUT: case RAFT_CONFIG_ELECTION_TIMEOUT:
if (set) { if (set) {
me->election_timeout = va_arg(va, raft_time_t); me->election_timeout = va_arg(va, int);
raft_update_quorum_meta(me, me->last_acked_msg_id); raft_update_quorum_meta(me, me->last_acked_msg_id);
raft_randomize_election_timeout(me); raft_randomize_election_timeout(me);
} else { } else {
*(va_arg(va, raft_time_t*)) = me->election_timeout; *(va_arg(va, int*)) = (int) me->election_timeout;
} }
break; break;
case RAFT_CONFIG_REQUEST_TIMEOUT: case RAFT_CONFIG_REQUEST_TIMEOUT:
if (set) { if (set) {
me->request_timeout = va_arg(va, raft_time_t); me->request_timeout = va_arg(va, int);
} else { } else {
*(va_arg(va, raft_time_t*)) = me->request_timeout; *(va_arg(va, int*)) = (int) me->request_timeout;
} }
break; break;
case RAFT_CONFIG_AUTO_FLUSH: case RAFT_CONFIG_AUTO_FLUSH:
......
...@@ -265,7 +265,7 @@ void TestRaft_server_starts_with_election_timeout_of_1000ms(CuTest * tc) ...@@ -265,7 +265,7 @@ void TestRaft_server_starts_with_election_timeout_of_1000ms(CuTest * tc)
{ {
void *r = raft_new(); void *r = raft_new();
raft_time_t election_timeout; int election_timeout;
raft_config(r, 0, RAFT_CONFIG_ELECTION_TIMEOUT, &election_timeout); raft_config(r, 0, RAFT_CONFIG_ELECTION_TIMEOUT, &election_timeout);
CuAssertTrue(tc, 1000 == election_timeout); CuAssertTrue(tc, 1000 == election_timeout);
...@@ -275,7 +275,7 @@ void TestRaft_server_starts_with_request_timeout_of_200ms(CuTest * tc) ...@@ -275,7 +275,7 @@ void TestRaft_server_starts_with_request_timeout_of_200ms(CuTest * tc)
{ {
void *r = raft_new(); void *r = raft_new();
raft_time_t request_timeout; int request_timeout;
raft_config(r, 0, RAFT_CONFIG_REQUEST_TIMEOUT, &request_timeout); raft_config(r, 0, RAFT_CONFIG_REQUEST_TIMEOUT, &request_timeout);
CuAssertTrue(tc, 200 == request_timeout); CuAssertTrue(tc, 200 == request_timeout);
...@@ -4195,7 +4195,7 @@ void TestRaft_leader_steps_down_if_there_is_no_quorum(CuTest * tc) ...@@ -4195,7 +4195,7 @@ void TestRaft_leader_steps_down_if_there_is_no_quorum(CuTest * tc)
raft_config(r, 1, RAFT_CONFIG_REQUEST_TIMEOUT, 1000); raft_config(r, 1, RAFT_CONFIG_REQUEST_TIMEOUT, 1000);
// Quorum timeout is twice the election timeout. // Quorum timeout is twice the election timeout.
raft_time_t election_timeout; int election_timeout;
raft_config(r, 0, RAFT_CONFIG_ELECTION_TIMEOUT, &election_timeout); raft_config(r, 0, RAFT_CONFIG_ELECTION_TIMEOUT, &election_timeout);
raft_time_t quorum_timeout = election_timeout * 2; raft_time_t quorum_timeout = election_timeout * 2;
...@@ -4220,7 +4220,7 @@ void TestRaft_leader_steps_down_if_there_is_no_quorum(CuTest * tc) ...@@ -4220,7 +4220,7 @@ void TestRaft_leader_steps_down_if_there_is_no_quorum(CuTest * tc)
// Trigger new round of append entries // Trigger new round of append entries
raft_time_t request_timeout; int request_timeout;
raft_config(r, 0, RAFT_CONFIG_REQUEST_TIMEOUT, &request_timeout); raft_config(r, 0, RAFT_CONFIG_REQUEST_TIMEOUT, &request_timeout);
raft_periodic_internal(r, request_timeout + 1); raft_periodic_internal(r, request_timeout + 1);
...@@ -4602,7 +4602,7 @@ void Test_transfer_automatic(CuTest *tc) ...@@ -4602,7 +4602,7 @@ void Test_transfer_automatic(CuTest *tc)
void TestRaft_config(CuTest *tc) void TestRaft_config(CuTest *tc)
{ {
int val; int val;
raft_time_t time; int time;
raft_server_t *r = raft_new(); raft_server_t *r = raft_new();
CuAssertIntEquals(tc, 0, raft_config(r, 1, RAFT_CONFIG_ELECTION_TIMEOUT, 566)); CuAssertIntEquals(tc, 0, raft_config(r, 1, RAFT_CONFIG_ELECTION_TIMEOUT, 566));
...@@ -4795,9 +4795,7 @@ void TestRaft_apply_entry_timeout(CuTest *tc) ...@@ -4795,9 +4795,7 @@ void TestRaft_apply_entry_timeout(CuTest *tc)
raft_add_node(r, NULL, 1, 1); raft_add_node(r, NULL, 1, 1);
raft_set_callbacks(r, &funcs, &ts); raft_set_callbacks(r, &funcs, &ts);
raft_set_current_term(r, 1); raft_set_current_term(r, 1);
raft_config(r, 1, RAFT_CONFIG_REQUEST_TIMEOUT, 100);
raft_time_t timeout = 100;
raft_config(r, 1, RAFT_CONFIG_REQUEST_TIMEOUT, timeout);
__RAFT_APPEND_ENTRIES_SEQ_ID(r, 21, 0, 1, ""); __RAFT_APPEND_ENTRIES_SEQ_ID(r, 21, 0, 1, "");
raft_set_commit_idx(r, 21); raft_set_commit_idx(r, 21);
...@@ -4840,9 +4838,7 @@ void TestRaft_apply_read_request_timeout(CuTest *tc) ...@@ -4840,9 +4838,7 @@ void TestRaft_apply_read_request_timeout(CuTest *tc)
raft_set_commit_idx(r, 1); raft_set_commit_idx(r, 1);
raft_apply_all(r); raft_apply_all(r);
raft_config(r, 1, RAFT_CONFIG_AUTO_FLUSH, 0); raft_config(r, 1, RAFT_CONFIG_AUTO_FLUSH, 0);
raft_config(r, 1, RAFT_CONFIG_REQUEST_TIMEOUT, 100);
raft_time_t timeout = 100;
raft_config(r, 1, RAFT_CONFIG_REQUEST_TIMEOUT, timeout);
int remaining = 20; int remaining = 20;
for (int i = 0; i < remaining; i++) { for (int i = 0; i < remaining; i++) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment