yurinaryshkin commented on code in PR #11294:
URL: https://github.com/apache/ignite/pull/11294#discussion_r1551239146


##########
modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/file/AbstractFileIO.java:
##########
@@ -46,29 +46,44 @@ private interface IOOperation {
      * @param num Number of bytes to operate.
      */
     private int fully(IOOperation operation, long position, int num, boolean 
write) throws IOException {
-        if (num > 0) {
-            long time = 0;
+        if (num <= 0)
+            return num;
 
-            for (int i = 0; i < num; ) {
-                int n = operation.run(i);
+        long time = 0;
 
-                if (n > 0) {
-                    i += n;
-                    time = 0;
-                }
-                else if (n == 0 || i > 0) {
-                    if (!write && available(num - i, position + i) == 0)
-                        return i;
-
-                    if (time == 0)
-                        time = System.nanoTime();
-                    else if ((System.nanoTime() - time) >= 
U.millisToNanos(MAX_IO_TIMEOUT_MS))
-                        throw new IOException(write && (position + i) == 
size() ? "Failed to extend file." :
-                            "Probably disk is too busy, please check your 
device.");
+        for (int i = 0; i < num; ) {
+            int n = operation.run(i);
+
+            if (n > 0) {
+                i += n;
+                time = 0;
+            }
+            else if (n == 0 || i > 0) {
+                /* Condition for reaching the end of file while there's still 
space in buffer
+                  OR for the case when the buffer is full but there's still 
data to read from file */
+                if (!write && available(num - i, position + i) == 0)
+                    return i;
+
+                if (time == 0)
+                    time = System.nanoTime();
+                else if ((System.nanoTime() - time) >= 
U.millisToNanos(MAX_IO_TIMEOUT_MS)) {
+                    String errorMsg;

Review Comment:
   Looks like the variable isn't needed. Instead of setting it, you can just 
throw exception. And "else" parts aren't really required.
   You can write something like this
   ```
   
                           if (write) {
                               if (position + i == size())
                                   throw 1;
                               throw 2;
                           }
                           throw 3;
   
   ```



-- 
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