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


##########
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;
+
+                    if (write && (position + i) == size())
+                        errorMsg = "Write operation unsuccessful, write 
timeout exceeds the maximum IO timeout ("

Review Comment:
   Please add braces when statements are more than in one line. See
   
https://cwiki.apache.org/confluence/display/IGNITE/Coding+Guidelines#CodingGuidelines-BracesandIndentation
   > Braces are required in all cases, even if not required by syntax, except 
for the cases when the next statement is a one-liner.
   



##########
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;
+
+                    if (write && (position + i) == size())
+                        errorMsg = "Write operation unsuccessful, write 
timeout exceeds the maximum IO timeout ("
+                            + U.millisToNanos(MAX_IO_TIMEOUT_MS) + " ms); 
failed to extend file.";
+                    else if (write)
+                        errorMsg = "Write operation unsuccessful, write 
timeout exceeds the maximum IO timeout ("

Review Comment:
   Please add braces.



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