Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patch phoenix5 client to work with JDK17 #13108

Merged
merged 1 commit into from
Jul 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 90 additions & 0 deletions lib/trino-phoenix5-patched/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- TODO(https://github.com/trinodb/trino/issues/13051): Remove whole module when Phoenix5 is released -->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>io.trino</groupId>
<artifactId>trino-root</artifactId>
<version>389-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

<artifactId>trino-phoenix5-patched</artifactId>
<name>trino-phoenix5-patched</name>
<description>Trino - patched Phoenix5 client to work with JDK17</description>

<properties>
<air.main.basedir>${project.parent.basedir}</air.main.basedir>
</properties>

<dependencies>
<dependency>
<groupId>org.apache.phoenix</groupId>
<artifactId>phoenix-client-embedded-hbase-2.2</artifactId>
<version>5.1.2</version>
</dependency>

<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.3.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<createDependencyReducedPom>true</createDependencyReducedPom>
<createSourcesJar>false</createSourcesJar>
<shadeSourcesContent>false</shadeSourcesContent>
<dependencyReducedPomLocation>${project.build.directory}/pom.xml</dependencyReducedPomLocation>
<promoteTransitiveDependencies>false</promoteTransitiveDependencies>
<artifactSet>
<excludes>
</excludes>
</artifactSet>
<relocations>
<relocation>
<pattern>org.apache.zookeeper</pattern>
<shadedPattern>org.apache.phoenix.shaded.org.apache.zookeeper</shadedPattern>
</relocation>
</relocations>
<filters>
<filter>
<artifact>org.apache.phoenix:phoenix-client-embedded-hbase-2.2</artifact>
<excludes>
<exclude>org/apache/phoenix/shaded/org/apache/zookeeper/client/StaticHostProvider.class</exclude>
<exclude>org/apache/phoenix/shaded/org/apache/zookeeper/client/StaticHostProvider$*.class</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.basepom.maven</groupId>
<artifactId>duplicate-finder-maven-plugin</artifactId>
<configuration>
<ignoredDependencies>
<dependency>
<groupId>org.apache.phoenix</groupId>
<artifactId>phoenix-client-embedded-hbase-2.2</artifactId>
</dependency>
</ignoredDependencies>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
/*
* Licensed 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.phoenix.shaded.org.apache.zookeeper.client;

import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

// TODO(https://github.com/trinodb/trino/issues/13051): Remove when Phoenix 5.2 is release
public final class StaticHostProvider
implements HostProvider
{
public interface Resolver
{
InetAddress[] getAllByName(String name) throws UnknownHostException;
}

private final List<InetSocketAddress> serverAddresses = new ArrayList<InetSocketAddress>(5);

private int lastIndex = -1;

private int currentIndex = -1;

private Resolver resolver;

/**
* Constructs a SimpleHostSet.
*
* @param serverAddresses
* possibly unresolved ZooKeeper server addresses
* @throws IllegalArgumentException
* if serverAddresses is empty or resolves to an empty list
*/
public StaticHostProvider(Collection<InetSocketAddress> serverAddresses)
{
this.resolver = name -> InetAddress.getAllByName(name);
init(serverAddresses);
}

/**
* Introduced for testing purposes. getAllByName() is a static method of InetAddress, therefore cannot be easily mocked.
* By abstraction of Resolver interface we can easily inject a mocked implementation in tests.
*
* @param serverAddresses
* possibly unresolved ZooKeeper server addresses
* @param resolver
* custom resolver implementation
* @throws IllegalArgumentException
* if serverAddresses is empty or resolves to an empty list
*/
public StaticHostProvider(Collection<InetSocketAddress> serverAddresses, Resolver resolver)
{
this.resolver = resolver;
init(serverAddresses);
}

/**
* Common init method for all constructors.
* Resolve all unresolved server addresses, put them in a list and shuffle.
*/
private void init(Collection<InetSocketAddress> serverAddresses)
{
if (serverAddresses.isEmpty()) {
throw new IllegalArgumentException(
"A HostProvider may not be empty!");
}

this.serverAddresses.addAll(serverAddresses);
Collections.shuffle(this.serverAddresses);
}

/**
* Evaluate to a hostname if one is available and otherwise it returns the
* string representation of the IP address.
*
* In Java 7, we have a method getHostString, but earlier versions do not support it.
* This method is to provide a replacement for InetSocketAddress.getHostString().
*
* @param addr
* @return Hostname string of address parameter
*/
private String getHostString(InetSocketAddress addr)
{
String hostString = "";

if (addr == null) {
return hostString;
}
if (!addr.isUnresolved()) {
InetAddress ia = addr.getAddress();

// If the string starts with '/', then it has no hostname
// and we want to avoid the reverse lookup, so we return
// the string representation of the address.
if (ia.toString().startsWith("/")) {
hostString = ia.getHostAddress();
}
else {
hostString = addr.getHostName();
}
}
else {
hostString = addr.getHostString();
}

return hostString;
}

@Override
public int size()
{
return serverAddresses.size();
}

@Override
public InetSocketAddress next(long spinDelay)
{
currentIndex = ++currentIndex % serverAddresses.size();
if (currentIndex == lastIndex && spinDelay > 0) {
try {
Thread.sleep(spinDelay);
}
catch (InterruptedException e) {
}
}
else if (lastIndex == -1) {
// We don't want to sleep on the first ever connect attempt.
lastIndex = 0;
}

InetSocketAddress curAddr = serverAddresses.get(currentIndex);
try {
String curHostString = getHostString(curAddr);
List<InetAddress> resolvedAddresses = new ArrayList<InetAddress>(Arrays.asList(this.resolver.getAllByName(curHostString)));
if (resolvedAddresses.isEmpty()) {
return curAddr;
}
Collections.shuffle(resolvedAddresses);
return new InetSocketAddress(resolvedAddresses.get(0), curAddr.getPort());
}
catch (UnknownHostException e) {
return curAddr;
}
}

@Override
public void onConnected()
{
lastIndex = currentIndex;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Licensed 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.phoenix;

import org.testng.annotations.Test;

public class TestDummy
{
@Test
public void buildRequiresTestToExist() {}
}
42 changes: 36 additions & 6 deletions plugin/trino-phoenix5/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@
<properties>
<air.main.basedir>${project.parent.basedir}</air.main.basedir>
<dep.hbase.version>2.2.6</dep.hbase.version>

<!-- This is required for JDK 17 to start HBase server due to illegal reflective access -->
<air.test.jvm.additional-arguments>
--add-opens=java.base/sun.nio.ch=ALL-UNNAMED
--add-opens=java.base/java.nio=ALL-UNNAMED
</air.test.jvm.additional-arguments>
</properties>

<dependencies>
Expand All @@ -24,6 +30,18 @@
<artifactId>trino-base-jdbc</artifactId>
</dependency>

<!-- TODO(https://github.com/trinodb/trino/issues/13051): Use org.apache.phoenix:phoenix-client-embedded-hbase-2.4:5.2.0 instead when Phoenix 5.2 is released -->
<dependency>
<groupId>io.trino</groupId>
<artifactId>trino-phoenix5-patched</artifactId>
<exclusions>
<exclusion>
<groupId>org.apache.phoenix</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>io.trino</groupId>
<artifactId>trino-plugin-toolkit</artifactId>
Expand Down Expand Up @@ -84,12 +102,6 @@
<artifactId>joda-time</artifactId>
</dependency>

<dependency>
<groupId>org.apache.phoenix</groupId>
<artifactId>phoenix-client-embedded-hbase-2.2</artifactId>
<version>5.1.2</version>
</dependency>

<dependency>
<groupId>org.gaul</groupId>
<artifactId>modernizer-maven-annotations</artifactId>
Expand Down Expand Up @@ -367,9 +379,27 @@
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.phoenix</groupId>
<artifactId>phoenix-client-embedded-hbase-2.2</artifactId>
</dependency>
</ignoredDependencies>
</configuration>
</plugin>
</plugins>
</build>

<!-- TODO(https://github.com/trinodb/trino/issues/13051): Remove, this is a workaround for errorprone which can't see shaded jar produced in package phase -->
<profiles>
<profile>
<id>errorprone-compiler</id>
<dependencies>
<dependency>
<groupId>org.apache.phoenix</groupId>
<artifactId>phoenix-client-embedded-hbase-2.2</artifactId>
<version>5.1.2</version>
</dependency>
</dependencies>
</profile>
</profiles>
</project>
11 changes: 10 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@
<module>lib/trino-memory-context</module>
<module>lib/trino-orc</module>
<module>lib/trino-parquet</module>
<!-- TODO(https://github.com/trinodb/trino/issues/13051): Remove whole module when Phoenix5 is released -->
<module>lib/trino-phoenix5-patched</module>
<module>lib/trino-plugin-toolkit</module>
<module>lib/trino-rcfile</module>
<module>lib/trino-record-decoder</module>
Expand Down Expand Up @@ -440,6 +442,13 @@
<version>${project.version}</version>
</dependency>

<!-- TODO(https://github.com/trinodb/trino/issues/13051): Remove when Phoenix5 is released -->
<dependency>
<groupId>io.trino</groupId>
<artifactId>trino-phoenix5-patched</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>io.trino</groupId>
<artifactId>trino-pinot</artifactId>
Expand Down Expand Up @@ -1979,7 +1988,7 @@
<plugin>
<groupId>io.github.gitflow-incremental-builder</groupId>
<artifactId>gitflow-incremental-builder</artifactId>
<version>4.1.0</version>
<version>4.1.1</version>
<extensions>true</extensions>
<configuration>
<disableIfBranchMatches>master</disableIfBranchMatches>
Expand Down