Skip to content

Commit

Permalink
[Enhancement] Change FE compile source/target to 17 (StarRocks#53617)
Browse files Browse the repository at this point in the history
1. Copy UnmodifiableCollectionsSerializer.java to our repository to fix compilable issue:
`Unable to make field final java.util.Collection java.util.Collections$UnmodifiableCollection.c accessible: module java.base does not "opens java.util" to unnamed module @61322f9d `
  Refer to magro/kryo-serializers#131
2. Upgrade jacoco to 0.8.8
3. For the arrow flight server, users should add `--add-opens=java.base/java.nio=org.apache.arrow.memory.core,ALL-UNNAMED` to JAVA_OPTS 
  Refer to https://arrow.apache.org/docs/java/install.html
4. Fix some UT

Signed-off-by: gengjun-git <[email protected]>
  • Loading branch information
gengjun-git authored and magzhu committed Jan 6, 2025
1 parent d3c9880 commit 91c1210
Show file tree
Hide file tree
Showing 6 changed files with 181 additions and 19 deletions.
16 changes: 2 additions & 14 deletions fe/fe-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ under the License.
<properties>
<starrocks.home>${basedir}/../../</starrocks.home>
<fe_ut_parallel>${env.FE_UT_PARALLEL}</fe_ut_parallel>
<jacoco.version>0.8.7</jacoco.version>
<jacoco.version>0.8.8</jacoco.version>
<iceberg.version>1.6.0</iceberg.version>
<paimon.version>0.8.2</paimon.version>
<delta-kernel.version>4.0.0rc1</delta-kernel.version>
Expand Down Expand Up @@ -339,18 +339,6 @@ under the License.
<version>${iceberg.version}</version>
</dependency>

<dependency>
<groupId>de.javakaffee</groupId>
<artifactId>kryo-serializers</artifactId>
<version>0.45</version>
<exclusions>
<exclusion>
<groupId>com.esotericsoftware</groupId>
<artifactId>kryo</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>io.delta</groupId>
<artifactId>delta-kernel-api</artifactId>
Expand Down Expand Up @@ -1146,7 +1134,7 @@ under the License.
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.7</version>
<version>${jacoco.version}</version>
<executions>
<execution>
<id>default-prepare-agent</id>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import com.starrocks.thrift.TIcebergMetadata;
import com.starrocks.thrift.TMetadataEntry;
import com.starrocks.thrift.TResultBatch;
import de.javakaffee.kryoserializers.UnmodifiableCollectionsSerializer;
import org.apache.iceberg.expressions.ResidualEvaluator;
import org.apache.iceberg.metrics.ScanMetrics;
import org.apache.iceberg.metrics.ScanMetricsUtil;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
// Copyright 2021-present StarRocks, Inc. All rights reserved.
//
// 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
//
// https://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.iceberg;

import com.esotericsoftware.kryo.Kryo;
import com.esotericsoftware.kryo.Serializer;
import com.esotericsoftware.kryo.io.Input;
import com.esotericsoftware.kryo.io.Output;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.SortedMap;
import java.util.SortedSet;
import java.util.TreeMap;
import java.util.TreeSet;

/**
* copy from <a href="https://github.com/opentripplanner/OpenTripPlanner/tree/dev-2.x/application/src/main/java/org/opentripplanner/kryo/UnmodifiableCollectionsSerializer.java">...</a>
* A kryo {@link Serializer} for unmodifiable {@link Collection}s and {@link Map}s created via
* {@link Collections}.
*
* @author <a href="mailto:[email protected]">Martin Grotzke</a>
*/
public class UnmodifiableCollectionsSerializer extends Serializer<Object> {

/**
* Creates a new {@link UnmodifiableCollectionsSerializer} and registers its serializer for the
* several unmodifiable Collections that can be created via {@link Collections}, including {@link
* Map}s.
*
* @param kryo the {@link Kryo} instance to set the serializer on.
* @see Collections#unmodifiableCollection(Collection)
* @see Collections#unmodifiableList(List)
* @see Collections#unmodifiableSet(Set)
* @see Collections#unmodifiableSortedSet(SortedSet)
* @see Collections#unmodifiableMap(Map)
* @see Collections#unmodifiableSortedMap(SortedMap)
*/
public static void registerSerializers(Kryo kryo) {
UnmodifiableCollectionsSerializer serializer = new UnmodifiableCollectionsSerializer();
UnmodifiableCollection.values();
for (UnmodifiableCollection item : UnmodifiableCollection.values()) {
kryo.register(item.type, serializer);
}
}

@Override
public void write(Kryo kryo, Output output, Object object) {
try {
UnmodifiableCollection unmodifiableCollection = UnmodifiableCollection.valueOfType(
object.getClass()
);
// the ordinal could be replaced by s.th. else (e.g. a explicitely managed "id")
output.writeInt(unmodifiableCollection.ordinal(), true);
kryo.writeClassAndObject(output, getValues(object));
} catch (RuntimeException e) {
// Don't eat and wrap RuntimeExceptions because the ObjectBuffer.write...
// handles SerializationException specifically (resizing the buffer)...
throw e;
} catch (Exception e) {
throw new RuntimeException(e);
}
}

@Override
public Object read(Kryo kryo, Input input, Class<Object> clazz) {
int ordinal = input.readInt(true);
UnmodifiableCollection unmodifiableCollection = UnmodifiableCollection.values()[ordinal];
Object sourceCollection = kryo.readClassAndObject(input);
return unmodifiableCollection.create(sourceCollection);
}

@Override
public Object copy(Kryo kryo, Object original) {
try {
UnmodifiableCollection unmodifiableCollection = UnmodifiableCollection.valueOfType(
original.getClass()
);
Object sourceCollectionCopy = kryo.copy(getValues(original));
return unmodifiableCollection.create(sourceCollectionCopy);
} catch (RuntimeException e) {
// Don't eat and wrap RuntimeExceptions
throw e;
} catch (Exception e) {
throw new RuntimeException(e);
}
}

private Collection<?> getValues(Object coll) {
return new ArrayList<>((Collection) coll);
}

private enum UnmodifiableCollection {
COLLECTION(Collections.unmodifiableCollection(Arrays.asList("")).getClass()) {
@Override
public Object create(Object sourceCollection) {
return Collections.unmodifiableCollection((Collection<?>) sourceCollection);
}
},
RANDOM_ACCESS_LIST(Collections.unmodifiableList(new ArrayList<Void>()).getClass()) {
@Override
public Object create(Object sourceCollection) {
return Collections.unmodifiableList((List<?>) sourceCollection);
}
},
LIST(Collections.unmodifiableList(new LinkedList<Void>()).getClass()) {
@Override
public Object create(Object sourceCollection) {
return Collections.unmodifiableList((List<?>) sourceCollection);
}
},
SET(Collections.unmodifiableSet(new HashSet<Void>()).getClass()) {
@Override
public Object create(Object sourceCollection) {
return Collections.unmodifiableSet((Set<?>) sourceCollection);
}
},
SORTED_SET(Collections.unmodifiableSortedSet(new TreeSet<Void>()).getClass()) {
@Override
public Object create(Object sourceCollection) {
return Collections.unmodifiableSortedSet((SortedSet<?>) sourceCollection);
}
},
MAP(Collections.unmodifiableMap(new HashMap<Void, Void>()).getClass()) {
@Override
public Object create(Object sourceCollection) {
return Collections.unmodifiableMap((Map<?, ?>) sourceCollection);
}
},
SORTED_MAP(Collections.unmodifiableSortedMap(new TreeMap<Void, Void>()).getClass()) {
@Override
public Object create(Object sourceCollection) {
return Collections.unmodifiableSortedMap((SortedMap<?, ?>) sourceCollection);
}
};

private final Class<?> type;

UnmodifiableCollection(Class<?> type) {
this.type = type;
}

public abstract Object create(Object sourceCollection);

static UnmodifiableCollection valueOfType(Class<?> type) {
for (UnmodifiableCollection item : values()) {
if (item.type.equals(type)) {
return item;
}
}
throw new IllegalArgumentException("The type " + type + " is not supported.");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public void testCheckpointCache() throws ExecutionException {
.expireAfterWrite(3600, TimeUnit.SECONDS)
.weigher((key, value) ->
Math.toIntExact(SizeEstimator.estimate(key) + SizeEstimator.estimate(value)))
.maximumWeight(1024 * 2)
.maximumWeight(400 * 2)
.concurrencyLevel(1)
.build(new CacheLoader<>() {
@NotNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1380,7 +1380,9 @@ public void testNowWithParameter() throws AnalysisException {
ConnectContext ctx = new ConnectContext(null);
ctx.setThreadLocalInfo();
ctx.setStartTime();
LocalDateTime expected = ctx.getStartTimeInstant().atZone(TimeUtils.getTimeZone().toZoneId()).toLocalDateTime();
Instant instant = ctx.getStartTimeInstant();
LocalDateTime expected = Instant.ofEpochSecond(instant.getEpochSecond(), instant.getNano() / 1000 * 1000)
.atZone(TimeUtils.getTimeZone().toZoneId()).toLocalDateTime();
assertEquals(expected, ScalarOperatorFunctions.now(new ConstantOperator(6, Type.INT)).getDatetime());
}

Expand Down
4 changes: 2 additions & 2 deletions fe/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ under the License.
<properties>
<starrocks.home>${basedir}/../</starrocks.home>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<jprotobuf.version>2.4.23</jprotobuf.version>
<log4j.version>2.19.0</log4j.version>
<jackson.version>2.15.2</jackson.version>
Expand Down

0 comments on commit 91c1210

Please sign in to comment.