You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@bookkeeper.apache.org by "hangc0276 (via GitHub)" <gi...@apache.org> on 2023/04/18 04:14:49 UTC

[GitHub] [bookkeeper] hangc0276 commented on a diff in pull request #3437: Issue #2220: support skip invalid record in recovery

hangc0276 commented on code in PR #3437:
URL: https://github.com/apache/bookkeeper/pull/3437#discussion_r1169469405


##########
bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/Journal.java:
##########
@@ -884,22 +885,31 @@ public long scanJournal(long journalId, long journalPos, JournalScanner scanner)
                 }
                 boolean isPaddingRecord = false;
                 if (len < 0) {
-                    if (len == PADDING_MASK && journalVersion >= JournalChannel.V5) {
-                        // skip padding bytes
-                        lenBuff.clear();
-                        fullRead(recLog, lenBuff);
-                        if (lenBuff.remaining() != 0) {
-                            break;
+                    try {
+                        if (len == PADDING_MASK && journalVersion >= JournalChannel.V5) {
+                            // skip padding bytes
+                            lenBuff.clear();
+                            fullRead(recLog, lenBuff);
+                            if (lenBuff.remaining() != 0) {
+                                break;
+                            }
+                            lenBuff.flip();
+                            len = lenBuff.getInt();
+                            if (len == 0) {
+                                continue;
+                            }
+                            isPaddingRecord = true;
+                        } else {
+                            LOG.error("Invalid record found with negative length: {}", len);
+                            throw new IOException("Invalid record found with negative length " + len);
                         }
-                        lenBuff.flip();
-                        len = lenBuff.getInt();
-                        if (len == 0) {
-                            continue;
+                    } catch (IOException e) {
+                        if (skipInvalidRecord) {

Review Comment:
   If we just skip one record and continue to read the next one, I'm afraid it will cause ledger data errors. Because when one journal file is broken, the rest of the data will be organized in the wrong way and we can't parse it.



-- 
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: commits-unsubscribe@bookkeeper.apache.org

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