Skip to content

Commit

Permalink
bugfix: reading segment, correctly stop on error
Browse files Browse the repository at this point in the history
  • Loading branch information
letFunny committed Jul 12, 2024
1 parent 4e8ffc2 commit a653857
Showing 1 changed file with 22 additions and 27 deletions.
49 changes: 22 additions & 27 deletions src/raft/uv_list.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <string.h>
#include <uv.h>

#include "assert.h"
#include "uv.h"
Expand Down Expand Up @@ -36,7 +37,6 @@ int UvList(struct uv *uv,
int n;
int i;
int rv;
int rv2;

n = uv_fs_scandir(NULL, &req, uv->dir, 0, NULL);
if (n < 0) {
Expand Down Expand Up @@ -64,58 +64,53 @@ int UvList(struct uv *uv,
/* If an error occurred while processing a preceeding entry or
* if we know that this is not a segment filename, just free it
* and skip to the next one. */
if (rv != 0 || uvListShouldIgnore(filename)) {
if (rv == 0) {
tracef("ignore %s", filename);
}
if (uvListShouldIgnore(filename)) {
tracef("ignore %s", filename);
continue;
}

/* Append to the snapshot list if it's a snapshot metadata
* filename and a valid associated snapshot file exists. */
rv = UvSnapshotInfoAppendIfMatch(uv, filename, snapshots,
n_snapshots, &appended);
if (appended || rv != 0) {
if (rv == 0) {
tracef("snapshot %s", filename);
}
if (rv != 0) {
goto error;

Check warning on line 77 in src/raft/uv_list.c

View check run for this annotation

Codecov / codecov/patch

src/raft/uv_list.c#L77

Added line #L77 was not covered by tests
}
if (appended) {
tracef("snapshot %s", filename);
continue;
}

/* Append to the segment list if it's a segment filename */
rv = uvSegmentInfoAppendIfMatch(entry.name, segments,
n_segments, &appended);
if (appended || rv != 0) {
if (rv == 0) {
tracef("segment %s", filename);
}
if (rv != 0) {
goto error;

Check warning on line 88 in src/raft/uv_list.c

View check run for this annotation

Codecov / codecov/patch

src/raft/uv_list.c#L88

Added line #L88 was not covered by tests
}
if (appended) {
tracef("segment %s", filename);
continue;
}

tracef("ignore %s", filename);
}

rv2 = uv_fs_scandir_next(&req, &entry);
assert(rv2 == UV_EOF);

if (rv != 0 && *segments != NULL) {
raft_free(*segments);
*segments = NULL;
}

if (rv != 0 && *snapshots != NULL) {
raft_free(*snapshots);
*snapshots = NULL;
}
rv = uv_fs_scandir_next(&req, &entry);
assert(rv == UV_EOF);

if (*snapshots != NULL) {
UvSnapshotSort(*snapshots, *n_snapshots);
}

if (*segments != NULL) {
uvSegmentSort(*segments, *n_segments);
}
return 0;

error:

Check warning on line 108 in src/raft/uv_list.c

View check run for this annotation

Codecov / codecov/patch

src/raft/uv_list.c#L108

Added line #L108 was not covered by tests
uv_fs_req_cleanup(&req);
raft_free(*segments);
*segments = NULL;

Check warning on line 111 in src/raft/uv_list.c

View check run for this annotation

Codecov / codecov/patch

src/raft/uv_list.c#L111

Added line #L111 was not covered by tests
raft_free(*snapshots);
*snapshots = NULL;

Check warning on line 113 in src/raft/uv_list.c

View check run for this annotation

Codecov / codecov/patch

src/raft/uv_list.c#L113

Added line #L113 was not covered by tests
return rv;
}

Expand Down

0 comments on commit a653857

Please sign in to comment.