You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by cs...@apache.org on 2023/05/03 10:07:47 UTC

[activemq] 01/02: [#9254] DataFile readRecord fallback to OS file.length in rare edge case

This is an automated email from the ASF dual-hosted git repository.

cshannon pushed a commit to branch activemq-5.18.x
in repository https://gitbox.apache.org/repos/asf/activemq.git

commit cd676023cc1989bbe565d806a5d3df3267519a51
Author: Matt Pavlovich <ma...@hyte.io>
AuthorDate: Mon May 1 20:08:16 2023 -0500

    [#9254] DataFile readRecord fallback to OS file.length in rare edge case
    
    (cherry picked from commit 3e61a200d07c4f788542e3e0a434e3e7db25cd81)
---
 .../store/kahadb/disk/journal/DataFileAccessor.java         | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/activemq-kahadb-store/src/main/java/org/apache/activemq/store/kahadb/disk/journal/DataFileAccessor.java b/activemq-kahadb-store/src/main/java/org/apache/activemq/store/kahadb/disk/journal/DataFileAccessor.java
index 57df143b56..c9671f2820 100644
--- a/activemq-kahadb-store/src/main/java/org/apache/activemq/store/kahadb/disk/journal/DataFileAccessor.java
+++ b/activemq-kahadb-store/src/main/java/org/apache/activemq/store/kahadb/disk/journal/DataFileAccessor.java
@@ -17,7 +17,6 @@
 package org.apache.activemq.store.kahadb.disk.journal;
 
 import java.io.IOException;
-import java.io.RandomAccessFile;
 import java.util.Map;
 
 import org.apache.activemq.util.ByteSequence;
@@ -85,7 +84,17 @@ final class DataFileAccessor {
                 file.seek(location.getOffset() + Journal.RECORD_HEAD_SPACE);
             }
             if ((long)location.getOffset() + location.getSize() > dataFile.length) {
-                throw new IOException("Invalid location size: " + location + ", size: " + location.getSize());
+                /**
+                 * AMQ-9254 if the read request is outside expected dataFile length, 
+                 *          perform expensive OS file length lookup operation 
+                 *          to allow read operation if it will succeed
+                 */
+                long osFileLength = dataFile.getFile().length();
+                if((long)location.getOffset() + location.getSize() > osFileLength) {
+                    throw new IOException("Invalid location size: " + location + ", size: " + location.getSize());
+                } else {
+                    LOG.warn("DataFile:{} actual length:{} larger than expected:{} for readRecord location:{} size:{}", dataFile.file.getName(), osFileLength, dataFile.length, location, location.getSize());
+                }
             }
             byte[] data = new byte[location.getSize() - Journal.RECORD_HEAD_SPACE];
             file.readFully(data);