Skip to content

SOLR-18094 Support running embedded-zk in "ensemble" mode with new node role - #2391

Open
gerlowskija wants to merge 87 commits into
apache:mainfrom
gerlowskija:spike-zk-quorum
Open

gerlowskija wants to merge 87 commits into
apache:mainfrom
gerlowskija:spike-zk-quorum

Conversation

@gerlowskija

@gerlowskija gerlowskija commented Apr 5, 2024 •

Copy link
Copy Markdown
Contributor

Description

Here is a video walkthrough of the ZooKeeper/Solr Dynamic Quorum Ensemble: https://share.descript.com/view/Q8dm0VfxNPG

Before this PR, Solr could only run embedded ZooKeeper in "standalone" mode, which can't take part in a larger ensemble and can't survive the loss of its node. There are use cases for an embedded multi-node quorum: development and testing, and adventurous users who want a small fault-tolerant SolrCloud cluster without also deploying ZooKeeper.

See SIP-14 and SOLR-15636 for context.

⚠️ Experimental / Alpha feature. This is intentionally rough and should not be used in production. The API and configuration may change without notice.

Solution

Embedded ZK quorum via a new node role

A node with the new zookeeper_quorum:on node role starts a ZooKeeperServerEmbedded instance in-process that takes part in a real ZooKeeper ensemble. Solr works out its own myid by matching its host and port against the ZK connection string. Apart from sharing a process with Solr, the ensemble behaves like one made of separate ZK servers. SolrZkServer is removed; the standalone embedded ZK now uses ZooKeeperServerEmbedded too.

Ports are derived from the Solr port, and each offset can be overridden with a system property:

Port Default Property
ZK client solr_port + 1000 solr.zookeeper.server.client.port.offset
ZK quorum peer solr_port + 1010 solr.zookeeper.server.quorum.port.offset
ZK leader election solr_port + 1020 solr.zookeeper.server.election.port.offset

Two ways to form an ensemble

Cold bootstrap: every node lists all members, and nodes wait (logging still waiting for a quorum) until a majority is up.

ZK_HOST="localhost:21000,localhost:31000,localhost:41000"
ROLES="data:on,overseer:allowed,zookeeper_quorum:on"
bin/solr start -p 20000 -z "$ZK_HOST" -Dsolr.node.roles="$ROLES" -Dsolr.zookeeper.server.datadir=zoo_home_1
bin/solr start -p 30000 -z "$ZK_HOST" -Dsolr.node.roles="$ROLES" -Dsolr.zookeeper.server.datadir=zoo_home_2
bin/solr start -p 40000 -z "$ZK_HOST" -Dsolr.node.roles="$ROLES" -Dsolr.zookeeper.server.datadir=zoo_home_3

Start with one node and grow by live joins: a single node comes up as a complete one-member ensemble (standaloneEnabled=false, so it can be reconfigured later). Later nodes list the existing members plus themselves, sync with the leader, and are added through ZooKeeper dynamic reconfiguration, with no restart of existing nodes. Restarting an existing member reclaims its seat rather than joining again.

bin/solr start -p 20000 -z "localhost:21000" -Dsolr.node.roles="$ROLES" ...
bin/solr start -p 30000 -z "localhost:21000,localhost:31000" -Dsolr.node.roles="$ROLES" ...
bin/solr start -p 40000 -z "localhost:21000,localhost:31000,localhost:41000" -Dsolr.node.roles="$ROLES" ...

To allow joins, Solr enables reconfigEnabled=true and zookeeper.skipACL=yes for the embedded server (see Known Limitations).

Managing membership

  • New v2 API: GET /api/cluster/zookeeper/members lists the members and the config version (zk-read permission). DELETE /api/cluster/zookeeper/members/{id}?version=... retires a member (new zk-edit permission), and a stale version returns 409.
  • Solr's ZooKeeper client follows ensemble changes at runtime: Curator's EnsembleTracker is on by default, and Solr allows server-list updates. A node's -z only matters at startup. The ZK Status page now says so when -z differs from the dynamic ensemble config, instead of claiming that dynamic reconfiguration is unsupported.

CLI

  • bin/solr -e cloud now forms its own 3-node embedded quorum by default, and asks separately how many extra plain Solr nodes to add. An explicit -z still uses an external ensemble.
  • New bin/solr assert --cloud-nodes N [--solr-url ...] waits for at least N live SolrCloud nodes.

Docs

  • zookeeper-ensemble.adoc: a new "Embedded ZooKeeper Ensemble (Experimental)" section, covering cold bootstrap, single-node growth, port configuration, retiring members and Known Limitations.
  • node-roles.adoc, solr-assert.adoc, solr-properties.adoc, rule-based-authorization-plugin.adoc (zk-edit), and a note in major-changes-in-solr-10.adoc.

