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
6f318d01
Commit
6f318d01
authored
Apr 11, 2016
by
Willem Thiart
Browse files
Fix: user setting data pointer in log_offer
Regression caused by
d106d229
parent
aa012f6b
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/raft_log.c
View file @
6f318d01
...
...
@@ -99,19 +99,26 @@ void log_clear(log_t* me_)
int
log_append_entry
(
log_t
*
me_
,
raft_entry_t
*
c
)
{
log_private_t
*
me
=
(
log_private_t
*
)
me_
;
int
e
=
0
;
if
(
0
==
c
->
id
)
return
-
1
;
__ensurecapacity
(
me
);
if
(
me
->
cb
&&
me
->
cb
->
log_offer
)
{
void
*
ud
=
raft_get_udata
(
me
->
raft
);
e
=
me
->
cb
->
log_offer
(
me
->
raft
,
ud
,
c
,
me
->
back
-
1
);
if
(
e
==
RAFT_ERR_SHUTDOWN
)
return
e
;
}
memcpy
(
&
me
->
entries
[
me
->
back
],
c
,
sizeof
(
raft_entry_t
));
me
->
count
++
;
me
->
back
++
;
if
(
me
->
cb
&&
me
->
cb
->
log_offer
)
return
me
->
cb
->
log_offer
(
me
->
raft
,
raft_get_udata
(
me
->
raft
),
c
,
me
->
back
-
1
);
return
0
;
return
e
;
}
raft_entry_t
*
log_get_from_idx
(
log_t
*
me_
,
int
idx
,
int
*
n_etys
)
...
...
tests/test_server.c
View file @
6f318d01
...
...
@@ -185,6 +185,39 @@ void TestRaft_server_append_entry_is_retrievable(CuTest * tc)
CuAssertTrue(tc, kept->data.buf == ety.data.buf);
}
static int __raft_logentry_offer(
raft_server_t* raft,
void *udata,
raft_entry_t *ety,
int ety_idx
)
{
ety->data.buf = udata;
return 0;
}
void TestRaft_server_append_entry_user_can_set_data_buf(CuTest * tc)
{
raft_cbs_t funcs = {
.log_offer = __raft_logentry_offer,
};
char *data = "xxx";
void *r = raft_new();
raft_set_state(r, RAFT_STATE_CANDIDATE);
raft_set_callbacks(r, &funcs, data);
raft_set_current_term(r, 5);
raft_entry_t ety = {};
ety.term = 1;
ety.id = 100;
ety.data.len = 4;
ety.data.buf = (unsigned char*)"aaa";
raft_append_entry(r, &ety);
raft_entry_t* kept = raft_get_entry_from_idx(r, 1);
CuAssertTrue(tc, NULL != kept->data.buf);
CuAssertTrue(tc, kept->data.buf == ety.data.buf);
}
#if 0
/* TODO: no support for duplicate detection yet */
void
...
...
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