janhoy commented on code in PR #5346:
URL: https://github.com/apache/solr/pull/5346#discussion_r4782421167
##########
solr/core/src/java/org/apache/solr/cli/StatusTool.java:
##########
@@ -197,13 +220,29 @@ public void runImpl(CommandLine cli) throws Exception {
solrUrl = CLIUtils.hasConnectionOption(cli) ?
CLIUtils.normalizeSolrUrl(cli) : null;
port = cli.hasOption(PORT_OPTION) ? cli.getParsedOptionValue(PORT_OPTION)
: null;
shortFormat = cli.hasOption(SHORT_OPTION);
+ printStopPort = cli.hasOption(STOP_PORT_OPTION);
maxWaitSecs = cli.getParsedOptionValue(MAX_WAIT_SECS_OPTION, 0);
credentials = cli.getOptionValue(CommonCLIOptions.CREDENTIALS_OPTION);
runTool();
}
public int runTool() throws Exception {
+ // Answered from the process arguments alone, and deliberately before any
HTTP call: a node
+ // that no longer serves requests is exactly the one that still has to be
stopped.
+ if (printStopPort) {
+ Optional<SolrProcess> proc =
+ port == null ? Optional.empty() : processMgr.processForPort(port);
+ if (proc.isEmpty()) {
+ CLIO.err("Could not find a running Solr on port " + port);
+ runtime.exit(1);
+ return 1;
+ }
+ CLIO.out(String.valueOf(proc.get().stopPort()));
Review Comment:
🤖 Done: anything outside 1–65535 is reported as unknown.
##########
solr/core/src/java/org/apache/solr/cli/StatusTool.java:
##########
@@ -197,13 +220,29 @@ public void runImpl(CommandLine cli) throws Exception {
solrUrl = CLIUtils.hasConnectionOption(cli) ?
CLIUtils.normalizeSolrUrl(cli) : null;
port = cli.hasOption(PORT_OPTION) ? cli.getParsedOptionValue(PORT_OPTION)
: null;
shortFormat = cli.hasOption(SHORT_OPTION);
+ printStopPort = cli.hasOption(STOP_PORT_OPTION);
maxWaitSecs = cli.getParsedOptionValue(MAX_WAIT_SECS_OPTION, 0);
credentials = cli.getOptionValue(CommonCLIOptions.CREDENTIALS_OPTION);
runTool();
}
public int runTool() throws Exception {
+ // Answered from the process arguments alone, and deliberately before any
HTTP call: a node
+ // that no longer serves requests is exactly the one that still has to be
stopped.
+ if (printStopPort) {
+ Optional<SolrProcess> proc =
+ port == null ? Optional.empty() : processMgr.processForPort(port);
Review Comment:
🤖 Leaving as is. The duplicate-port map problem predates this PR and affects
every `status` call; better fixed separately.
##########
solr/core/src/java/org/apache/solr/cli/SolrProcessManager.java:
##########
@@ -154,6 +161,24 @@ private Optional<Integer>
parsePortFromProcess(ProcessHandle ph) {
return portStr.isPresent() ? portStr.map(Integer::parseInt) :
Optional.empty();
}
+ /**
+ * Finds the Jetty stop port of a running node from its {@code -DSTOP.PORT}
argument, falling back
+ * to the port that {@code bin/solr} derives when nothing was configured.
+ */
+ private int parseStopPortFromProcess(ProcessHandle ph, int port) {
+ for (String arg : arguments(ph).reversed()) {
+ int idx = arg.indexOf(STOP_PORT_ARG);
+ if (idx >= 0) {
+ try {
+ return Integer.parseInt(arg.substring(idx + STOP_PORT_ARG.length()));
+ } catch (NumberFormatException e) {
+ log.warn("Ignoring unparseable {} of process {}", arg, ph.pid());
+ }
+ }
+ }
+ return port - DEFAULT_STOP_PORT_OFFSET;
Review Comment:
🤖 Done: returns empty, so the script applies STOP_PORT or the derived port.
##########
solr/core/src/java/org/apache/solr/cli/SolrProcessManager.java:
##########
@@ -154,6 +161,24 @@ private Optional<Integer>
parsePortFromProcess(ProcessHandle ph) {
return portStr.isPresent() ? portStr.map(Integer::parseInt) :
Optional.empty();
}
+ /**
+ * Finds the Jetty stop port of a running node from its {@code -DSTOP.PORT}
argument, falling back
+ * to the port that {@code bin/solr} derives when nothing was configured.
+ */
+ private int parseStopPortFromProcess(ProcessHandle ph, int port) {
+ for (String arg : arguments(ph).reversed()) {
+ int idx = arg.indexOf(STOP_PORT_ARG);
Review Comment:
🤖 Done: exact `-DSTOP.PORT=` prefix, reverse scan kept.
##########
solr/bin/solr.cmd:
##########
@@ -1292,6 +1289,32 @@ set eout=%eout:"=%
echo !eout!
GOTO :eof
+:resolve_stop_port
+ REM Each node knows its own stop port, so read it back from the running
process.
+ REM The tool's output is captured through a temp file and not with a 'for
/f' over its command
+ REM line: the quotes around -classpath are lost when the command is wrapped
in backquotes, and
+ REM the class is then not found, which would leave every stop falling back
to the derived port.
+ set RESOLVED_STOP_PORT=
+ set "STOP_PORT_ERR=nul"
+ IF "%verbose%"=="1" set "STOP_PORT_ERR=con"
+ set "STOP_PORT_OUT=%TEMP%\solr-stopport-%RANDOM%.txt"
+ "%JAVA%" %SOLR_TOOL_OPTS% -Dsolr.install.dir="%SOLR_TIP%" ^
+
-Dlog4j.configurationFile="file:///%DEFAULT_SERVER_DIR%\resources\log4j2-console.xml"
^
+ -classpath
"%SOLR_TIP%\lib\*;%DEFAULT_SERVER_DIR%\solr-webapp\webapp\WEB-INF\lib\*;%DEFAULT_SERVER_DIR%\lib\ext\*"
^
+ org.apache.solr.cli.SolrCLI status -p %1 --stop-port >"%STOP_PORT_OUT%"
2>%STOP_PORT_ERR%
Review Comment:
🤖 Leaving as is. No other tool call in solr.cmd has a timeout, and the same
WMI query already runs for `status`.
--
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]