You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flink.apache.org by se...@apache.org on 2014/09/23 23:49:39 UTC

[2/6] git commit: [FLINK-1115] Local file streams retry file creation on FileNotFoundException to increase resilience against spurious failures in tests

[FLINK-1115] Local file streams retry file creation on FileNotFoundException to increase resilience against spurious failures in tests


Project: http://git-wip-us.apache.org/repos/asf/incubator-flink/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-flink/commit/1ddec930
Tree: http://git-wip-us.apache.org/repos/asf/incubator-flink/tree/1ddec930
Diff: http://git-wip-us.apache.org/repos/asf/incubator-flink/diff/1ddec930

Branch: refs/heads/master
Commit: 1ddec930a29c1d870d5b5bbde0098d10ff9b45ce
Parents: cf80d86
Author: Stephan Ewen <se...@apache.org>
Authored: Tue Sep 23 19:36:27 2014 +0200
Committer: Stephan Ewen <se...@apache.org>
Committed: Tue Sep 23 19:36:27 2014 +0200

----------------------------------------------------------------------
 .../core/fs/local/LocalDataOutputStream.java    | 27 +++++++++++++-------
 1 file changed, 18 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-flink/blob/1ddec930/flink-core/src/main/java/org/apache/flink/core/fs/local/LocalDataOutputStream.java
----------------------------------------------------------------------
diff --git a/flink-core/src/main/java/org/apache/flink/core/fs/local/LocalDataOutputStream.java b/flink-core/src/main/java/org/apache/flink/core/fs/local/LocalDataOutputStream.java
index 14ffefb..afef7c1 100644
--- a/flink-core/src/main/java/org/apache/flink/core/fs/local/LocalDataOutputStream.java
+++ b/flink-core/src/main/java/org/apache/flink/core/fs/local/LocalDataOutputStream.java
@@ -16,10 +16,10 @@
  * limitations under the License.
  */
 
-
 package org.apache.flink.core.fs.local;
 
 import java.io.File;
+import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.IOException;
 
@@ -28,14 +28,15 @@ import org.apache.flink.core.fs.FSDataOutputStream;
 /**
  * The <code>LocalDataOutputStream</code> class is a wrapper class for a data
  * output stream to the local file system.
- * 
  */
 public class LocalDataOutputStream extends FSDataOutputStream {
 
+	private static final int MAX_OPEN_TRIES = 3;
+	
 	/**
 	 * The file output stream used to write data.
 	 */
-	private FileOutputStream fos = null;
+	private FileOutputStream fos;
 
 	/**
 	 * Constructs a new <code>LocalDataOutputStream</code> object from a given {@link File} object.
@@ -46,26 +47,34 @@ public class LocalDataOutputStream extends FSDataOutputStream {
 	 *         thrown if the data output stream cannot be created
 	 */
 	public LocalDataOutputStream(final File file) throws IOException {
-
-		this.fos = new FileOutputStream(file);
+		// we allow multiple tries to create the file, to increase resilience against spurious I/O failures
+		
+		FileNotFoundException lastException = null;
+		
+		for (int attempt = 0; attempt < MAX_OPEN_TRIES; attempt++) {
+			try {
+				this.fos = new FileOutputStream(file);
+				return;
+			}
+			catch (FileNotFoundException e) {
+				lastException = e;
+			}
+		}
+		throw lastException;
 	}
 
-
 	@Override
 	public void write(final int b) throws IOException {
 		fos.write(b);
 	}
 
-
 	@Override
 	public void write(final byte[] b, final int off, final int len) throws IOException {
 		fos.write(b, off, len);
 	}
 
-
 	@Override
 	public void close() throws IOException {
-
 		fos.close();
 	}
 }