Ian Springer created SOLR-18686:
-----------------------------------

             Summary: Overseer DOWNNODE processing reads every collection's 
state.json, stalling the state update queue on clusters with many collections
                 Key: SOLR-18686
                 URL: https://issues.apache.org/jira/browse/SOLR-18686
             Project: Solr
          Issue Type: Improvement
          Components: SolrCloud
    Affects Versions: 10.1, 10.0, 9.7
            Reporter: Ian Springer


h3. Problem

On clusters with thousands of collections, the Overseer's handling of 
{{downnode}} messages is slow enough to stall the whole cluster during rolling 
restarts and mass node turnover.

Every node sends a {{downnode}} message when it starts, stops cleanly or 
reconnects ({{ZkController.publishNodeAsDown}}, which is also now called from 
{{preClose()}}). The Overseer handles each one in {{NodeMutator.downNode}}:

{code:java}
return clusterState
    .collectionStream()
    .filter(entry -> !entry.isPerReplicaState())
    .map(docCollection -> computeCollectionUpdate(nodeName, docCollection, 
zkClient))
    ...
{code}

{{collectionStream()}} resolves every {{CollectionRef}}. Each lazily loaded 
collection costs a ZooKeeper read of its {{state.json}}, and a lazy 
collection's cached copy expires after {{solr.OverseerStateUpdateDelay}} (2 s 
by default). So under a steady stream of {{downnode}} messages, almost every 
message reads every collection in the cluster again. The reads are serial and 
run on the single thread that applies every cluster state change. Nothing else 
in the state update queue moves while they run: leader elections, replica state 
changes, and the state updates that Collection API commands wait on.

SOLR-10277 stopped {{downnode}} from *writing* collections the node has no 
replicas in, but it still *reads* every one of them. The cost is O(collections) 
per message, and a rolling restart or mass shutdown sends O(nodes) messages, so 
a cluster-wide event costs O(nodes x collections) serial ZooKeeper reads.

h3. Impact in production

These numbers are from our 9.7 clusters, which run 1,250 to 5,200 collections:

* *Per message:* about 0.5 to 4 s per {{downnode}}, depending on collection 
count. On the cluster with about 1,250 collections, a mass shutdown drained the 
state update queue at about 2 messages/s, and thread dumps showed the state 
updater thread in {{NodeMutator.downNode}}.
* *Queue backlog:* one teardown of about 2,600 nodes backed the Overseer queues 
up to over 12,000 entries.
* *Collection API timeouts:* a scheduled load that turns over about 2,900 nodes 
sends about 2,900 {{downnode}} messages. {{CREATE}} and {{MODIFYCOLLECTION}} 
calls queued behind them hit the 30 s Collection API timeout. This happened on 
every weekly run we looked at.

We replayed one of these loads' real message sequence (5,184 collections, about 
3,000 {{downnode}} messages mixed with the load's {{CREATE}}, {{ADDREPLICA}}, 
{{STATE}} and {{DELETECORE}} messages) against a stock 9.7 Overseer. The median 
{{downnode}} took 606 ms and about 5,160 ZooKeeper reads. A {{CREATE}} queued 
behind them became visible only after 1,549 s (about 26 minutes).

The cost depends on how many collections the Overseer has to read from 
ZooKeeper. On a long-lived Overseer handling occasional {{downnode}} messages, 
we measured about 15 ms each. It is worst during exactly the events that send 
many of them: rolling restarts, mass shutdowns and large loads, which often 
also move Overseer leadership.

h3. Proposal

The sending node already knows the answer. {{publishNodeAsDown}} walks its own 
cluster state to build {{replicasPerCollectionOnNode}} and uses it for 
per-replica-state collections, but sends the Overseer only the node name.

* {{publishNodeAsDown}} adds those collection names to the {{downnode}} message 
as a {{collections}} list.
* {{NodeMutator.downNode}} reads only the listed collections when the message 
has the list. A listed collection that no longer exists is skipped. A message 
without the list (from an older node) falls back to the full scan.
* An older Overseer ignores the extra property, so mixed versions work in 
either direction and there is no need for a full cluster restart.

This takes the cost of a {{downnode}} from O(collections in the cluster) to 
O(collections on the node).

Distributed cluster state updates 
({{DistributedClusterStateUpdater.executeNodeDownStateUpdate}}) are out of 
scope here.

h3. Benchmark

5,184 collections (2 shards x 2 replicas, about 10 collections per node across 
2,000 nodes) in an embedded ZooKeeper. 1,450 nodes each send two {{downnode}} 
messages, 2,900 in all, and all of them are queued before the Overseer starts. 
The time runs from Overseer start to an empty queue, on a laptop with JDK 21:

||Mode||Total||Per downnode||
|Current behavior|727.8 s|251 ms|
|Listed collections only|6.7 s|2.3 ms|

The final {{state.json}} replica states are identical in both modes (15,236 
DOWN, 5,500 ACTIVE). A local ZooKeeper is much faster than a production 
ensemble, so the gap in a real cluster is larger.

h3. What it can miss

A replica added to the node, in a collection the node had no replica in, after 
the node built its list and before the Overseer processes the message. That 
replica keeps whatever state it was added with while the node is absent from 
{{live_nodes}}, which is the same thing an unclean exit leaves behind today. To 
keep that out of the default path, we put the new behavior behind a cluster 
property ({{useListedCollectionsOnlyForDownNode}}, default {{false}}, read on 
each message, so {{CLUSTERPROP}} turns it on without a restart). I'm open to 
making it the default, or dropping the switch, if people think that window 
doesn't matter.

The change is small: about 55 production lines across {{ZkController}}, 
{{NodeMutator}} and {{ZkStateReader}} (to register the cluster property), plus 
tests in {{NodeMutatorTest}}, {{OverseerTest}} and {{ZkControllerTest}}. I'll 
open a PR against main.



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to