janhoy commented on code in PR #5333:
URL: https://github.com/apache/solr/pull/5333#discussion_r4578952930
##########
solr/bin/solr:
##########
@@ -962,16 +962,27 @@ fi
if [[ "$SCRIPT_CMD" == "stop" ]]; then
if $stop_all; then
none_stopped=true
- # Read from a process substitution, not a pipeline, so none_stopped
survives the loop
- while read -r PIDF; do
+ other_pidfiles=()
+ zookeeper_pidfiles=()
+ while IFS= read -r PIDF; do
+ NEXT_PID=$(cat "$PIDF")
+ if ps -ww -o args= -p "$NEXT_PID" | grep -q --
'-Dsolr.zookeeper.server.enabled=true'; then
Review Comment:
🤖 This runs a second `ps` per node: `solr_port_listen` (line 489) already
does `ps -fww -p "$PID"` over the same command line, so capturing it once and
deriving both the port and the ZooKeeper flag would halve the spawns and keep
one `ps` convention. Also, `-ww -o args=` is a third `ps` form in this script;
`-o args` is POSIX but `-ww` is BSD/Linux, is that fine for the other Unixes we
claim?
##########
solr/core/src/java/org/apache/solr/core/NodeRoles.java:
##########
@@ -57,6 +58,10 @@ public NodeRoles(String rolesString) {
roles.put(r, r.modeWhenRoleIsAbsent());
}
}
+ // Overrides any parsed zookeeper mode with reality; invalid modes are
still rejected above.
+ roles.put(
+ Role.ZOOKEEPER,
Review Comment:
🤖 A `zookeeper:on` in `solr.node.roles` is parsed and accepted, then
overwritten by reality, while `zookeeper:preferred` throws. Would rejecting
`zookeeper` in the roles string outright be clearer than accepting and ignoring
it?
##########
solr/solr-ref-guide/modules/deployment-guide/pages/node-roles.adoc:
##########
@@ -69,6 +72,18 @@ A node with this role (in mode "on") can host shards and
replicas for collection
=== `overseer` role
A node with this role can perform duties of an overseer node (unless mode is
`disallowed`). When one or more nodes have the overseer role in `preferred`
mode, the overseer leader will be elected from one of these nodes. In case no
node is designated as a preferred overseer or no such node is live, the
overseer leader will be elected from one of the nodes that have the overseer
role in `allowed` mode. If all nodes that are designated with overseer role
(allowed or preferred) are down, the cluster will be left without an overseer.
+=== `zookeeper` role
+
+The `zookeeper:on` role identifies a Solr node that hosts an embedded
ZooKeeper server.
+Solr derives this role from `solr.zookeeper.server.enabled`, preserving the
node's other roles.
+If no roles were configured, the node retains the defaults
`data:on,overseer:allowed` alongside `zookeeper:on`.
+
+On Unix/macOS only, `bin/solr stop --all` stops nodes hosting embedded
ZooKeeper last.
+This keeps embedded ZooKeeper available while the other nodes shut down.
+
+The role is `on` when embedded ZooKeeper is enabled and `off` otherwise.
+It cannot be set through `solr.node.roles`; isntead configure embedded
ZooKeeper using `solr.zookeeper.server.enabled`.
Review Comment:
🤖 Typo: "isntead" should be "instead".
##########
solr/core/src/test/org/apache/solr/core/NodeRolesTest.java:
##########
@@ -0,0 +1,75 @@
+/*
+ * 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.solr.core;
+
+import org.apache.solr.SolrTestCase;
+import org.apache.solr.common.SolrException;
+import org.junit.Before;
+import org.junit.Test;
+
+/** Tests the ZooKeeper node role alongside the existing node roles. */
+public class NodeRolesTest extends SolrTestCase {
Review Comment:
🤖 There are now two test classes named `NodeRolesTest` (this one and
`org.apache.solr.cloud.NodeRolesTest`), which confuses test reports and
`--tests` filters. `NodeRolesUnitTest` or `ZookeeperNodeRoleTest`?
##########
changelog/unreleased/SOLR-11966.yml:
##########
@@ -0,0 +1,9 @@
+title: >
+ On Unix/macOS, bin/solr stop --all stops nodes hosting embedded ZooKeeper
last.
+ Embedded ZooKeeper hosts now report the zookeeper:on node role.
+type: changed
Review Comment:
🤖 Two user-visible changes under one `changed` entry: the node role reads as
`added` and the stop ordering as `fixed`. Worth two entries.
##########
solr/solr-ref-guide/modules/deployment-guide/pages/solr-control-script-reference.adoc:
##########
@@ -168,4 +168,3 @@ You can turn off schemaless functionality for a collection
with the following co
[source,bash]
$ bin/solr config -c mycollection --action set-user-property --property
update.autoCreateFields --value false
-
Review Comment:
🤖 This file only loses its trailing newline, which looks like an accidental
editor change; worth dropping from the PR.
##########
solr/solr-ref-guide/modules/deployment-guide/pages/node-roles.adoc:
##########
@@ -69,6 +72,18 @@ A node with this role (in mode "on") can host shards and
replicas for collection
=== `overseer` role
A node with this role can perform duties of an overseer node (unless mode is
`disallowed`). When one or more nodes have the overseer role in `preferred`
mode, the overseer leader will be elected from one of these nodes. In case no
node is designated as a preferred overseer or no such node is live, the
overseer leader will be elected from one of the nodes that have the overseer
role in `allowed` mode. If all nodes that are designated with overseer role
(allowed or preferred) are down, the cluster will be left without an overseer.
+=== `zookeeper` role
+
+The `zookeeper:on` role identifies a Solr node that hosts an embedded
ZooKeeper server.
+Solr derives this role from `solr.zookeeper.server.enabled`, preserving the
node's other roles.
+If no roles were configured, the node retains the defaults
`data:on,overseer:allowed` alongside `zookeeper:on`.
+
+On Unix/macOS only, `bin/solr stop --all` stops nodes hosting embedded
ZooKeeper last.
Review Comment:
🤖 "On Unix/macOS only" goes stale as soon as `solr.cmd` catches up (see the
cherry-pick offered in the review body); a neutral wording or a pointer to the
JIRA would not need revisiting.
##########
solr/packaging/test/test_start_solr.bats:
##########
@@ -40,6 +40,48 @@ teardown() {
refute_output --partial 'forcefully killing'
}
+@test "SOLR-11966 stop ZooKeeper hosts after other SolrCloud nodes" {
+ solr start
+ solr start -p "${SOLR2_PORT}" -z "localhost:${ZK_PORT}"
+
+ run wait_for 30 1 node_has_zookeeper_role \
+
"http://localhost:${SOLR_PORT}/api/cluster/node-roles/node/localhost:${SOLR_PORT}_solr?indent=false"
on
+ assert_success
+ assert_output --partial '"data":"on"'
+ assert_output --partial '"overseer":"allowed"'
+ assert_output --partial '"zookeeper":"on"'
+
+ run wait_for 30 1 node_has_zookeeper_role \
+
"http://localhost:${SOLR2_PORT}/api/cluster/node-roles/node/localhost:${SOLR2_PORT}_solr?indent=false"
off
+ assert_success
+ assert_output --partial '"zookeeper":"off"'
+
+ run env SOLR_STOP_WAIT=30 solr stop --all
+ assert_success
+ assert_output --regexp "Sending stop command.*port ${SOLR2_PORT} .*Sending
stop command.*port ${SOLR_PORT} "
+ refute_output --partial 'forcefully killing'
+ solr assert --not-started "http://localhost:${SOLR_PORT}" --timeout 5000
+ solr assert --not-started "http://localhost:${SOLR2_PORT}" --timeout 5000
+}
+
+node_has_zookeeper_role() {
Review Comment:
🤖 `node_has_zookeeper_role` sits between two `@test` blocks; moving it up
with the other helpers keeps the tests readable.
--
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]