Phillippko commented on code in PR #6702:
URL: https://github.com/apache/ignite-3/pull/6702#discussion_r2416190390


##########
modules/raft/src/main/java/org/apache/ignite/internal/raft/storage/segstore/SegmentPayload.java:
##########
@@ -70,8 +61,43 @@ void writeTo(ByteBuffer buffer) {
         buffer.putInt(crc);
     }
 
-    int size() {
-        return overheadSize() + payloadSize;
+    static LogEntry readFrom(ByteBuffer buffer, LogEntryDecoder 
logEntryDecoder) {
+        int entrySize = buffer.getInt(buffer.position() + GROUP_ID_SIZE_BYTES);
+
+        verifyCrc(buffer, entrySize);
+
+        buffer.position(buffer.position() + GROUP_ID_SIZE_BYTES + 
LENGTH_SIZE_BYTES);
+
+        // TODO: https://issues.apache.org/jira/browse/IGNITE-26623.
+        byte[] entryBytes = new byte[entrySize];
+
+        buffer.get(entryBytes);
+
+        // Move the position as if we have read the whole payload.
+        buffer.position(buffer.position() + HASH_SIZE);
+
+        return logEntryDecoder.decode(entryBytes);
+    }
+
+    private static void verifyCrc(ByteBuffer buffer, int entrySize) {
+        int position = buffer.position();
+
+        int dataSize = size(entrySize) - HASH_SIZE;
+
+        int expectedCrc = buffer.getInt(position + dataSize);
+
+        int actualCrc = FastCrc.calcCrc(buffer, dataSize);
+
+        // calcCrc alters the position.
+        buffer.position(position);
+
+        if (expectedCrc != actualCrc) {
+            throw new IllegalStateException("CRC mismatch, expected: " + 
expectedCrc + ", actual: " + actualCrc);
+        }
+    }
+
+    static int size(int entrySize) {

Review Comment:
   I wanted to make it more obvious that "size" method returns size with 
overhead
   
   in AI2 we use term "realPageSize", but now I realized it is a page size 
EXCLUDING overhead, not including, so ignore this comment :) 
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscr...@ignite.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to