Repository navigation
perf(controller,satellite): read only a definition's replicas, not every Resource - #303
Conversation
Every ResourceDefinition requeues every five seconds, and each pass read every Resource in the cluster past the cache to count the definition's replicas for the tiebreaker. On a cluster with about four hundred replicas that is a few megabytes of JSON per pass and dozens of passes a second: the controller sat at its CPU limit while idle, and a burst of new volumes waited seconds for their DRBD identities behind it. The read now asks the API server for the definition's replicas only, one field-selected list per spelling of its name, including every spelling a replica in the cache carries. A server or cache that cannot serve the selector still gets the whole-cluster read. Assisted-by: LLM Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
Every pass of every replica on a node, the periodic re-checks included, read every Resource in the cluster past the cache to find the replica's peers. On a node with a hundred replicas in a cluster of four hundred that kept the satellite at its CPU limit while idle, so the passes of new replicas ran throttled and their devices appeared tens of seconds late. The read now asks for the replica's definition only, the same way the controller does. Assisted-by: LLM Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
A benchmark of the provisioning burst linstor-csi sends: sixteen volumes behind csi-provisioner's ten workers, each placed in two autoplace calls, through the REST server, the controller and one real satellite resource reconciler per node, on nodes that already carry volumes. It reports how long each create took to have its replicas built and ready, which is when LINSTOR answers it. It takes minutes, so it runs only with BURST_BENCH set. Assisted-by: LLM Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
ReplicasOf asks the cache which spellings of a definition its replicas carry, on every pass of every definition on the controller and of every replica on a satellite. Without an index that is a copy of every cached Resource into a fresh list each time: far cheaper than the uncached whole-cluster read it replaced, but still linear in the cluster and paid dozens of times a second. Index the cache by the key of the definition name, so the lookup touches that definition's replicas only. The controller gets it with the rest of the store's indexes; the satellite builds its own manager and registers it there. A cache without the index still answers, by the full walk. Assisted-by: LLM Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
Each ReplicasOf call asked the API server for the definition to learn its spellings, a request per pass of every definition and every replica. Those spellings are fixed when the definition is created, so the cache's copy names them as well as the server's does. Ask the server only when the cache has not seen the definition yet. Assisted-by: LLM Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
On a cluster whose Resource CRD predates the selectable field every ReplicasOf call sent the definition lookup and a refused list before the whole-cluster read it ends on, three requests where there used to be one. Remember the server's refusal for the process and go straight to the whole-cluster read. The CRD and the binaries ship in one release, so the process is replaced before a CRD that would accept the selector arrives. Assisted-by: LLM Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
The whole-cluster list ReplicasOf replaced came back sorted by object name. The scoped read concatenated its answers spelling by spelling, so a definition whose replicas carry mixed spellings came back in a different order. Sort, so callers see the order they always did. Assisted-by: LLM Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
A field selector matches one spelling exactly, so a replica applied by hand under a spelling neither the definition nor the cache knows yet is missed until the next pass. Say so where the read is defined, along with why nothing blockstor writes is such a replica and why the store's own definition reads differ from this one. ReplicasOf already answers only the definition's replicas, so the callers' second filter by definition name is dead code. Assisted-by: LLM Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
Registering the cached-replica index pushed NewManager past the funlen budget. The five reconciler registrations are one step with one error shape, so they move out together and NewManager keeps the ordering. Assisted-by: LLM Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
The remembered selector refusal is process-wide by design: it is a fact about the one API server the process talks to, so it stays a package variable with the reason stated. The test export becomes a function rather than a second global, the refusal test drops a nolint directive paralleltest never needed, and the index test preallocates its object list. Assisted-by: LLM Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 15 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
The placer writes a placement's replicas one at a time. The controller's tiebreaker reconciler sees the definition between those writes, and at two diskful replicas of a three-replica placement it puts a TIE_BREAKER witness on the node the third one is for. The placer's create then found that witness, took "already exists" for its replica and reported the placement done. The definition stayed two diskful replicas and a witness until a later placement promoted the witness, two to three minutes on, with the first replica suspended without quorum meanwhile. The race was always there; it was hidden while the reconciler read every Resource in the cluster, which took longer than the gap between two creates. Reading only the definition's replicas made the reconciler fast enough to land the witness inside the gap. LINSTOR places a diskful replica over a TieBreaker by taking the witness over, and the placer already does so for a witness it saw before it started. A diskless replica found by the create is now promoted the same way; a diskful one is left as it is. Assisted-by: LLM Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
The placer promoted whatever replica it found on the node. A witness the controller was already deleting got its flags stripped and was counted as placed, so the placement reported a replica that was gone a moment later. A witness that vanished and was written again between the promote and its fallback create was counted as the diskful replica, the bug the take-over fixes, one step further on. The promotion now decides on the replica it patches: one being deleted leaves the node unplaced, one that turned diskful is left as it is, and a create that finds a replica again goes back to the promotion for a bounded number of rounds. Assisted-by: LLM Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
The race between the placer and the tiebreaker reconciler only shows when a replica create takes longer than the controller's pass over the definition, which envtest never does. The burst stack now takes the latency of a create and of a whole-cluster Resource read, and a three-replica spawn at 100 ms and 400 ms checks that no witness is left on any node once the autoplace answers. Without the placer's take-over three of four spawns end with a witness; with the controller reading every Resource at 400 ms none does, which is why the race stayed hidden. Assisted-by: LLM Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
A three-replica spawn came up with one connection StandAlone for good. The placer writes the replicas one at a time, and the tiebreaker reconciler, seeing the first two, put a TIE_BREAKER witness on the node the third was for. The placement took the witness over as diskful, but the first two replicas had set it up as a diskless peer by then, and one kernel refused the handshake with "The peer is configured to be diskless but presents Inconsistent". LINSTOR decides on the witness once the whole placement is written, in the same transaction. A placement now says it is in progress with an RD annotation, and the reconciler adds no witness while it is due; the deadline only bounds a placement that never got to remove it. Assisted-by: LLM Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
A placement of more than one diskful replica stamps the RD as in progress before its first create and removes the stamp when it is done, so the tiebreaker reconciler decides on the replicas it placed rather than on the first two of three. The take-over of a witness written meanwhile stays as the fallback for a stamp that could not be written. A placement of one replica passes through no other shape and writes nothing. Assisted-by: LLM Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
The spawn test checked the replicas once the autoplace answered, when a witness the placement took over is already gone. A watch on the Resources now records every witness of the definition while it runs. Without the placement's hold three of four spawns show one on the third node, which is what left a peer's connection StandAlone. Assisted-by: LLM Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
Placements of one definition run in the REST server and in the controller, and lockDefinition serialises them within one process only. The second placement overwrote the first one's stamp and removed it when it finished, so the first went on writing replicas with no hold, and the tiebreaker reconciler could put a witness on a node it was about to make diskful. The annotation now lists one deadline per placement. Each adds its own, removes only its own and drops the expired ones of placements that never removed theirs; the reconciler holds while any is due. Assisted-by: LLM Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
`linstor r c n1 n2 n3 rd` writes its replicas one at a time, the same as a placement, but took no hold. After the second create the tiebreaker reconciler saw an even-diskful tie and put a witness on n3, which n1 and n2 set up as a diskless peer before the third create took it over as diskful: the race the placement hold closes. LINSTOR writes the whole request in one transaction. A request for two or more diskful replicas now holds the witness until it is written. Assisted-by: LLM Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
A placement that dies before it removes its hold leaves two diskful replicas and no witness, and nothing wakes the definition again. Here the 5 s requeue brings it back; the change that drops that requeue for deadline-driven ones must count the placement hold among the deadlines and read it as the list it is, or this test fails instead of a cluster sitting in the split-brain shape until the next resync. Assisted-by: LLM Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
Aleksei Sviridkin (lexfrei)
left a comment
There was a problem hiding this comment.
I went through ReplicasOf and its fallback, the definition-key index on both managers, the per-placement hold and its release, and the live-replica take-over. I found nothing blocking. The take-over of a diskless replica matches upstream autoplace, which passes nodes with an existing diskless replica to setSkipAlreadyPlacedOnNodeNamesCheck (CtrlRscAutoPlaceApiCallHandler). The #308 merge note in the description is the one thing to carry: whichever of the two lands second needs nextTiebreakerDeadline to read the placement hold.
What this reduces
A burst of 16 replicated volumes no longer timed out on v0.4.0-alpha.7, but each CreateVolume still took about 30 seconds, and the six volumes waiting for a free provisioner worker took about 60. A third of the autoplace calls ended on the 30-second deploy bound. The satellites spent that time running passes slowly, and the controller handed out DRBD identities slowly. Neither was waiting on DRBD.
Root cause
The controller and every satellite run at their CPU limit (500m) while the cluster is idle. On the test cluster with about 400 replicas, cAdvisor shows the satellites throttled in 82 to 94 percent of CFS periods, at about 0.48 cores used on average. The controller is throttled in 87 percent of periods. A burst then runs on what is left.
Two reads cause most of that load, and both read every Resource in the cluster past the cache, which is about 1.5 MB of JSON at 400 replicas:
listReplicasDirect). With 180 definitions that is about 36 whole-cluster lists a second. In an envtest profile with 411 replicas this one read took 38 percent of the controller's CPU, and the controller used 0.50 cores while doing nothing but take four status writes a second.listPeerResources). It was the largest satellite cost in the same profile.The CRD already declares
spec.resourceDefinitionNameselectable, and the store already uses it for definition-scoped reads.Changes
listReplicasDirectasks the API server for the definition's replicas, with one field-selected list per spelling of the name. The spellings are the ones the store knows plus every spelling a replica in the cache carries, so a replica written under another spelling is still counted.listPeerResourcesuses the same read. A peer the read misses would be left out of the rendered.res, so the cache-observed spellings matter here too.ReplicasOfsays so.tests/integration/burst_provisioning_test.godrives the burst linstor-csi sends: 16 volumes behind 10 workers, each placed in two autoplace calls, through the REST server, the controller and one real satellite resource reconciler per node, on nodes that already hold volumes. It measures how long each create takes until its replicas are built and ready, which is when LINSTOR answers. It runs only withBURST_BENCH=1.The cause is not in an open PR branch: both reads are on
mainand have been there since May. The commits apply cleanly on top of the v0.4.0-alpha.7 stack.Testing
go vet ./...,go test ./...with envtest,make lint-configandmake lint(0 issues), all with Go 1.25.7.pkg/naming,TestNamesAreComparedAsKeys) passes with the refilters afterReplicasOfremoved.ReplicasOffinds a replica under a spelling only the cache knows, and falls back to the whole-cluster read when the selector is refused. With their part of the fix reverted, the two scope tests fail ("read every Resource in the cluster 1 time(s)"). With the cache spellings dropped, the spelling test fails because it misses the replica.GOMAXPROCS=2for the whole process (controller, REST server, three satellites), on a shared workstation: burst 26.3 s and 30.1 s in two runs before, 15.8 s after; slowest CreateVolume 20.4 s and 22.9 s before, 12.7 s after; median CreateVolume about 15 s before and 8.6 s after; 16 of 16 creates over 10 s in both runs before, 5 of 16 after. The numbers move with the machine's load, so read them as a range rather than a figure.-tags=integration,TestGroupKWFandTestSmoke) on this branch: all passed in a second run. In the first,TestGroupKWFHappyPathfailed once while another build ran on the workstation; it passed in the rerun of the group and in seven runs on its own.r l) and took 2 to 3 minutes to be ready, against 6 to 13 s on v0.4.0-alpha.7. A DRBD watcher on the cluster saw the spawn's first replica suspended once, 9 s after the spawn, with its connection to the third node still Connecting; the watcher does not tell the suspend reasons apart, so whether quorum was the reason is not established.TestSpawnThreeDiskfulTakesOverTheWitnessGrownMeanwhilereproduces the race on envtest with the controller, the REST server and three satellite reconcilers. The burst stack now takes the latency of a replica create (100 ms) and of a whole-cluster Resource read (400 ms, Resource lists only), which envtest otherwise answers in a fraction of. Four three-replica autoplaces each check that no replica is a witness once the autoplace answers and that all three come up. Without the placer fix three of the four end with a witness (the first, on a cold controller, does not race). With the controller reading every Resource at 400 ms and without the placer fix, none of six did, which is why the race stayed hidden. With the fix, four of four and three runs of six of six came up three diskful.TestGroupKWF*,TestGroupFRAutoPlace*,TestGroupFRToggleDiskful2DisklessReapsTieBreaker,TestGroupCRGSpawnResources,TestSpawnThreeDiskfulTakesOverTheWitnessGrownMeanwhile) pass on the final head. The full integration suite on the final head passed exceptTestGroupKWFHappyPath, which timed out once waiting for its snapshot ("Snapshot wf-happy.snap-1 not created") while the other branch's suite was compiling; it passed five runs on its own right after, and passed in the group run.Not tested
GOMAXPROCSonly approximates them.TestGroupKWFHappyPathfailures: twice now it timed out waiting for its snapshot under load and passed on its own each time, which points at timing under load, not proven.DELETEflag, which the Kubernetes store shows for a Resource with a DeletionTimestamp.Known limitations
This removes the largest CPU cost at idle, but not every part of the burst latency. In the benchmark a create still takes several seconds per autoplace under contention. What remains is the number of satellite passes a new replica goes through before its device is reported. These include the finalizer pass with its five-second requeue, the waits for the controller's allocation, and peer passes that each run a full
drbdadm adjust, together with the 500m CPU limit in the deployment manifests. Those are separate changes.The witness still appears for the moment between the second and the third create before the placer promotes it, and the controller sets the definition's quorum for it in between. LINSTOR writes the replicas of an autoplace in one transaction and never shows it. Keeping the reconciler from growing a witness while a placement runs needs a signal between the REST server and the controller and is left out here.
Merging into the v0.4.0-alpha stack:
tryPlacethere also records the nodes a placement deployed to and created on (#291 and the snapshot-delete branch). A witness the create takes over belongs in the deployed list and not in the created one, as for a witness seen before the placement started, and so does the replica the take-over lands through its fallback create. A node whose witness was being deleted is in neither list, since nothing was placed there.No witness during a placement
What this fixes
A three-replica spawn on v0.4.0-alpha.12 left one connection of the new resource
StandAlonefor ten minutes. One replica's kernel had set its peer up as a diskless peer, and when that peer came up diskful the handshake failed withThe peer is configured to be diskless but presents Inconsistent. One spawn of two on the test cluster hit it.Root cause
The peer had been a TIE_BREAKER witness for about a second. The placer writes a placement's replicas one at a time, and the tiebreaker reconciler, reading only the definition's replicas since this PR, sees the first two of three as the even-diskful tie a witness breaks and puts one on the node the third replica is for (controller log:
ensureTiebreaker replicas: 2, diskful: 2, witness: 0, willCreate: true). The placement then takes the witness over as diskful, which settles the count, but by then the first two replicas have rendered and brought up the witness as a diskless peer. LINSTOR decides on the witness once the whole placement is written, in the same transaction, so it never shows one there.Changes
blockstor.org/placement-in-progress-untilon the definition before its first create and removes its own stamp when it is done, which wakes the definition's reconciler. A placement of one replica writes nothing.linstor r c n1 n2 n3 rdwrites its replicas one at a time just like a placement, while LINSTOR writes them in one transaction. A request with two or more diskful replicas now holds the witness until all of them are written; a single replica or a diskful one next to a diskless one writes nothing.When merged with #308, which replaced the 5-second requeue with a requeue at the witness deadlines,
nextTiebreakerDeadlinemust also come back at the latest due placement hold, read withapiv1.PlacementInProgressUntil(the value is a list, so adding the key to thetime.Parseloop is not enough). A test here fails on that merge until it does: a reconcile under a placement hold must requeue within the hold.Testing
pkg/placer: every create of a three-replica placement sees the stamp, the stamp is gone afterwards, and a one-replica placement never writes it. Fails with the hold or its removal taken out.pkg/placer: two holds on one definition, the later one released first, leave the earlier one in force, and releasing both leaves no annotation. Fails with the single-value stamp this replaces.pkg/rest:r cof three diskful replicas sees the hold at every create and leaves none behind; one diskful replica, and one diskful next to a diskless one, write nothing. Fails without the hold, and the diskless case fails when diskless envelopes are counted.pkg/api/v1: adding, removing and reading the per-placement holds, including expired and unparseable entries.internal/controller: two diskful replicas with a live stamp get no witness, also when the live stamp sits next to an expired one; with only an expired stamp they get one. Fails with the gate taken out, and the list case fails with a single-value parse. A reconcile under a placement hold requeues within the hold; fails with the requeue removed, and fails on a trial merge with perf(controller): stop re-reading every definition every 5 s #308 untilnextTiebreakerDeadlinereads the hold.tests/integration: the three-replica spawn at cluster latency (100 ms a create, 400 ms a whole-cluster read) now watches the Resources during the autoplace and fails on any witness. Without the hold three of four spawns show one on the third node; with it none does.make lint-config && make lint: 0 issues.go test ./...and the integration suite pass.Not tested
r cof three nodes, end to end: both are covered by unit tests against the in-memory store only.