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


##########
modules/raft/src/main/java/org/apache/ignite/internal/raft/storage/segstore/SegstoreLogStorage.java:
##########
@@ -87,8 +92,12 @@ public long getLastLogIndex() {
     }
 
     @Override
-    public LogEntry getEntry(long index) {
-        throw new UnsupportedOperationException();
+    public @Nullable LogEntry getEntry(long index) {
+        try {
+            return segmentFileManager.getEntry(groupId, index, 
logEntryDecoder);
+        } catch (IOException e) {
+            throw new IgniteInternalException(INTERNAL_ERR, e);

Review Comment:
   Should we use more specific error code  + add message? 



##########
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:
   ```suggestion
       static int realSize(int entrySize) {
   ```
   
   (not insisting)



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to