Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ruanhaishen
Willemt Raft
Commits
68982848
Commit
68982848
authored
Aug 04, 2015
by
Willem Thiart
Browse files
Refactored recv appendentries
parent
adec3025
Changes
2
Show whitespace changes
Inline
Side-by-side
src/raft_log.c
View file @
68982848
...
...
@@ -94,11 +94,14 @@ raft_entry_t* log_get_from_idx(log_t* me_, int idx)
log_private_t
*
me
=
(
log_private_t
*
)
me_
;
int
i
;
assert
(
0
<=
idx
-
1
);
if
(
me
->
base_log_idx
+
me
->
count
<
idx
||
idx
<
me
->
base_log_idx
)
return
NULL
;
/* idx starts at 1 */
idx
-=
1
;
i
=
(
me
->
front
+
idx
-
me
->
base_log_idx
)
%
me
->
size
;
return
&
me
->
entries
[
i
];
}
...
...
src/raft_server.c
View file @
68982848
...
...
@@ -252,13 +252,19 @@ int raft_recv_appendentries(
}
#endif
/* not the first appendentries we've received */
if
(
0
!=
ae
->
prev_log_idx
)
/* Not the first appendentries we've received */
/* NOTE: the log starts at 1 */
if
(
1
<
ae
->
prev_log_idx
)
{
raft_entry_t
*
e
=
raft_get_entry_from_idx
(
me_
,
ae
->
prev_log_idx
);
if
(
e
)
if
(
!
e
)
{
__log
(
me_
,
"AE no log at prev_idx %d"
,
ae
->
prev_log_idx
);
r
->
success
=
0
;
return
0
;
}
/* 2. Reply false if log doesn't contain an entry at prevLogIndex
whose term matches prevLogTerm (§5.3) */
if
(
e
->
term
!=
ae
->
prev_log_term
)
...
...
@@ -278,13 +284,6 @@ int raft_recv_appendentries(
if
(
e2
)
log_delete
(
me
->
log
,
ae
->
prev_log_idx
+
1
);
}
else
{
__log
(
me_
,
"AE no log at prev_idx"
);
r
->
success
=
0
;
return
0
;
}
}
/* 5. If leaderCommit > commitIndex, set commitIndex =
min(leaderCommit, last log index) */
...
...
@@ -489,13 +488,12 @@ void raft_send_appendentries(raft_server_t* me_, int node)
ae
.
term
=
me
->
current_term
;
ae
.
leader_id
=
me
->
nodeid
;
ae
.
leader_commit
=
raft_get_commit_idx
(
me_
);
int
next_idx
=
raft_node_get_next_idx
(
p
);
//__ae_set_prev_log(me, p, &ae, next_idx);
ae
.
prev_log_idx
=
0
;
ae
.
prev_log_term
=
0
;
ae
.
n_entries
=
0
;
ae
.
entries
=
NULL
;
int
next_idx
=
raft_node_get_next_idx
(
p
);
msg_entry_t
mety
;
...
...
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