Known limitations (experimental)

  • Membership changes are not authenticated. zookeeper.skipACL=yes applies to the whole JVM, and anyone who can reach a ZK client port can add or remove voting members. Keep the ZK ports on a trusted network. When SOLR-18659: Secure embedded ZooKeeper automatically when SSL is on #5329 lands we will actually be able to use teh SSL stuff to authenticate, so we won't need skipACL. And I can live with this limitation if you don't care about security (i.e no SSL)
  • A node's -z is not updated when the ensemble grows. Running nodes follow the new members, but on restart a node can only connect through the hosts it lists.
  • Every join changes the majority size: two members tolerate no failures, and an accidental join adds a voter.
  • ZooKeeper's data and conf directories (zoo.cfg.dynamic.*) must persist. A node whose ZK data is wiped comes back as a stranger.
  • The JVM's default locale must format numbers with ASCII digits. ZooKeeper writes its dynamic config using the default locale. ZOOKEEPER-5139: Use Locale.ROOT when formatting QuorumServer addresses zookeeper#2514 is a fix for the future.
  • Hostnames in -z must exactly match solr.host.
  • Quorum loss and recovery is not yet reliable. testQuorumLossAndRecovery is still @AwaitsFix: in about 4% of runs the Overseer stops applying state updates after quorum loss (see the comments below).
  • Runs best with the security manager disabled.

Tests

  • TestEmbeddedZkQuorum:
    • basic quorum
    • cold bootstrap from one node then growing 1→2→3 by live joins
    • indexing
    • resilience to a node failure
    • ZK leader failover
    • repeated cold bootstrap converging
    • a join that fails cleanly when the leader dies mid-reconfigure
    • quorum loss and recovery (@AwaitsFix, with a race fixed and a thread dump on failure)
  • ZooKeeperEnsembleAPITest / ZooKeeperEnsembleStandaloneTest: the members API.
  • AssertToolTest, test_assert.bats, TestSolrCLIRunExample: assert --cloud-nodes and the new -e cloud.
  • ExternalZkEnsembleTest (new, Testcontainers): 3 ZooKeeper containers and 2 Solr containers built from the tree. It covers collection creation, indexing and querying across nodes, and stopping the ZK leader. Run it with ./gradlew -p solr/docker dockerExternalZkEnsembleTest.
  • Test framework:
    • MiniSolrCloudCluster.Builder.withEmbeddedZkQuorum(n), which now accepts 1 node.
    • Port reservation that covers the quorum and election ports.
    • A narrow SolrIgnoredThreadsFilter entry for a ZooKeeper LearnerHandler sender-thread leak.

Checklist

Please review the following and check all that apply:

  • I have reviewed the guidelines for How to Contribute and my code conforms to the standards described there to the best of my ability.
  • I have created a Jira issue and added the issue ID to my pull request title.
  • I have given Solr maintainers access to contribute to my PR branch. (optional but recommended)
  • I have developed this patch against the main branch.
  • I have run ./gradlew check.
  • I have added tests for my changes.
  • I have added documentation for the Reference Guide

…found" with an out-dated ClusterState (apache#2363)"

This reverts commit 5c399dd.
This commit augments our embedded-ZK code to support running embedded-ZK
in "quorum" or ensemble mode.  Multiple Solr nodes can now all have
their embedded-ZK's join a multi-node quorum upon startup.  Other than
Solr and ZK sharing a process, the embedded- ZK ensemble behaves
identically to one formed of independent processes: nodes can join or
leave the cluster, etc.

Embedded-ensemble-ZK is enabled any time the `zkQuorumRun` system
property is present, along with an explicitly specified ZK host string.
On startup, Solr will identify which host in the zk-conn-string it
should be (based on admittedly hacky heuristics), and then spins up a
'ZooKeeperServerEmbedded' instance in-process to join the ensemble. e.g.

```
export LH="localhost"
bin/solr start -p 8983 -z $LH:9983,$LH:9984,$LH:9985 -DzkQuorumRun
bin/solr start -p 8984 -z $LH:9983,$LH:9984,$LH:9985 -DzkQuorumRun
bin/solr start -p 8985 -z $LH:9983,$LH:9984,$LH:9985 -DzkQuorumRun
```

Some notes:
  - this doesn't (yet) work with ZK's dynamic-ensemble feature, so all
    ZK nodes must be specified in a static ZK conn string provided at
    startup
  - this appears to run best when the security-manager is disabled.
