From cc97ea188e1d5b8e851d1a8438b8af092783ec04 Mon Sep 17 00:00:00 2001 From: Steve Loughran Date: Wed, 17 Aug 2016 11:42:57 -0700 Subject: [SPARK-16736][CORE][SQL] purge superfluous fs calls A review of the code, working back from Hadoop's `FileSystem.exists()` and `FileSystem.isDirectory()` code, then removing uses of the calls when superfluous. 1. delete is harmless if called on a nonexistent path, so don't do any checks before deletes 1. any `FileSystem.exists()` check before `getFileStatus()` or `open()` is superfluous as the operation itself does the check. Instead the `FileNotFoundException` is caught and triggers the downgraded path. When a `FileNotFoundException` was thrown before, the code still creates a new FNFE with the error messages. Though now the inner exceptions are nested, for easier diagnostics. Initially, relying on Jenkins test runs. One troublespot here is that some of the codepaths are clearly error situations; it's not clear that they have coverage anyway. Trying to create the failure conditions in tests would be ideal, but it will also be hard. Author: Steve Loughran Closes #14371 from steveloughran/cloud/SPARK-16736-superfluous-fs-calls. --- .../main/scala/org/apache/spark/repl/ExecutorClassLoader.scala | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'repl/src') diff --git a/repl/src/main/scala/org/apache/spark/repl/ExecutorClassLoader.scala b/repl/src/main/scala/org/apache/spark/repl/ExecutorClassLoader.scala index 2f07395edf..df13b32451 100644 --- a/repl/src/main/scala/org/apache/spark/repl/ExecutorClassLoader.scala +++ b/repl/src/main/scala/org/apache/spark/repl/ExecutorClassLoader.scala @@ -17,7 +17,7 @@ package org.apache.spark.repl -import java.io.{ByteArrayOutputStream, FilterInputStream, InputStream, IOException} +import java.io.{ByteArrayOutputStream, FileNotFoundException, FilterInputStream, InputStream, IOException} import java.net.{HttpURLConnection, URI, URL, URLEncoder} import java.nio.channels.Channels @@ -147,10 +147,11 @@ class ExecutorClassLoader( private def getClassFileInputStreamFromFileSystem(fileSystem: FileSystem)( pathInDirectory: String): InputStream = { val path = new Path(directory, pathInDirectory) - if (fileSystem.exists(path)) { + try { fileSystem.open(path) - } else { - throw new ClassNotFoundException(s"Class file not found at path $path") + } catch { + case _: FileNotFoundException => + throw new ClassNotFoundException(s"Class file not found at path $path") } } -- cgit v1.2.3