xiangfu0 commented on code in PR #19448:
URL: https://github.com/apache/pinot/pull/19448#discussion_r4670385745


##########
pinot-tools/src/main/resources/appAssemblerScriptTemplate:
##########
@@ -112,6 +112,35 @@ fi
 # $PLUGINS_DIR is semi-colon separated list of plugin directories, default to 
'"$BASEDIR"/plugins' if not set.
 # $PLUGINS_INCLUDE is semi-colon separated plugins name, e.g. 
pinot-avro;pinot-batch-ingestion-standalone. Default is not set, which means 
load all the plugin jars.
 # If the same plugin is found in multiple directories, it will only be picked 
up from the first directory it was found. The directories in $PLUGINS_DIR are 
traversed by their order.
+#
+# A plugin ships as a thin jar plus a pinot-plugin.classpath file listing the 
shared-store jars it
+# needs, as paths relative to $BASEDIR. Selecting a subset with 
$PLUGINS_INCLUDE therefore
+# means taking each named plugin's jars *and* the store entries its index 
names - the store as a
+# whole is not per-plugin, so adding all of it would defeat the selection. The 
whole store is added
+# only when every built-in plugin is loaded, after the jars of all 
directories, so that a jar in a
+# custom plugin directory still wins over a store jar with the same classes.
+# Paths may contain spaces: find results are read NUL-delimited.
+
+# Appends one entry to $PLUGINS_CLASSPATH.
+add_to_plugins_classpath() {
+  PLUGINS_CLASSPATH=${PLUGINS_CLASSPATH:+$PLUGINS_CLASSPATH:}$1
+}
+
+# Appends the shared-store jars that the pinot-plugin.classpath index $1 
names, once each.
+add_plugin_index() {
+  local PLUGIN_DEP
+  # The index is a classpath fragment: entries separated by ':' and/or 
newlines. build-classpath
+  # writes no final newline, so the last entry is read when read fails but the 
variable is set.
+  while IFS= read -r PLUGIN_DEP || [ -n "$PLUGIN_DEP" ] ; do
+    if [ -n "$PLUGIN_DEP" ] && [ -f "$BASEDIR/$PLUGIN_DEP" ] ; then
+      case ":$PLUGINS_CLASSPATH:" in
+        *":$BASEDIR/$PLUGIN_DEP:"*) ;;
+        *) add_to_plugins_classpath "$BASEDIR/$PLUGIN_DEP" ;;
+      esac
+    fi
+  done < <(tr ':' '\n' < "$1")

Review Comment:
   The process substitutions stop the launcher from running under `sh`. On 
master `sh bin/pinot-admin.sh ...` works with dash and with bash as `sh`. At 
this head every generated script fails before it does anything, in the default 
distribution too, since the template is shared:
   
   ```
   $ sh bin/pinot-admin.sh
   bin/pinot-admin.sh: 141: Syntax error: redirection unexpected              
(dash)
   bin/pinot-admin.sh: line 141: syntax error near unexpected token `<'      
(bash as sh)
   ```
   
   The shebang is bash, so this only hits people who start the scripts through 
`sh`, but that works today. Splitting the `find` output on newlines handles 
spaces without bash-only syntax, for example with `IFS` set to a newline around 
a plain `for`, or `while read` over a here-document. NUL-delimited reading 
needs `read -d`, which is bash-only too.



##########
pinot-distribution/pinot-assembly-thin.xml:
##########
@@ -0,0 +1,526 @@
+<!--
+
+    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.
+
+-->
+<assembly
+    
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2";
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+    
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2
 http://maven.apache.org/xsd/assembly-1.1.2.xsd";>
+  <id>bin</id>
+  <formats>
+    <format>tar.gz</format>
+    <format>dir</format>

Review Comment:
   The clean in `pinot-plugins` fixes the tarball, but this `dir` output still 
accumulates. The assembly writes into the directory of the previous build, so 
after a dependency upgrade and a rebuild without `clean`, `build/plugin-libs/` 
has both versions and the default launcher puts both on the class path. I 
checked the mechanism with maven-assembly-plugin 3.8.0 and these two formats: 
on the second build the directory had `dep-1.0.jar dep-2.0.jar` and the tar.gz 
only `dep-2.0.jar`.
   
   `ThinDistributionCheck` would flag it, but it only runs in CI after `clean 