@gerlowskija

Copy link
Copy Markdown
Contributor Author

FYI: https://cwiki.apache.org/confluence/display/SOLR/SIP-14+Embedded+Zookeeper for context on others' interest in moving this direction.

@janhoy

janhoy commented Apr 29, 2024

Copy link
Copy Markdown
Contributor

Great work. I think we should rip out the existing embedded ZK, which is a hack.

Do you want to proceed in a PR or perhaps in a central feature branch?

@gerlowskija

Copy link
Copy Markdown
Contributor Author

Spent a few minutes pulling in the latest 'main'. Hoping to give it a bit more cleanup in the next few days if I can, but I've been hoping that for more than a year at this point (😬 ), so if anyone else is interested please feel free to move this forward!

@epugh

epugh commented Oct 14, 2025

Copy link
Copy Markdown
Contributor

@gerlowskija I took a stab at getting in the use of the solr roles to determine if we hsould run embedded zk quorum mode, and it worked! Here is my start script, where each runs with -f so you need three terminals. Omit the -f and you don't need the seperate terminals.

mkdir -p ./three_nodes/node1/solr
mkdir -p ./three_nodes/node2/solr
mkdir -p ./three_nodes/node3/solr

SOLR_SECURITY_MANAGER_ENABLED=false bin/solr start -f -p 8983 --solr-home "./three_nodes/node1/solr" -z localhost:9983,localhost:9984,localhost:9985 -Dsolr.node.roles=data:on,overseer:allowed,zookeeper_quorum:on
SOLR_SECURITY_MANAGER_ENABLED=false bin/solr start -f -p 8984 --solr-home "./three_nodes/node2/solr" -z localhost:9983,localhost:9984,localhost:9985 -Dsolr.node.roles=data:on,overseer:allowed,zookeeper_quorum:on
SOLR_SECURITY_MANAGER_ENABLED=false bin/solr start -f -p 8985 --solr-home "./three_nodes/node3/solr" -z localhost:9983,localhost:9984,localhost:9985 -Dsolr.node.roles=data:on,overseer:allowed,zookeeper_quorum:on

# Conflicts:
#	solr/core/src/java/org/apache/solr/core/ZkContainer.java
#	solr/packaging/build.gradle
@janhoy

janhoy commented Oct 15, 2025

Copy link
Copy Markdown
Contributor
  • Merged in main branch
  • Properly clean up the ZK server resource in close()

@epugh

epugh commented Oct 16, 2025

Copy link
Copy Markdown
Contributor

