Jackie-Jiang commented on code in PR #19378: URL: https://github.com/apache/pinot/pull/19378#discussion_r3927846834
########## pinot-plugins/pinot-input-format/pinot-protobuf/src/test/java/org/apache/pinot/plugin/inputformat/protobuf/ProtoBufTempFileLeakTest.java: ########## @@ -0,0 +1,387 @@ +/** + * 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.pinot.plugin.inputformat.protobuf; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.net.URL; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; +import java.util.stream.Stream; +import org.apache.commons.io.FileUtils; +import org.apache.pinot.spi.data.readers.GenericRow; +import org.apache.pinot.spi.filesystem.LocalPinotFS; +import org.apache.pinot.spi.filesystem.PinotFSFactory; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import static org.apache.pinot.plugin.inputformat.protobuf.ProtoBufCodeGenMessageDecoder.PROTOBUF_JAR_FILE_PATH; +import static org.apache.pinot.plugin.inputformat.protobuf.ProtoBufCodeGenMessageDecoder.PROTO_CLASS_NAME; +import static org.apache.pinot.plugin.inputformat.protobuf.ProtoBufTestDataGenerator.createComplexTypeRecord; +import static org.apache.pinot.plugin.inputformat.protobuf.ProtoBufTestDataGenerator.getComplexTypeObject; +import static org.apache.pinot.plugin.inputformat.protobuf.ProtoBufTestDataGenerator.getFieldsInSampleRecord; +import static org.apache.pinot.plugin.inputformat.protobuf.ProtoBufTestDataGenerator.getSampleRecordMessage; +import static org.apache.pinot.plugin.inputformat.protobuf.ProtoBufTestDataGenerator.getSourceFieldsForComplexType; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertTrue; +import static org.testng.Assert.fail; + + +/// Verifies that protobuf decoder and reader operations do not leak temporary directories. Review Comment: This test can be much smaller. Existing decoder and record-reader tests already cover simple and complex functional decoding, while temp-file behavior does not depend on schema complexity. Please remove the duplicate complex cases and repeated field assertions, keeping one focused regression per distinct resource path. The fake PinotFS could also serve classpath resources directly, eliminating the staging directory, `_baseDir`, and its cleanup requirement. ########## pinot-plugins/pinot-input-format/pinot-protobuf/src/main/java/org/apache/pinot/plugin/inputformat/protobuf/ProtoBufCodeGenMessageDecoder.java: ########## @@ -49,12 +68,21 @@ public void init(Map<String, String> props, Set<String> fieldsToRead, String top "Protocol Buffer Message class name must be provided"); String protoClassName = props.getOrDefault(PROTO_CLASS_NAME, ""); String jarPath = props.getOrDefault(PROTOBUF_JAR_FILE_PATH, ""); - ClassLoader protoMessageClsLoader = loadClass(jarPath); - Descriptors.Descriptor descriptor = getDescriptorForProtoClass(protoMessageClsLoader, protoClassName); - String codeGenCode = new MessageCodeGen().codegen(descriptor, fieldsToRead); - Class<?> recordExtractor = compileClass(protoMessageClsLoader, - MessageCodeGen.EXTRACTOR_PACKAGE_NAME + "." + MessageCodeGen.EXTRACTOR_CLASS_NAME, codeGenCode); - _decodeMethod = recordExtractor.getMethod(MessageCodeGen.EXTRACTOR_METHOD_NAME, byte[].class, GenericRow.class); + File jarFile = resolveToLocalFile(jarPath); Review Comment: Would it be simpler to leave the codegen-JAR path out of this PR? The descriptor callers now have a small, complete leak-free fix, while remote codegen JARs still require an explicit classloader/segment lifecycle or a managed cache. The new `_localTmpDir` state and failure cleanup add complexity but cannot clean up successful decoders on offload. I suggest reverting the codegen changes here and addressing that lifecycle separately. -- 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. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
