Skip to content

Commit

Permalink
DRILL-6349: Drill JDBC driver fails on Java 1.9+ with NoClassDefFound…
Browse files Browse the repository at this point in the history
…Error: sun/misc/VM
  • Loading branch information
oleg-zinovev committed Oct 19, 2018
1 parent 785f59b commit 0783358
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.Properties;
import java.util.concurrent.TimeUnit;

import io.netty.util.internal.PlatformDependent;
import org.apache.drill.common.exceptions.DrillConfigurationException;
import org.apache.drill.common.exceptions.UserException;
import org.apache.drill.common.scanner.ClassPathScanner;
Expand All @@ -46,7 +47,7 @@ public class DrillConfig extends NestedConfig {
private final ImmutableList<String> startupArguments;

@SuppressWarnings("restriction")
private static final long MAX_DIRECT_MEMORY = sun.misc.VM.maxDirectMemory();
private static final long MAX_DIRECT_MEMORY = PlatformDependent.maxDirectMemory();

@VisibleForTesting
public DrillConfig(Config config) {
Expand Down
19 changes: 17 additions & 2 deletions exec/java-exec/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,15 @@
<!-- </dependency> -->
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm-debug-all</artifactId>
<version>5.0.3</version>
<artifactId>asm-commons</artifactId>
<version>6.2.1</version>
<!-- <scope>test</scope> -->
</dependency>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm-util</artifactId>
<version>6.2.1</version>
</dependency>
<dependency>
<groupId>org.apache.drill.contrib.data</groupId>
<artifactId>tpch-sample-data</artifactId>
Expand Down Expand Up @@ -551,6 +556,16 @@
<groupId>sqlline</groupId>
<artifactId>sqlline</artifactId>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>1.1.1</version>
</dependency>
</dependencies>

<profiles>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public class ReplacingInterpreter extends BasicInterpreter {
private final List<ReplacingBasicValue> valueList;

public ReplacingInterpreter(final String className, final List<ReplacingBasicValue> valueList) {
super(ASM5);
this.className = className;
this.valueList = valueList;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ protected void createPartitionSublists() {

// build a list of DFSDirPartitionLocation.
for (final List<String> dirs : dirToFileMap.keySet()) {
locations.add( new DFSDirPartitionLocation((String [])dirs.toArray(), dirToFileMap.get(dirs)));
locations.add( new DFSDirPartitionLocation(dirs.toArray(new String[dirs.size()]), dirToFileMap.get(dirs)));
}

locationSuperList = Lists.partition(locations, PartitionDescriptor.PARTITION_BATCH_SIZE);
Expand Down
2 changes: 2 additions & 0 deletions exec/java-exec/src/test/resources/drill-udf/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@
<includes>
<include>${include.files}</include>
</includes>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import java.sql.ResultSetMetaData;
import java.sql.SQLClientInfoException;
import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -412,6 +413,15 @@ private static class ClosedConnectionChecker
super(intf, jdbcObject, STATEMENT_CLOSED_MESSAGE);
}

@Override
protected boolean isOkayNonthrowingMethod(Method method) {
return
super.isOkayNonthrowingMethod(method)
// New Java 9 methods not implemented in Avatica.
|| method.getName().equals("beginRequest")
|| method.getName().equals("endRequest");
}

@Override
protected boolean isOkaySpecialCaseException(Method method, Throwable cause) {
final boolean result;
Expand All @@ -424,6 +434,12 @@ else if (SQLClientInfoException.class == cause.getClass()
|| method.getName().equals("getClientInfo"))) {
// Special good case--we had to use SQLClientInfoException from those.
result = true;
}
else if (SQLFeatureNotSupportedException.class == cause.getClass()
&& (method.getName().equals("setShardingKeyIfValid")
|| method.getName().equals("setShardingKey"))) {
// New Java 9 methods not implemented in Avatica.
result = true;
} else {
result = false;
}
Expand Down Expand Up @@ -453,6 +469,24 @@ private static class ClosedPlainStatementChecker
ClosedPlainStatementChecker(Class<Statement> intf, Statement jdbcObject) {
super(intf, jdbcObject, PLAIN_STATEMENT_CLOSED_MESSAGE);
}

@Override
protected boolean isOkaySpecialCaseException(Method method, Throwable cause) {
final boolean result;
if (super.isOkaySpecialCaseException(method, cause)) {
result = true;
} else if (NullPointerException.class == cause.getClass()
&& (method.getName().equals("enquoteIdentifier")
|| method.getName().equals("enquoteLiteral")
|| method.getName().equals("enquoteNCharLiteral")
|| method.getName().equals("isSimpleIdentifier"))) {
result = true;
} else {
result = false;
}

return result;
}
} // class ClosedPlainStatementChecker

@Test
Expand All @@ -477,6 +511,24 @@ private static class ClosedPreparedStatementChecker
PreparedStatement jdbcObject) {
super(intf, jdbcObject, PREPAREDSTATEMENT_CLOSED_MESSAGE);
}

@Override
protected boolean isOkaySpecialCaseException(Method method, Throwable cause) {
final boolean result;
if (super.isOkaySpecialCaseException(method, cause)) {
result = true;
} else if (NullPointerException.class == cause.getClass()
&& (method.getName().equals("enquoteIdentifier")
|| method.getName().equals("enquoteLiteral")
|| method.getName().equals("enquoteNCharLiteral")
|| method.getName().equals("isSimpleIdentifier"))) {
result = true;
} else {
result = false;
}

return result;
}
} // class closedPreparedStmtOfOpenConnChecker

@Test
Expand Down Expand Up @@ -587,7 +639,9 @@ protected boolean isOkayNonthrowingMethod(Method method) {
|| method.getName().equals("getConnection")
// TODO: New Java 8 methods not implemented in Avatica.
|| method.getName().equals("getMaxLogicalLobSize")
|| method.getName().equals("supportsRefCursors");
|| method.getName().equals("supportsRefCursors")
// New Java 9 methods not implemented in Avatica.
|| method.getName().equals("supportsSharding");
}

@Override
Expand Down
1 change: 0 additions & 1 deletion logical/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.15</version>
<configuration>
<useSystemClassLoader>false</useSystemClassLoader>
</configuration>
Expand Down
6 changes: 4 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
Expand Down Expand Up @@ -709,7 +710,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.17</version>
<version>2.21.0</version>
<executions>
<execution>
<id>default-test</id>
Expand All @@ -721,7 +722,7 @@
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>2.19.1</version>
<version>2.21.0</version>
</dependency>
</dependencies>
<configuration>
Expand All @@ -734,6 +735,7 @@
-Djava.net.preferIPv4Stack=true
-Djava.awt.headless=true
-XX:+CMSClassUnloadingEnabled -ea
-Djdk.attach.allowAttachSelf=true
</argLine>
<forkCount>${forkCount}</forkCount>
<reuseForks>true</reuseForks>
Expand Down

0 comments on commit 0783358

Please sign in to comment.