Move entry tracking to SegmentedJournalReader
[controller.git] / atomix-storage / src / main / java / io / atomix / storage / journal / SegmentEntry.java
1 /*
2  * Copyright (c) 2024 PANTHEON.tech, s.r.o. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package io.atomix.storage.journal;
9
10 import java.nio.ByteBuffer;
11
12 /**
13  * An {@link Indexed} entry read from {@link JournalSegment}.
14  *
15  * @param checksum The CRC32 checksum of data
16  * @param bytes Entry bytes
17  */
18 record SegmentEntry(int checksum, ByteBuffer bytes) {
19     /**
20      * The size of the header, comprising of:
21      * <ul>
22      *   <li>32-bit signed entry length</li>
23      *   <li>32-bit unsigned CRC32 checksum</li>
24      * </li>
25      */
26     static final int HEADER_BYTES = Integer.BYTES + Integer.BYTES;
27
28     SegmentEntry {
29         if (bytes.remaining() < 1) {
30             throw new IllegalArgumentException("Invalid entry bytes " + bytes);
31         }
32     }
33 }