sashapolo commented on code in PR #6702:
URL: https://github.com/apache/ignite-3/pull/6702#discussion_r2416119387
##########
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:
What's "real size"?
--
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]