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

Port defaulting should be the same for all tools #1951

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

HoustonPutman
Copy link
Contributor

If Solr processes need to be found, port scanning will always be used.

I need to make a JIRA for this, but this has been exhausting, so it can wait till later.

Basically any Solr tool accepts -p, -host and -urlScheme, and can default the Solr URL from that. If a port is not provided, it will use SOLR_PORT if that is explicitly set beforehand. Otherwise, it will scan processes for a Solr Port. If more than one process is found, it will fail.

Similarly the tools (stop -all, status) that find all running Solr instances will use port scanning instead of PIDs.

This is somewhat back-incompat, for tools that use to use port scanning instead of SOLR_PORT, but I think this is acceptable. This can also wait for 10.0 if we want to, but I don't think that's necessary.

This is a WIP and likely needs more tests, and possibly there are some tools that I forgot.

If Solr processes need to be found, port scanning will always
be used.
@janhoy
Copy link
Contributor

janhoy commented Sep 23, 2023

Wow, huge effort. Love consistency! Will this need changes in solr.cmd as well? 🫣
Will try to circle back to this and take it for a spin. It's great having the bats tests to guard against regressions here!

@epugh
Copy link
Contributor

epugh commented Sep 23, 2023

I absolutely love all this clean up! I'll be honest, all the flavours of variables have been a bit confusing ;-)... I think some accretion over time of concepts layered on concepts...

So one thing I'll ask, "Is any of this required?"... I suspect that I don't quite understand how some folks use Solr... I pretty much only ever run one Solr per VM/image with proxies in front etc, so in my world, Solr is always http, Solr is always localhost (127.0.01?), and Solr is always port 8983 when I am on that node. I had actually been hoping to move in the direction of eliminating the whole port, schema, host variables, and just using a url everywhere.... I want to encourage us to be able to use the various commands like bin/solr create from anywhere, which would imply that you pretty much only ever do a bin/solr [your_command] --solrUrl https://myserverincloud:50678 -u user:password instead of the current way of looking up local variables. This pattern may come from I generally stand up a solr as step one, and then externally, as step 2, interact with it.

Regardless, this is all amazing work!

@@ -148,7 +148,7 @@ fi
: "${SOLR_START_WAIT:=$SOLR_STOP_WAIT}" # defaulting to $SOLR_STOP_WAIT for backwards compatibility reasons

# Store whether a solr port was explicitly provided, for the "solr stop" command.
PROVIDED_SOLR_PORT="${SOLR_PORT:-}"
PROVIDED_SOLR_PORT_ENV="${SOLR_PORT:-}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is _ENV a pattern we use elsewhere in bin/solr? For these variables? If we have similar concepts, maybe we can get all of the variables following this pattern?

@@ -626,6 +626,7 @@ function jetty_port() {
# run a Solr command-line tool using the SolrCLI class;
# useful for doing cross-platform work from the command-line using Java
function run_tool() {
export SOLR_PORT="$(choose_default_solr_port)"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would (choose_default_solr_port()) be possible to signal it's a function? just a spitball...


function run_package() {
runningSolrUrl=""
function get_all_running_solr_ports() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love the breaking down these convulted functions into smaller ones, makes it easier to read and reason! Hell, maybe someday we bats test the functions?

echo ""
fi
done
# no-commit - check if the SOLR_TOOL_HOST is the localhost, otherwise don't do this
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I never quite understood what SOLR_TOOL_HOST gave us that SOLR_HOST doesn't!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assuming that you are running your tool on the same node as a Solr and therefore HAVE a SOLR_HOST.

else
exit # subshell!
fi
echo -e "Sending stop command to Solr running on port $SOLR_PORT ... waiting up to $SOLR_STOP_WAIT seconds to allow Jetty process $SOLR_PID to stop gracefully."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We talk about "Solr process" in various messages, except here, we mention Jetty... Maybe time to accept that Jetty is an implmentation detail, and change this to "Solr process" ;-)!!

# Check if a process is running with the specified PID.
# -o stat will output the STAT, where Z indicates a zombie
# stat='' removes the header (--no-headers isn't supported on all platforms)
# Note the space after '$('. It is needed to avoid confusion with special bash eval syntax
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An this is why I ❤️ bash.. ;-).

@@ -1017,7 +991,7 @@ if [[ "$SCRIPT_CMD" == "package" ]]; then
esac
done
fi
run_package "$@"
run_tool package "$@"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you! This has been on my backlog for a while to fix... I think you can delete run_package now too!

done
fi
run_tool auth "${AUTH_PARAMS[@]}" -solrUrl "$SOLR_URL_SCHEME://$SOLR_TOOL_HOST:${AUTH_PORT:-8983}/solr" -authConfDir "$SOLR_HOME" $VERBOSE
run_tool auth "${AUTH_PARAMS[@]}" -authConfDir "$SOLR_HOME" $VERBOSE
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can see where I was struggling to figure out how to eliminate the SOLR_URL_SCHEME and firends, and yet it was sneaking back in. This at least is a lot shorter!

Copy link
Contributor

@epugh epugh Sep 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I was noticing in bin/solr auth getting the warning about the solrUrl not needing /solr and this fixes it, assuming we aren't constructing a solr url internally with a trailing /solr.

@@ -56,24 +56,38 @@ public List<Option> getOptions() {
.argName("URL")
.hasArg()
.required(true)
.desc("Send a GET request to a Solr API endpoint.")
.build());
.desc("Send a GET request to a Solr API endpoint, or path to use with the default Solr URL.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice tweak to the tool, in a world where you can assume your solr!

SolrCLI.OPTION_SOLRPORT,
SolrCLI.OPTION_SOLRHOST,
SolrCLI.OPTION_URLSCHEME,
SolrCLI.OPTION_VERBOSE);
}

