39 static_assert(
sizeof(
Entry) %
alignof(
Entry) == 0);
41 auto* header =
reinterpret_cast<FileHeader*
>(file_.data());
42 const bool blank = std::all_of(file_.data(), file_.data() +
sizeof(
FileHeader), [](uint8_t b) { return b == 0; });
48 fresh.
first_seq = std::max<uint64_t>(first_seq, 1);
50 std::memcpy(header, &fresh,
sizeof(
FileHeader));
51 }
else if (std::memcmp(header->magic, format.
magic,
sizeof(header->magic)) != 0) {
52 throw std::runtime_error(std::string(format.
name) +
": " +
path +
" is not a fill journal");
53 }
else if (header->version != format.
version || header->entry_size !=
sizeof(
Entry) ||
55 throw std::runtime_error(std::string(format.
name) +
": " +
path +
56 " was written with a different layout (version " +
57 std::to_string(header->version) +
")");
60 capacity_ =
static_cast<size_t>(header->capacity);
62 LOG_WARN(
"{}: {} keeps the capacity it was created with, {} fills, not {}", format.
name, path_, capacity_,
66 uint64_t last_seq = 0;
67 std::unordered_map<uint64_t, uint64_t> newest;
68 for (
size_t i = 0; i < capacity_; ++i) {
69 const Entry& e = entry(i);
81 next_seq_ = std::max({last_seq + 1, header->first_seq, header->next_seq});
82 LOG_INFO(
"{}: {} holds {} fill(s), room for {}", format.
name, path_, size_, capacity_);
125 std::vector<const Entry*> held;
127 for (
size_t i = 0; i < capacity_; ++i) {
128 if (entry(i).journal_seq != 0) {
129 held.push_back(&entry(i));
132 std::sort(held.begin(), held.end(), [](
const Entry* a,
const Entry* b) { return a->journal_seq < b->journal_seq; });
133 std::vector<OrderFillEvent> out;
134 out.reserve(held.size());
135 for (
const Entry* e : held) {
136 out.push_back(e->fill);