You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ozone.apache.org by GitBox <gi...@apache.org> on 2021/08/20 10:02:33 UTC

[GitHub] [ozone] ChenSammi commented on a change in pull request #2538: HDDS-5619. Ozone data corruption issue on follower node.

ChenSammi commented on a change in pull request #2538:
URL: https://github.com/apache/ozone/pull/2538#discussion_r692827259



##########
File path: hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/keyvalue/helpers/ChunkUtils.java
##########
@@ -183,17 +180,39 @@ private static long writeDataToChannel(FileChannel channel, ChunkBuffer data,
   public static void readData(File file, ByteBuffer[] buffers,
       long offset, long len, HddsVolume volume)
       throws StorageContainerException {
+    readData(file, null, buffers, offset, len, volume);
+  }
+
+  public static void readData(File file, FileChannel channel,
+      ByteBuffer[] buffers, long offset, long len, HddsVolume volume)
+      throws StorageContainerException {
 
     final Path path = file.toPath();
     final long startTime = Time.monotonicNow();
     final long bytesRead;
+    final long endOffsetToRead = offset + len;
 
     try {
+      if (file.length() > 0) {
+        Preconditions.checkArgument(file.length() >= endOffsetToRead,
+            "file length should atleast match the last offset to read");
+      }
       bytesRead = processFileExclusively(path, () -> {
-        try (FileChannel channel = open(path, READ_OPTIONS, NO_ATTRIBUTES);
-             FileLock ignored = channel.lock(offset, len, true)) {
+        // if the file handle is already cached, just use that for reads.
+        if (channel != null) {
+          try (FileLock lock = channel.lock(offset, len, true)) {
+            channel.position(offset);
+            return channel.position(offset).read(buffers);

Review comment:
       channel.position is called twice. 




-- 
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: issues-unsubscribe@ozone.apache.org

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



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org