Skip to content

Commit

Permalink
Gate breaking disk format changes
Browse files Browse the repository at this point in the history
Signed-off-by: Cole Miller <[email protected]>
  • Loading branch information
cole-miller committed Apr 29, 2024
1 parent b4f9381 commit e73e93e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/raft/uv_encoding.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ size_t uvSizeofBatchHeader(size_t n, bool with_local_data)
size_t res = 8 + /* Number of entries in the batch, little endian */
16 * n; /* One header per entry */;
if (with_local_data) {
#ifdef DQLITE_NEXT
res += 8; /* Local data length, applies to all entries */
#endif
}
return res;
}
Expand Down Expand Up @@ -310,8 +312,10 @@ void uvEncodeBatchHeader(const struct raft_entry *entries,
bytePut64(&cursor, n);

if (with_local_data) {
#ifdef DQLITE_NEXT
/* Local data size per entry, little endian */
bytePut64(&cursor, (uint64_t)sizeof(struct raft_entry_local_data));
#endif
}

for (i = 0; i < n; i++) {
Expand Down Expand Up @@ -389,12 +393,14 @@ int uvDecodeBatchHeader(const void *batch,
}

if (local_data_size != NULL) {
#ifdef DQLITE_NEXT
uint64_t z = byteGet64(&cursor);
if (z == 0 || z > sizeof(struct raft_entry_local_data) || z % sizeof(uint64_t) != 0) {
rv = RAFT_MALFORMED;
goto err;

Check warning on line 400 in src/raft/uv_encoding.c

View check run for this annotation

Codecov / codecov/patch

src/raft/uv_encoding.c#L399-L400

Added lines #L399 - L400 were not covered by tests
}
*local_data_size = z;
#endif
}

*entries = raft_malloc(*n * sizeof **entries);
Expand Down Expand Up @@ -598,8 +604,10 @@ int uvDecodeEntriesBatch(uint8_t *batch,
entry->local_data = (struct raft_entry_local_data){};
assert(local_data_size <= sizeof(entry->local_data.buf));
assert(local_data_size % 8 == 0);
#ifdef DQLITE_NEXT
memcpy(entry->local_data.buf, cursor, local_data_size);
cursor += local_data_size;
#endif
}
return 0;
}
4 changes: 4 additions & 0 deletions src/raft/uv_encoding.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
#include "../raft.h"

/* Current disk format version. */
#ifdef DQLITE_NEXT
#define UV__DISK_FORMAT 2
#else
#define UV__DISK_FORMAT 1
#endif

int uvEncodeMessage(const struct raft_message *message,
uv_buf_t **bufs,
Expand Down
6 changes: 6 additions & 0 deletions src/raft/uv_segment.c
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,9 @@ static int uvLoadEntriesBatch(struct uv *uv,
data.len = 0;
for (i = 0; i < n; i++) {
data.len += (*entries)[i].buf.len;
#ifdef DQLITE_NEXT
data.len += sizeof((*entries)[i].local_data);
#endif
}
data.base = (uint8_t *)content->base + *offset;

Expand Down Expand Up @@ -749,7 +751,9 @@ int uvSegmentBufferAppend(struct uvSegmentBuffer *b,
size += uvSizeofBatchHeader(n_entries, true); /* Batch header */
for (i = 0; i < n_entries; i++) { /* Entries data */
size += bytePad64(entries[i].buf.len);
#ifdef DQLITE_NEXT
size += sizeof(struct raft_entry_local_data);
#endif
}

rv = uvEnsureSegmentBufferIsLargeEnough(b, b->n + size);
Expand Down Expand Up @@ -780,10 +784,12 @@ int uvSegmentBufferAppend(struct uvSegmentBuffer *b,
cursor = (uint8_t *)cursor + entry->buf.len;
static_assert(sizeof(entry->local_data.buf) % sizeof(uint64_t) == 0,
"bad size for entry local data");
#ifdef DQLITE_NEXT
size_t local_data_size = sizeof(entry->local_data.buf);
memcpy(cursor, entry->local_data.buf, local_data_size);
crc2 = byteCrc32(cursor, local_data_size, crc2);
cursor = (uint8_t *)cursor + local_data_size;
#endif
}

bytePut32(&crc1_p, crc1);
Expand Down

0 comments on commit e73e93e

Please sign in to comment.