install`. A `maven-clean-plugin` execution in the thin profile of 
`pinot-distribution` that empties `plugins/` and `plugin-libs/` of the 
assembled directory at `prepare-package` would close it.



##########
pinot-tools/src/main/resources/appAssemblerScriptTemplate:
##########
@@ -112,6 +112,35 @@ fi
 # $PLUGINS_DIR is semi-colon separated list of plugin directories, default to 
'"$BASEDIR"/plugins' if not set.
 # $PLUGINS_INCLUDE is semi-colon separated plugins name, e.g. 
pinot-avro;pinot-batch-ingestion-standalone. Default is not set, which means 
load all the plugin jars.
 # If the same plugin is found in multiple directories, it will only be picked 
up from the first directory it was found. The directories in $PLUGINS_DIR are 
traversed by their order.
+#
+# A plugin ships as a thin jar plus a pinot-plugin.classpath file listing the 
shared-store jars it
+# needs, as paths relative to $BASEDIR. Selecting a subset with 
$PLUGINS_INCLUDE therefore
+# means taking each named plugin's jars *and* the store entries its index 
names - the store as a
+# whole is not per-plugin, so adding all of it would defeat the selection. The 
whole store is added
+# only when every built-in plugin is loaded, after the jars of all 
directories, so that a jar in a
+# custom plugin directory still wins over a store jar with the same classes.
+# Paths may contain spaces: find results are read NUL-delimited.
+
+# Appends one entry to $PLUGINS_CLASSPATH.
+add_to_plugins_classpath() {
+  PLUGINS_CLASSPATH=${PLUGINS_CLASSPATH:+$PLUGINS_CLASSPATH:}$1
+}
+
+# Appends the shared-store jars that the pinot-plugin.classpath index $1 
names, once each.
+add_plugin_index() {
+  local PLUGIN_DEP
+  # The index is a classpath fragment: entries separated by ':' and/or 
newlines. build-classpath
+  # writes no final newline, so the last entry is read when read fails but the 
variable is set.
+  while IFS= read -r PLUGIN_DEP || [ -n "$PLUGIN_DEP" ] ; do
+    if [ -n "$PLUGIN_DEP" ] && [ -f "$BASEDIR/$PLUGIN_DEP" ] ; then

Review Comment:
   The launcher and `PluginManager` now read the same index with different 
rules. `indexedJars` takes the nearest parent directory that has the jar and 
logs when there is none. This looks only under `$BASEDIR` and skips a missing 
jar without a word. So for a thin plugin in a custom `PLUGINS_DIR` that has its 
own `plugin-libs/` next to it, the two disagree:
   
   ```
   custom/plugins/acme/pinot-plugin.classpath: 
plugin-libs/own.jar:plugin-libs/both.jar:plugin-libs/shared.jar
   custom/plugin-libs/: own.jar both.jar        <installation>/plugin-libs/: 
both.jar shared.jar
   
   launcher, PLUGINS_DIR=custom/plugins:  acme.jar, then both.jar and 
shared.jar from the installation.
                                          own.jar is dropped, nothing on stderr.
   PluginManager.indexedJars:             own.jar and both.jar from custom/. 
shared.jar is logged as missing.
   ```
   
   Could the launcher use the same order (the store next to the plugins 
directory, then `$BASEDIR`) and print a warning for an entry it can't find? If 
a store next to a custom plugins directory isn't meant to be supported, a 
warning plus a line in the description would be enough.



-- 
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]

Reply via email to