FYI, the .bats test worked a few times for me and then quit working ;-(

Uses a base class SolrCloudWithEmbeddedZkQuorumTestCase
New MiniSolrCloudCluster constructor that spins up a quorum cluster
" bin/solr assert --not-root"
" bin/solr assert --not-root",
"",
" # Assert a 3-node SolrCloud/ZooKeeper ensemble is fully up before continuing",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

i don't think we should need the -z here.. We should go to any Solr node and still get the same results...

Comment thread solr/packaging/test/test_assert.bats Resolved
epugh and others added 3 commits November 23, 2026 17:50
Test and harden the single-node bootstrap path added in d3b6c74:

- MiniSolrCloudCluster: allow a 1-node embedded-ZK quorum. Reserve the
  ports ZkContainer actually binds (+1000/+1010/+1020, not +1000/+1/+2)
  and draw candidates from 10000-30000 instead of the OS ephemeral
  allocator, which on macOS climbs until no port leaves room for the ZK
  offsets.
- TestEmbeddedZkQuorum: replace the 2->3 test with 1->2->3, skipped when
  the default locale formats integers with non-ASCII digits (ZooKeeper
  writes its dynamic config in the default locale and can't parse it back).
- SolrIgnoredThreadsFilter: ignore ZooKeeper LearnerHandler sender threads
  left parked in sendPackets. When a leader shuts down, the handler's own
  shutdown() clears the queued proposal of death, then fails to re-queue
  it because the thread is interrupted.
- ZookeeperStatusHandler: the connection-string mismatch warning no longer
  claims Solr doesn't support dynamic reconfiguration.
- ZkContainer: hoist a computed log argument out of the quorum-wait log
  call (validateLogCalls), plus formatting.
- Ref guide: document the unauthenticated membership changes, quorum-size
  effects of joins, persistence of ZK data dirs, and the locale requirement
  as known limitations.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_018RwsEje8u9apx3SRzissZm
ExternalZkEnsembleTest runs two Solr containers, built from this tree,
against three ZooKeeper containers on one Docker network: it creates and
queries a collection, checks the ZK Status page, then stops the ZK leader
and checks Solr keeps indexing and querying on the surviving quorum. Run
it with './gradlew -p solr/docker dockerExternalZkEnsembleTest'; each
Docker test task now filters to its own class.

Solr runs in containers too because its ZooKeeper client (Curator's
EnsembleTracker with an updatable FixedEnsembleProvider) follows the
ensemble config, switching to the zkN:2181 addresses ZooKeeper advertises.
Confirmed with bin/solr: a node whose -z listed only one ensemble member
kept working after that member stopped. Correct the ZK Status warning and
ref guide accordingly: a node's connection string only matters at startup.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_018RwsEje8u9apx3SRzissZm
@epugh

epugh commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

I went through the ZooKeeper deployment scenarios Solr supports to see which ones we have test coverage for. Embedded single ZK, embedded quorum, external single ZK, ZK ACLs/digest credentials, session expiry and state compression are all covered. These are the gaps I found:

Scenario Why it matters Current coverage
External ZK ensemble (3+ separate servers) The recommended production setup Now covered by ExternalZkEnsembleTest (e4e2ae7): 3 ZK containers + 2 Solr containers built from the tree, including stopping the ZK leader. Run with ./gradlew -p solr/docker dockerExternalZkEnsembleTest.
Chroot (-z zk1,zk2,zk3/solr) How several Solr clusters share one ensemble; very common in production Unit tests for parsing and the zk CLI only, no cluster-level test
SASL / Kerberos to ZK Enterprise ZK authentication Documented in zookeeper-access-control.adoc, no tests
TLS to ZK (secureClientPort, zookeeper.client.secure) Encrypting Solr↔ZK traffic, increasingly required Neither documented nor tested. The ZK client supports it via JVM properties, but nothing confirms Solr works with it
Quorum loss and recovery Majority of ZK servers down, then back Embedded quorum: testQuorumLossAndRecovery exists but is skipped and listed as "not yet fully reliable". External ensemble: not tested
Replacing ZK servers in a running external ensemble Swapping ZK hosts via dynamic reconfiguration, e.g. a hardware refresh Not tested
Single DNS name for the ensemble (e.g. a Kubernetes headless Service) Common on Kubernetes Not tested
ZooKeeper observers Non-voting read members, e.g. across datacenters Neither documented nor tested
Rolling ZooKeeper upgrade Upgrading ZK under a running Solr cluster Not tested (RollingUpgradeTest upgrades Solr, not ZK)

One finding that affects the last few rows and this PR's docs: Solr's ZooKeeper client does follow ensemble changes at runtime. Curator's EnsembleTracker is on by default, and Solr builds Curator with new FixedEnsembleProvider(zkHost), which allows server-list updates. I confirmed it with bin/solr: a node whose -z listed only one ensemble member kept working after that member stopped. So a node's connection string only matters at startup. The ZK Status warning ("Solr does not currently support dynamic reconfiguration and will only be able to connect to the zk hosts in your connection string") and the matching Known Limitations entry in zookeeper-ensemble.adoc overstated the limitation; e4e2ae7 corrects both.

If I were to add coverage next, I'd start with chroot (a small extension of the external-ensemble test), then TLS, which is the biggest blind spot.

Update: I pushed two commits to this branch:

  • 5bc5d3b: tests and hardening for starting the embedded quorum from one node and growing it 1→2→3 by live joins (plus a test-framework port-reservation fix, a workaround for a ZooKeeper LearnerHandler thread leak, and new Known Limitations entries).
  • e4e2ae7: the external-ensemble Docker test above, and the ZK Status / ref guide corrections.
  • 756bc9f: a race fix and failure diagnostics for testQuorumLossAndRecovery, which is still skipped. See the comment below for the remaining Overseer bug.

@github-actions github-actions Bot added docker Docker image tool:build labels Nov 24, 2026
…n its real failure

The test indexed as soon as quorum returned, before the surviving node's
ZK client had reconnected; that node's session outlived the outage, so ZK
still showed it live with an active replica while it rejected updates
("Cannot talk to ZooKeeper"). Wait for every node's ZK client to connect,
then for all replicas to be active rather than exactly one, which raced
against recovery succeeding.

What remains is a real failure, so the test stays @AwaitsFix: when the
shard leader is on a stopped node, the Overseer's state-update thread can
stop applying updates after a ConnectionLoss, without logging why, and the
shard never elects a leader. Log a thread dump when recovery times out to
show where that thread is stuck.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_018RwsEje8u9apx3SRzissZm
@epugh

epugh commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

I pushed 756bc9f, which looks at testQuorumLossAndRecovery (still @AwaitsFix, SOLR-18094):

  • Fixed a race in the test. After the restarts, it wrote to the survivor before that node's ZooKeeper client had reconnected, and the update was rejected. It now waits for every running node's ZK client to be connected, then for all replicas to be active.
  • Added diagnostics. If that wait times out, the test logs the stack of every thread running org.apache.solr.cloud code, one log call per thread so the ~10KB log-message cap doesn't truncate it.

With the race gone, the test still fails in about 2 of 47 runs because of what looks like a real bug, which probably deserves its own JIRA issue:

After quorum loss, the Overseer's state-update thread logs Exception in Overseer main queue loop and then goes silent. It keeps its Overseer seat and stays alive (it logs "Overseer Loop exiting" only at shutdown), but it stops applying state updates. Every leader registration then times out with "Cluster state does not reflect leader change after issuing command". The restarted replicas have no update history and can't take over, so the shard stays leaderless.

The two failures had different triggers:

  1. ConnectionLoss in ZkStateWriter.writePendingUpdates, during the outage.
  2. NoNodeException in ZkDistributedQueue.remove, right after quorum came back. Most likely a queue-cleanup multi timed out during the outage but had actually been applied, so the retry found the entries already gone.

I haven't yet captured where the thread is stuck. Neither failure happened with the fixed dump in place (the last 32 runs passed). The next failure in a beast or nightly run should show it: ./gradlew :solr:core:test --tests TestEmbeddedZkQuorum.testQuorumLossAndRecovery -Ptests.awaitsfix=true -Ptests.iters=20.

epugh and others added 5 commits November 24, 2026 07:22
The note still described the old +1/+2 quorum and election ports. With
the +1000/+1010/+1020 offsets, Solr ports must be more than 1020 apart.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_018RwsEje8u9apx3SRzissZm
- Share the Docker tests' helpers, constants and Testcontainers thread
  filter in DockerHelpers, and their Gradle task setup in one closure.
- Drop a redundant ZK leader wait from ExternalZkEnsembleTest.
- Name ZkContainer's default port offsets and use them in
  MiniSolrCloudCluster instead of repeating the numbers.
- Move the ASCII-digit locale guard into withEmbeddedZkQuorum(), so it
  covers every embedded-quorum test, not just one.
- Smaller tidy-ups in TestEmbeddedZkQuorum and SolrIgnoredThreadsFilter.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_018RwsEje8u9apx3SRzissZm
bin/solr start -e cloud now starts node 1 as a one-member ensemble and
adds the other members one at a time, instead of starting them all
concurrently. That removes the thread pool, the sibling rollback and
the per-node DefaultExecutor workaround, and shows the growth flow the
ref guide describes.

Also fix ExampleTest and test_example.bats, which expected node 2 on
SOLR_PORT+1; ensemble nodes are spaced 100 ports apart. They now assert
three live nodes with --cloud-nodes 3.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_018RwsEje8u9apx3SRzissZm
test_assert.bats gained them alongside --cloud-nodes, but its CATS port
didn't. The second node shares the first's Solr home, as in SslTest, so
the test needs no shell-specific file commands.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_018RwsEje8u9apx3SRzissZm
@epugh
epugh marked this pull request as ready for review November 24, 2026 13:49
@github-actions

Copy link
Copy Markdown

Automated PR readiness judgements (LLM-generated; may be wrong; not updated on later pushes).

  • ✅ Jira issue in title: already present
  • ✅ Changelog: type: added
  • ✅ Reference Guide update: included
  • ⚠️ Upgrade notes — probably not needed (confidence: medium): While `SolrZkServer` is removed, it is an internal class replaced by `ZooKeeperServerEmbedded` for the same standalone functionality, and the new ensemble mode is opt-in via a new role, so existing configurations and behaviors remain compatible.​
  • ✅ Tests: included

Use dot-separated names with an explicit unit, per the property naming
convention:
- solr.zookeeper.server.join.probeTimeoutMs -> join.probe.timeout.ms
- solr.zookeeper.server.join.connectTimeoutMs -> join.timeout.ms (it
  bounds the whole join, not just connecting)
- solr.zookeeper.server.quorum.waitLogIntervalMs -> quorum.wait.log.interval.ms

Add all three to the Solr Properties Reference, and note there that the
client port offset also applies to the standalone embedded ZooKeeper.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_018RwsEje8u9apx3SRzissZm
@epugh

epugh commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

With two nodes up and two down I get this in the UI, and it could work better:

image. It's not exactly clear why things are unhappy...!

Here is the setup in the TUI:

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants