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
RedisLabs Raft
Commits
80d5f3ed
You need to sign in or sign up before continuing.
Commit
80d5f3ed
authored
May 02, 2018
by
Yossi Gottlieb
Browse files
Fix log_get_from_idx() off by one error.
parent
274ff74d
Changes
3
Show whitespace changes
Inline
Side-by-side
src/raft_log.c
View file @
80d5f3ed
...
@@ -172,7 +172,7 @@ raft_entry_t* log_get_from_idx(log_t* me_, int idx, int *n_etys)
...
@@ -172,7 +172,7 @@ raft_entry_t* log_get_from_idx(log_t* me_, int idx, int *n_etys)
assert
(
0
<=
idx
-
1
);
assert
(
0
<=
idx
-
1
);
if
(
me
->
base
+
me
->
count
<
idx
||
idx
<
me
->
base
)
if
(
me
->
base
+
me
->
count
<
idx
||
idx
<
=
me
->
base
)
{
{
*
n_etys
=
0
;
*
n_etys
=
0
;
return
NULL
;
return
NULL
;
...
...
src/raft_server.c
View file @
80d5f3ed
...
@@ -1259,6 +1259,12 @@ int raft_end_snapshot(raft_server_t *me_)
...
@@ -1259,6 +1259,12 @@ int raft_end_snapshot(raft_server_t *me_)
me
->
snapshot_in_progress
=
0
;
me
->
snapshot_in_progress
=
0
;
__log
(
me_
,
NULL
,
"end snapshot base:%d commit-index:%d current-index:%d
\n
"
,
log_get_base
(
me
->
log
),
raft_get_commit_idx
(
me_
),
raft_get_current_idx
(
me_
));
if
(
!
raft_is_leader
(
me_
))
if
(
!
raft_is_leader
(
me_
))
return
0
;
return
0
;
...
...
tests/test_log.c
View file @
80d5f3ed
...
@@ -579,3 +579,49 @@ void TestLog_delete_after_polling_from_double_append(CuTest * tc)
...
@@ -579,3 +579,49 @@ void TestLog_delete_after_polling_from_double_append(CuTest * tc)
CuAssertIntEquals
(
tc
,
log_delete
(
l
,
1
),
0
);
CuAssertIntEquals
(
tc
,
log_delete
(
l
,
1
),
0
);
CuAssertIntEquals
(
tc
,
0
,
log_count
(
l
));
CuAssertIntEquals
(
tc
,
0
,
log_count
(
l
));
}
}
void
TestLog_get_from_idx_with_base_off_by_one
(
CuTest
*
tc
)
{
void
*
queue
=
llqueue_new
();
void
*
r
=
raft_new
();
raft_cbs_t
funcs
=
{
.
log_pop
=
__log_pop
,
.
log_get_node_id
=
__logentry_get_node_id
};
raft_set_callbacks
(
r
,
&
funcs
,
queue
);
void
*
l
;
raft_entry_t
e1
,
e2
;
memset
(
&
e1
,
0
,
sizeof
(
raft_entry_t
));
memset
(
&
e2
,
0
,
sizeof
(
raft_entry_t
));
e1
.
id
=
1
;
e2
.
id
=
2
;
l
=
log_alloc
(
1
);
log_set_callbacks
(
l
,
&
funcs
,
r
);
raft_entry_t
*
ety
;
/* append append */
CuAssertIntEquals
(
tc
,
0
,
log_append_entry
(
l
,
&
e1
));
CuAssertIntEquals
(
tc
,
0
,
log_append_entry
(
l
,
&
e2
));
CuAssertIntEquals
(
tc
,
2
,
log_count
(
l
));
/* poll */
CuAssertIntEquals
(
tc
,
log_poll
(
l
,
(
void
*
)
&
ety
),
0
);
CuAssertIntEquals
(
tc
,
ety
->
id
,
1
);
CuAssertIntEquals
(
tc
,
1
,
log_count
(
l
));
/* get off-by-one index */
int
n_etys
;
CuAssertPtrEquals
(
tc
,
log_get_from_idx
(
l
,
1
,
&
n_etys
),
NULL
);
CuAssertIntEquals
(
tc
,
n_etys
,
0
);
/* now get the correct index */
ety
=
log_get_from_idx
(
l
,
2
,
&
n_etys
);
CuAssertPtrNotNull
(
tc
,
ety
);
CuAssertIntEquals
(
tc
,
n_etys
,
1
);
CuAssertIntEquals
(
tc
,
ety
->
id
,
2
);
}
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