diff --git a/src/raft/uv_encoding.c b/src/raft/uv_encoding.c index 2722926a8..130fb9e13 100644 --- a/src/raft/uv_encoding.c +++ b/src/raft/uv_encoding.c @@ -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; } @@ -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++) { @@ -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; } *local_data_size = z; +#endif } *entries = raft_malloc(*n * sizeof **entries); @@ -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; } diff --git a/src/raft/uv_encoding.h b/src/raft/uv_encoding.h index 0f228999e..851966fb7 100644 --- a/src/raft/uv_encoding.h +++ b/src/raft/uv_encoding.h @@ -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, diff --git a/src/raft/uv_segment.c b/src/raft/uv_segment.c index d207dcb4d..07646c0cf 100644 --- a/src/raft/uv_segment.c +++ b/src/raft/uv_segment.c @@ -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; @@ -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); @@ -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);