AHeise commented on a change in pull request #10952: [FLINK-15777][filesystem]Determine Hadoop version with fs classpath. URL: https://github.com/apache/flink/pull/10952#discussion_r371300568
########## File path: flink-filesystems/flink-hadoop-fs/src/main/java/org/apache/flink/runtime/fs/hdfs/HadoopRecoverableFsDataOutputStream.java ########## @@ -175,44 +172,39 @@ private static void safelyTruncateFile( } } - private static void ensureTruncateInitialized() throws FlinkRuntimeException { - if (HadoopUtils.isMinHadoopVersion(2, 7) && truncateHandle == null) { - Method truncateMethod; + private static Method findTrunacteMethod(FileSystem fs) throws FlinkRuntimeException { + Method truncateMethod = null; + if (HadoopUtils.isMinHadoopVersion(fs.getClass().getClassLoader(), 2, 7)) { try { - truncateMethod = FileSystem.class.getMethod("truncate", Path.class, long.class); - } - catch (NoSuchMethodException e) { + truncateMethod = fs.getClass().getMethod("truncate", Path.class, long.class); + } catch (NoSuchMethodException e) { throw new FlinkRuntimeException("Could not find a public truncate method on the Hadoop File System."); } - - if (!Modifier.isPublic(truncateMethod.getModifiers())) { - throw new FlinkRuntimeException("Could not find a public truncate method on the Hadoop File System."); - } - - truncateHandle = truncateMethod; } + + return truncateMethod; } - private static boolean truncate(final FileSystem hadoopFs, final Path file, final long length) throws IOException { - if (!HadoopUtils.isMinHadoopVersion(2, 7)) { - throw new IllegalStateException("Truncation is not available in hadoop version < 2.7 , You are on Hadoop " + VersionInfo.getVersion()); + private static boolean truncate( Review comment: > Do we need some new test coverage? Yes, but I don't have a good idea for a non-complicated test setup. In theory, we would need to have a test matrix where we co-ship Flink with hadoop 2.6 and 2.8 and have plugins with hadoop 2.6 and 2.8. ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services