@Override
public void runImpl(CommandLine cli) throws Exception {
String response = null;
String getUrl = cli.getOptionValue("get");
if (getUrl != null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this check? If the get parameter is marked required in the ocnfiguration, I would assume you wouldn't get to here if it is missing!

@@ -131,7 +134,7 @@ public void runImpl(CommandLine cli) throws Exception {

protected void createCore(CommandLine cli, SolrClient solrClient) throws Exception {
String coreName = cli.getOptionValue("name");
String solrUrl = cli.getOptionValue("solrUrl", SolrCLI.getDefaultSolrUrl());
String solrUrl = cli.getOptionValue("solrUrl", SolrCLI.getDefaultSolrUrl(cli));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of curiosity, if SolrCLI.getDefaultSolrUrl(cli)) always takes a cli, should we make it be cli.getDefaultSolrUrl() instead?

@@ -310,6 +310,18 @@ private Pair<String, String> parsePackageVersion(String arg) {
public List<Option> getOptions() {
return List.of(
SolrCLI.OPTION_SOLRURL,
// Cannot use the default OPTION_SOLRPORT, because -p is already taken by PARAMS
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah... I wonder if we should make the slightly breaking chagne? This feels like we are going to get bit by this in the future? Or, do we think humans will never actually use teh -p parameter to mean a solr port, becuase it's a config file type thing... I could see just forcing --package, cause how often do you type this command? whereas -p is super common IF we think humans will use these parameters a lot. <-- did that make sense?

@@ -869,6 +857,7 @@ protected boolean isValidConfig(File configsetsDir, String config) {
}

protected Map<String, Object> getNodeStatus(String solrUrl, int maxWaitSecs) throws Exception {
solrUrl += "/solr";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bummer! But we are in an awkward place where a solrUrl can end with /solr or with /api ;-) So maybe this pattern becomes more common in varous tools... Actually, are you sure you need this? Ithought the status tool would deal with the solrURL.....

@@ -80,7 +80,7 @@ public class SolrCLI implements CLIO {
public static final Option OPTION_ZKHOST =
Option.builder("z")
.longOpt("zkHost")
.argName("HOST")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice

.hasArg()
.required(false)
.desc(
"Solr URL Scheme, which will be used, along with SOLR_TOOL_HOST and SOLR_PORT, to determine the Solr URL to connect to if a solrURL is not provided; defaults to: "
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SOLR_HOST instead of SOLR_TOOL_HOST? again, I don't quite get the difference ;-).

assert_output --partial "assuming solrUrl is http://localhost:${tmp_port}"
}

@test "create collection with port scanning" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is port scanning really a feature we want? Do people just randomly launch solr on random port, and then scan to find it? If poeple do, then great feature, and I LOVE the test... Just kind of wondering about that use case... (Look, I used the word "use case" ;-). )

@@ -29,7 +29,12 @@ teardown() {
}

@test "package detects no running solr" {
# not sure this is actually a good thing.. we may not want this..
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kind of want to keep this comment... There is an issue open to look at this. Why do we check if solr is running on this command?

@@ -43,7 +43,6 @@ teardown() {
@test "status shell script ignores passed in -solrUrl cli parameter from user" {
solr start
run solr status -solrUrl http://localhost:9999/solr
assert_output --partial "needn't include Solr's context-root"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

? no longer germaine? as in we're checking something that no longer needs checking because this is how it works?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants