Skip to content

Commit

Permalink
Fix supportVectoredIO for bad hadoop version string
Browse files Browse the repository at this point in the history
There are cases where the hadoop version info may not be respecting
the semantic versioning. It is the case for the hadoop version
provided in some of the AWS managed services. This causes
a ExceptionInInitializerError while trying to instantiate and ORC
file reader.

Fixing this by defaulting to non vectored IO in case the semantic
versioning is not respected
  • Loading branch information
otorreno committed Jul 25, 2024
1 parent e818d56 commit a2afdd0
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hive.common.io.DiskRangeList;
import org.apache.hadoop.util.VersionInfo;
import org.apache.orc.CompressionCodec;
import org.apache.orc.DataReader;
import org.apache.orc.OrcProto;
Expand All @@ -48,7 +49,7 @@
*/
public class RecordReaderUtils {
private static final HadoopShims SHIMS = HadoopShimsFactory.get();
private static final boolean supportVectoredIO = SHIMS.supportVectoredIO();
private static final boolean supportVectoredIO = SHIMS.supportVectoredIO(VersionInfo.getVersion());
private static final Logger LOG = LoggerFactory.getLogger(RecordReaderUtils.class);

private static class DefaultDataReader implements DataReader {
Expand Down
20 changes: 13 additions & 7 deletions java/shims/src/java/org/apache/orc/impl/HadoopShims.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,19 @@ ByteBuffer readBuffer(int maxLength,
*/
boolean endVariableLengthBlock(OutputStream output) throws IOException;

default boolean supportVectoredIO() {
// HADOOP-18103 is available since Apache Hadoop 3.3.5+
String[] versionParts = VersionInfo.getVersion().split("[.]");
int major = Integer.parseInt(versionParts[0]);
int minor = Integer.parseInt(versionParts[1]);
int patch = Integer.parseInt(versionParts[2]);
return major == 3 && (minor > 3 || (minor == 3 && patch > 4));
default boolean supportVectoredIO(String version) {
try {
// HADOOP-18103 is available since Apache Hadoop 3.3.5+
String[] versionParts = version.split("[.]");
int major = Integer.parseInt(versionParts[0]);
int minor = Integer.parseInt(versionParts[1]);
int patch = Integer.parseInt(versionParts[2]);
return major == 3 && (minor > 3 || (minor == 3 && patch > 4));
} catch (final NumberFormatException e) {
// There could be cases where we are not able to parse the version
// Here we are defaulting to the non vectoredIO if that is the case
return false;
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.orc.impl;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;

public class TestHadoopShimsPost3_3_4 {

@Test
public void testWrongVersionForSupportVectoredIO() {
assertFalse(new HadoopShimsCurrent().supportVectoredIO("3.3.6-co-3"));
}

@Test
public void testOlderVersionForSupportVectoredIO() {
assertFalse(new HadoopShimsCurrent().supportVectoredIO("3.3.4"));
}

@Test
public void testSupportedVersionForSupportVectoredIO() {
assertTrue(new HadoopShimsCurrent().supportVectoredIO("3.3.5"));
}
}

0 comments on commit a2afdd0

Please sign in to comment.