return 0;
}
+static uint64_t inc_seqnum(uint64_t seqnum) {
+ if (seqnum < UINT64_MAX-1)
+ return seqnum + 1;
+
+ return 1; /* skip over UINT64_MAX and 0 when we run out of seqnums and start again */
+}
+
static uint64_t journal_file_entry_seqnum(
JournalFile *f,
uint64_t *seqnum) {
- uint64_t ret;
+ uint64_t next_seqnum;
assert(f);
assert(f->header);
/* Picks a new sequence number for the entry we are about to add and returns it. */
- ret = le64toh(f->header->tail_entry_seqnum) + 1;
+ next_seqnum = inc_seqnum(le64toh(f->header->tail_entry_seqnum));
- if (seqnum) {
- /* If an external seqnum counter was passed, we update both the local and the external one,
- * and set it to the maximum of both */
-
- if (*seqnum + 1 > ret)
- ret = *seqnum + 1;
-
- *seqnum = ret;
- }
+ /* If an external seqnum counter was passed, we update both the local and the external one, and set
+ * it to the maximum of both */
+ if (seqnum)
+ *seqnum = next_seqnum = MAX(inc_seqnum(*seqnum), next_seqnum);
- f->header->tail_entry_seqnum = htole64(ret);
+ f->header->tail_entry_seqnum = htole64(next_seqnum);
if (f->header->head_entry_seqnum == 0)
- f->header->head_entry_seqnum = htole64(ret);
+ f->header->head_entry_seqnum = htole64(next_seqnum);
- return ret;
+ return next_seqnum;
}
int journal_file_append_object(