Skip to content
This repository has been archived by the owner on Mar 4, 2024. It is now read-only.

Commit

Permalink
Merge pull request #89 from amiloradovsky/uv-io-memset
Browse files Browse the repository at this point in the history
uv: resilience improvements
  • Loading branch information
freeekanayaka committed Nov 5, 2019
2 parents 6ce1b8e + fe05473 commit 25805d9
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 23 deletions.
2 changes: 1 addition & 1 deletion configure.ac
@@ -1,5 +1,5 @@
AC_PREREQ(2.60)
AC_INIT([raft], [0.9.6])
AC_INIT([raft], [0.9.10])
AC_LANG([C])
AC_CONFIG_MACRO_DIR([m4])
AC_CONFIG_AUX_DIR([ac])
Expand Down
2 changes: 1 addition & 1 deletion src/fixture.c
Expand Up @@ -1372,7 +1372,7 @@ static void completeRequest(struct raft_fixture *f, unsigned i, raft_time t)
{
struct io *io = f->servers[i].io.impl;
queue *head;
struct request *r;
struct request *r = NULL;
bool found = false;
f->time = t;
f->event.server_index = i;
Expand Down
2 changes: 1 addition & 1 deletion src/progress.c
Expand Up @@ -104,7 +104,7 @@ bool progressShouldReplicate(struct raft *r, unsigned i)
bool needs_heartbeat = now - p->last_send >= r->heartbeat_timeout;
raft_index last_index = logLastIndex(&r->log);
bool is_up_to_date = p->next_index == last_index + 1;
bool result;
bool result = false;

/* We must be in a valid state. */
assert(p->state == PROGRESS__PROBE || p->state == PROGRESS__PIPELINE ||
Expand Down
2 changes: 1 addition & 1 deletion src/tick.c
Expand Up @@ -180,7 +180,7 @@ static int tickLeader(struct raft *r)

static int tick(struct raft *r)
{
int rv;
int rv = -1;

assert(r->state == RAFT_UNAVAILABLE || r->state == RAFT_FOLLOWER ||
r->state == RAFT_CANDIDATE || r->state == RAFT_LEADER);
Expand Down
13 changes: 12 additions & 1 deletion src/uv.c
Expand Up @@ -592,16 +592,22 @@ int raft_uv_init(struct raft_io *io,
if (uv == NULL) {
return RAFT_NOMEM;
}
memset (uv, 0, sizeof (struct uv));
/* during initialization of a structure this big (40 fields),
you're guaranteed to forget to initialize something */

uv->io = io;
uv->loop = loop;
strcpy(uv->dir, dir);
uv->transport = transport;
uv->transport->data = uv;
uv->logger = NULL; /* will be set later, or will fail earlier */
uv->id = 0;
UvFsInit(&uv->fs, uv->loop);
uv->state = 0;
uv->errored = false;
uv->direct_io = false; /* assume unsupported */
uv->async_io = false; /* assume unsupported */
uv->block_size = 0; /* Detected in raft_io->init() */
uv->n_blocks = 0; /* Calculated in raft_io->init() */
uv->clients = NULL;
Expand All @@ -625,11 +631,16 @@ int raft_uv_init(struct raft_io *io,
QUEUE_INIT(&uv->snapshot_put_reqs);
QUEUE_INIT(&uv->snapshot_get_reqs);
uv->snapshot_put_work.data = NULL;
uv->tick_cb = NULL;
/* TODO: struct uvMetadata metadata; /\* Cache of metadata on disk *\/ */
/* TODO: struct uv_timer_s timer; /\* Timer for periodic ticks *\/ */
uv->tick_cb = NULL; /* will be set at ~start~ */
uv->recv_cb = NULL; /* will be set at ~start~ */
uv->closing = false;
uv->close_cb = NULL;

/* Set the raft_io implementation. */
io->version = 1; /* future-proof'ing */
io->data = NULL; /* canary-poison */
io->impl = uv;
io->init = uvInit;
io->start = uvStart;
Expand Down
36 changes: 18 additions & 18 deletions test/unit/test_uv_writer.c
Expand Up @@ -241,24 +241,24 @@ static void submitCbAssertFail(struct UvWriterReq *req, int status)

/* Assert that the content of the test file has the given number of blocks, each
* filled with progressive numbers. */
#define ASSERT_CONTENT(N) \
{ \
size_t size = N * f->block_size; \
void *buf = munit_malloc(size); \
unsigned i; \
unsigned j; \
\
test_dir_read_file(f->dir, "foo", buf, size); \
\
for (i = 0; i < N; i++) { \
char *cursor = (char *)buf + i * f->block_size; \
for (j = 0; j < f->block_size; j++) { \
munit_assert_int(cursor[j], ==, i + 1); \
} \
} \
\
free(buf); \
}
#define ASSERT_CONTENT(N) \
{ \
size_t size = N * f->block_size; \
void *buf = munit_malloc(size); \
\
test_dir_read_file(f->dir, "foo", buf, size); \
\
for (unsigned __i = 0; __i < N; __i++) \
{ \
char *cursor = (char *)buf + __i * f->block_size; \
for (unsigned __j = 0; __j < f->block_size; __j++) \
{ \
munit_assert_int (cursor[__j], ==, __i + 1); \
} \
} \
\
free(buf); \
}

SUITE(UvWriterSubmit)

Expand Down

0 comments on commit 25805d9

Please sign in to comment.