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

Commit 4c71b94

Browse files
authored
Merge pull request #218 from MathieuBordere/bugfix/start-index
uv: Set start_index correctly when no closed segments present
2 parents e565c04 + ed7dbd2 commit 4c71b94

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/uv.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ static int uvLoadSnapshotAndEntries(struct uv *uv,
391391
}
392392
if (segments != NULL) {
393393
if (segments[0].is_open) {
394-
*start_index = 1;
394+
*start_index = (*snapshot)->index + 1;
395395
} else {
396396
*start_index = segments[0].first_index;
397397
}

test/integration/test_uv_load.c

+23
Original file line numberDiff line numberDiff line change
@@ -850,6 +850,29 @@ TEST(load, openSegmentWithEntriesBehindSnapshot, setUp, tearDown, 0, NULL)
850850
return MUNIT_OK;
851851
}
852852

853+
/* The data directory contains a snapshot and an open segment containing a valid
854+
* entry, and no closed segments. */
855+
TEST(load, openSegmentNoClosedSegmentsSnapshotPresent, setUp, tearDown, 0, NULL)
856+
{
857+
struct fixture *f = data;
858+
struct snapshot snapshot = {
859+
1, /* term */
860+
3, /* index */
861+
1 /* data */
862+
};
863+
SNAPSHOT_PUT(1, 3, 1);
864+
APPEND(1, 4);
865+
UNFINALIZE(4, 4, 1);
866+
LOAD(0, /* term */
867+
0, /* voted for */
868+
&snapshot, /* snapshot */
869+
4, /* start index */
870+
4, /* data for first loaded entry */
871+
1 /* n entries */
872+
);
873+
return MUNIT_OK;
874+
}
875+
853876
/* The data directory has several closed segments, all with entries compatible
854877
* with the snapshot. */
855878
TEST(load, closedSegmentsOverlappingWithSnapshot, setUp, tearDown, 0, NULL)

0 commit comments

Comments
 (0)