Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
Willemt Raft
Commits
3627f344
Commit
3627f344
authored
Jun 08, 2018
by
Jiale Zhi
Committed by
Willem
Jun 09, 2018
Browse files
Fix typos and extra spaces (#77)
parent
700eebe6
Changes
7
Hide whitespace changes
Inline
Side-by-side
include/raft.h
View file @
3627f344
...
@@ -223,7 +223,7 @@ typedef int (
...
@@ -223,7 +223,7 @@ typedef int (
msg_appendentries_t
*
msg
msg_appendentries_t
*
msg
);
);
/**
/**
* Log compaction
* Log compaction
* Callback for telling the user to send a snapshot.
* Callback for telling the user to send a snapshot.
*
*
...
@@ -291,7 +291,7 @@ typedef int (
...
@@ -291,7 +291,7 @@ typedef int (
* @param[in] raft The Raft server making this callback
* @param[in] raft The Raft server making this callback
* @param[in] user_data User data that is passed from Raft server
* @param[in] user_data User data that is passed from Raft server
* @param[in] term Current term
* @param[in] term Current term
* @param[in] vote The node value dicating we haven't voted for anybody
* @param[in] vote The node value dic
t
ating we haven't voted for anybody
* @return 0 on success */
* @return 0 on success */
typedef
int
(
typedef
int
(
*
func_persist_term_f
*
func_persist_term_f
...
@@ -722,12 +722,12 @@ int raft_node_get_id(raft_node_t* me_);
...
@@ -722,12 +722,12 @@ int raft_node_get_id(raft_node_t* me_);
* @return get state of type raft_state_e. */
* @return get state of type raft_state_e. */
int
raft_get_state
(
raft_server_t
*
me_
);
int
raft_get_state
(
raft_server_t
*
me_
);
/**
The
the most recent log's term
/**
Get
the most recent log's term
* @return the last log term */
* @return the last log term */
int
raft_get_last_log_term
(
raft_server_t
*
me_
);
int
raft_get_last_log_term
(
raft_server_t
*
me_
);
/** Turn a node into a voting node.
/** Turn a node into a voting node.
* Voting nodes can take part in elections and in-regards to commiting entries,
* Voting nodes can take part in elections and in-regards to commit
t
ing entries,
* are counted in majorities. */
* are counted in majorities. */
void
raft_node_set_voting
(
raft_node_t
*
node
,
int
voting
);
void
raft_node_set_voting
(
raft_node_t
*
node
,
int
voting
);
...
@@ -817,7 +817,7 @@ int raft_get_first_entry_idx(raft_server_t* me_);
...
@@ -817,7 +817,7 @@ int raft_get_first_entry_idx(raft_server_t* me_);
* We need to send an appendentries response.
* We need to send an appendentries response.
*
*
* @param[in] last_included_term Term of the last log of the snapshot
* @param[in] last_included_term Term of the last log of the snapshot
* @param[in] last_included_index Index of the last log of the snapshot
* @param[in] last_included_index Index of the last log of the snapshot
*
*
* @return
* @return
* 0 on success
* 0 on success
...
...
include/raft_log.h
View file @
3627f344
...
@@ -16,8 +16,8 @@ void log_clear(log_t* me_);
...
@@ -16,8 +16,8 @@ void log_clear(log_t* me_);
/**
/**
* Add entry to log.
* Add entry to log.
* Don't add entry if we've already added this entry (based off ID)
* Don't add entry if we've already added this entry (based off ID)
* Don't add entries with ID=0
* Don't add entries with ID=0
* @return 0 if unsucessful; 1 otherwise */
* @return 0 if unsuc
c
essful; 1 otherwise */
int
log_append_entry
(
log_t
*
me_
,
raft_entry_t
*
c
);
int
log_append_entry
(
log_t
*
me_
,
raft_entry_t
*
c
);
/**
/**
...
...
include/raft_private.h
View file @
3627f344
/**
/**
* Copyright (c) 2013, Willem-Hendrik Thiart
* Copyright (c) 2013, Willem-Hendrik Thiart
* Use of this source code is governed by a BSD-style license that can be
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
* found in the LICENSE file.
*
*
* @file
* @file
* @author Willem Thiart himself@willemthiart.com
* @author Willem Thiart himself@willemthiart.com
...
@@ -44,7 +44,7 @@ typedef struct {
...
@@ -44,7 +44,7 @@ typedef struct {
/* amount of time left till timeout */
/* amount of time left till timeout */
int
timeout_elapsed
;
int
timeout_elapsed
;
raft_node_t
*
nodes
;
raft_node_t
*
nodes
;
int
num_nodes
;
int
num_nodes
;
...
...
src/raft_server.c
View file @
3627f344
...
@@ -233,7 +233,7 @@ int raft_periodic(raft_server_t* me_, int msec_since_last_period)
...
@@ -233,7 +233,7 @@ int raft_periodic(raft_server_t* me_, int msec_since_last_period)
if
(
me
->
request_timeout
<=
me
->
timeout_elapsed
)
if
(
me
->
request_timeout
<=
me
->
timeout_elapsed
)
raft_send_appendentries_all
(
me_
);
raft_send_appendentries_all
(
me_
);
}
}
else
if
(
me
->
election_timeout_rand
<=
me
->
timeout_elapsed
&&
else
if
(
me
->
election_timeout_rand
<=
me
->
timeout_elapsed
&&
/* Don't become the leader when building snapshots or bad things will
/* Don't become the leader when building snapshots or bad things will
* happen when we get a client request */
* happen when we get a client request */
!
raft_snapshot_is_in_progress
(
me_
))
!
raft_snapshot_is_in_progress
(
me_
))
...
@@ -542,7 +542,7 @@ static int __should_grant_vote(raft_server_private_t* me, msg_requestvote_t* vr)
...
@@ -542,7 +542,7 @@ static int __should_grant_vote(raft_server_private_t* me, msg_requestvote_t* vr)
if
(
vr
->
term
<
raft_get_current_term
((
void
*
)
me
))
if
(
vr
->
term
<
raft_get_current_term
((
void
*
)
me
))
return
0
;
return
0
;
/* TODO: if voted for is candiate return 1 (if below checks pass) */
/* TODO: if voted for is candi
d
ate return 1 (if below checks pass) */
if
(
raft_already_voted
((
void
*
)
me
))
if
(
raft_already_voted
((
void
*
)
me
))
return
0
;
return
0
;
...
@@ -1256,7 +1256,7 @@ int raft_begin_snapshot(raft_server_t *me_)
...
@@ -1256,7 +1256,7 @@ int raft_begin_snapshot(raft_server_t *me_)
me
->
snapshot_in_progress
=
1
;
me
->
snapshot_in_progress
=
1
;
__log
(
me_
,
NULL
,
__log
(
me_
,
NULL
,
"begin snapshot sli:%d slt:%d slogs:%d
\n
"
,
"begin snapshot sli:%d slt:%d slogs:%d
\n
"
,
me
->
snapshot_last_idx
,
me
->
snapshot_last_idx
,
me
->
snapshot_last_term
,
me
->
snapshot_last_term
,
raft_get_num_snapshottable_logs
(
me_
));
raft_get_num_snapshottable_logs
(
me_
));
...
@@ -1367,7 +1367,7 @@ int raft_begin_load_snapshot(
...
@@ -1367,7 +1367,7 @@ int raft_begin_load_snapshot(
me
->
num_nodes
=
1
;
me
->
num_nodes
=
1
;
__log
(
me_
,
NULL
,
__log
(
me_
,
NULL
,
"loaded snapshot sli:%d slt:%d slogs:%d
\n
"
,
"loaded snapshot sli:%d slt:%d slogs:%d
\n
"
,
me
->
snapshot_last_idx
,
me
->
snapshot_last_idx
,
me
->
snapshot_last_term
,
me
->
snapshot_last_term
,
raft_get_num_snapshottable_logs
(
me_
));
raft_get_num_snapshottable_logs
(
me_
));
...
...
tests/CuTest.c
View file @
3627f344
...
@@ -151,7 +151,7 @@ void CuFail_Line(CuTest* tc, const char* file, int line, const char* message2, c
...
@@ -151,7 +151,7 @@ void CuFail_Line(CuTest* tc, const char* file, int line, const char* message2, c
CuString
string
;
CuString
string
;
CuStringInit
(
&
string
);
CuStringInit
(
&
string
);
if
(
message2
!=
NULL
)
if
(
message2
!=
NULL
)
{
{
CuStringAppend
(
&
string
,
message2
);
CuStringAppend
(
&
string
,
message2
);
CuStringAppend
(
&
string
,
": "
);
CuStringAppend
(
&
string
,
": "
);
...
@@ -166,7 +166,7 @@ void CuAssert_Line(CuTest* tc, const char* file, int line, const char* message,
...
@@ -166,7 +166,7 @@ void CuAssert_Line(CuTest* tc, const char* file, int line, const char* message,
CuFail_Line
(
tc
,
file
,
line
,
NULL
,
message
);
CuFail_Line
(
tc
,
file
,
line
,
NULL
,
message
);
}
}
void
CuAssertStrEquals_LineMsg
(
CuTest
*
tc
,
const
char
*
file
,
int
line
,
const
char
*
message
,
void
CuAssertStrEquals_LineMsg
(
CuTest
*
tc
,
const
char
*
file
,
int
line
,
const
char
*
message
,
const
char
*
expected
,
const
char
*
actual
)
const
char
*
expected
,
const
char
*
actual
)
{
{
CuString
string
;
CuString
string
;
...
@@ -178,7 +178,7 @@ void CuAssertStrEquals_LineMsg(CuTest* tc, const char* file, int line, const cha
...
@@ -178,7 +178,7 @@ void CuAssertStrEquals_LineMsg(CuTest* tc, const char* file, int line, const cha
}
}
CuStringInit
(
&
string
);
CuStringInit
(
&
string
);
if
(
message
!=
NULL
)
if
(
message
!=
NULL
)
{
{
CuStringAppend
(
&
string
,
message
);
CuStringAppend
(
&
string
,
message
);
CuStringAppend
(
&
string
,
": "
);
CuStringAppend
(
&
string
,
": "
);
...
@@ -191,7 +191,7 @@ void CuAssertStrEquals_LineMsg(CuTest* tc, const char* file, int line, const cha
...
@@ -191,7 +191,7 @@ void CuAssertStrEquals_LineMsg(CuTest* tc, const char* file, int line, const cha
CuFailInternal
(
tc
,
file
,
line
,
&
string
);
CuFailInternal
(
tc
,
file
,
line
,
&
string
);
}
}
void
CuAssertIntEquals_LineMsg
(
CuTest
*
tc
,
const
char
*
file
,
int
line
,
const
char
*
message
,
void
CuAssertIntEquals_LineMsg
(
CuTest
*
tc
,
const
char
*
file
,
int
line
,
const
char
*
message
,
int
expected
,
int
actual
)
int
expected
,
int
actual
)
{
{
char
buf
[
STRING_MAX
];
char
buf
[
STRING_MAX
];
...
@@ -200,7 +200,7 @@ void CuAssertIntEquals_LineMsg(CuTest* tc, const char* file, int line, const cha
...
@@ -200,7 +200,7 @@ void CuAssertIntEquals_LineMsg(CuTest* tc, const char* file, int line, const cha
CuFail_Line
(
tc
,
file
,
line
,
message
,
buf
);
CuFail_Line
(
tc
,
file
,
line
,
message
,
buf
);
}
}
void
CuAssertDblEquals_LineMsg
(
CuTest
*
tc
,
const
char
*
file
,
int
line
,
const
char
*
message
,
void
CuAssertDblEquals_LineMsg
(
CuTest
*
tc
,
const
char
*
file
,
int
line
,
const
char
*
message
,
double
expected
,
double
actual
,
double
delta
)
double
expected
,
double
actual
,
double
delta
)
{
{
char
buf
[
STRING_MAX
];
char
buf
[
STRING_MAX
];
...
@@ -209,7 +209,7 @@ void CuAssertDblEquals_LineMsg(CuTest* tc, const char* file, int line, const cha
...
@@ -209,7 +209,7 @@ void CuAssertDblEquals_LineMsg(CuTest* tc, const char* file, int line, const cha
CuFail_Line
(
tc
,
file
,
line
,
message
,
buf
);
CuFail_Line
(
tc
,
file
,
line
,
message
,
buf
);
}
}
void
CuAssertPtrEquals_LineMsg
(
CuTest
*
tc
,
const
char
*
file
,
int
line
,
const
char
*
message
,
void
CuAssertPtrEquals_LineMsg
(
CuTest
*
tc
,
const
char
*
file
,
int
line
,
const
char
*
message
,
void
*
expected
,
void
*
actual
)
void
*
expected
,
void
*
actual
)
{
{
char
buf
[
STRING_MAX
];
char
buf
[
STRING_MAX
];
...
...
tests/CuTest.h
View file @
3627f344
...
@@ -54,17 +54,17 @@ void CuTestRun(CuTest* tc);
...
@@ -54,17 +54,17 @@ void CuTestRun(CuTest* tc);
/* Internal versions of assert functions -- use the public versions */
/* Internal versions of assert functions -- use the public versions */
void
CuFail_Line
(
CuTest
*
tc
,
const
char
*
file
,
int
line
,
const
char
*
message2
,
const
char
*
message
);
void
CuFail_Line
(
CuTest
*
tc
,
const
char
*
file
,
int
line
,
const
char
*
message2
,
const
char
*
message
);
void
CuAssert_Line
(
CuTest
*
tc
,
const
char
*
file
,
int
line
,
const
char
*
message
,
int
condition
);
void
CuAssert_Line
(
CuTest
*
tc
,
const
char
*
file
,
int
line
,
const
char
*
message
,
int
condition
);
void
CuAssertStrEquals_LineMsg
(
CuTest
*
tc
,
void
CuAssertStrEquals_LineMsg
(
CuTest
*
tc
,
const
char
*
file
,
int
line
,
const
char
*
message
,
const
char
*
file
,
int
line
,
const
char
*
message
,
const
char
*
expected
,
const
char
*
actual
);
const
char
*
expected
,
const
char
*
actual
);
void
CuAssertIntEquals_LineMsg
(
CuTest
*
tc
,
void
CuAssertIntEquals_LineMsg
(
CuTest
*
tc
,
const
char
*
file
,
int
line
,
const
char
*
message
,
const
char
*
file
,
int
line
,
const
char
*
message
,
int
expected
,
int
actual
);
int
expected
,
int
actual
);
void
CuAssertDblEquals_LineMsg
(
CuTest
*
tc
,
void
CuAssertDblEquals_LineMsg
(
CuTest
*
tc
,
const
char
*
file
,
int
line
,
const
char
*
message
,
const
char
*
file
,
int
line
,
const
char
*
message
,
double
expected
,
double
actual
,
double
delta
);
double
expected
,
double
actual
,
double
delta
);
void
CuAssertPtrEquals_LineMsg
(
CuTest
*
tc
,
void
CuAssertPtrEquals_LineMsg
(
CuTest
*
tc
,
const
char
*
file
,
int
line
,
const
char
*
message
,
const
char
*
file
,
int
line
,
const
char
*
message
,
void
*
expected
,
void
*
actual
);
void
*
expected
,
void
*
actual
);
/* public assert functions */
/* public assert functions */
...
...
tests/test_server.c
View file @
3627f344
...
@@ -1407,7 +1407,7 @@ void TestRaft_follower_recv_appendentries_delete_entries_if_conflict_with_new_en
...
@@ -1407,7 +1407,7 @@ void TestRaft_follower_recv_appendentries_delete_entries_if_conflict_with_new_en
char* strs[] = {"111", "222", "333"};
char* strs[] = {"111", "222", "333"};
raft_entry_t *ety_appended;
raft_entry_t *ety_appended;
__create_mock_entries_for_conflict_tests(tc, r, strs);
__create_mock_entries_for_conflict_tests(tc, r, strs);
CuAssertIntEquals(tc, 3, raft_get_log_count(r));
CuAssertIntEquals(tc, 3, raft_get_log_count(r));
...
@@ -1903,7 +1903,7 @@ void TestRaft_follower_recv_appendentries_heartbeat_does_not_overwrite_logs(
...
@@ -1903,7 +1903,7 @@ void TestRaft_follower_recv_appendentries_heartbeat_does_not_overwrite_logs(
raft_recv_appendentries(r, raft_get_node(r, 2), &ae, &aer);
raft_recv_appendentries(r, raft_get_node(r, 2), &ae, &aer);
/* receive a heartbeat
/* receive a heartbeat
* NOTE: the leader hasn't received the response to the last AE so it can
* NOTE: the leader hasn't received the response to the last AE so it can
* only assume prev_Log_idx is still 1 */
* only assume prev_Log_idx is still 1 */
memset(&ae, 0, sizeof(msg_appendentries_t));
memset(&ae, 0, sizeof(msg_appendentries_t));
ae.term = 1;
ae.term = 1;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment