Repository navigation
fix: a ChangeMembers reaching many scopes redid, for each, work that depends only on the actor's grants - #165
Merged
Conversation
…ery role giving each permission it asked where the actor held a conditional grant of a role giving none of them
…ery role a role it granted lists gives
… grant the actor held there where it held the same on all of them
…e once for the scopes it reaches
…ive each scope its own end With one end on every cluster, the positions read for it, found on the first scope, answered for every other, so the tests of the roles found to give nothing asked and of what a granted role asks passed with either reverted. Each cluster's grant now ends at its own time.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A
ChangeMembersreaching many scopes builds one authority per scope, before its transaction and again under its locks. Each one redid work that depends only on the actor's grants and the call, so cost grew with scopes × the actor's grants, or scopes × what a granted role asks. Decisions, and which conditions are read, when and in what order, are unchanged (see Testing).readEnding, a role that missed the first-permission shortcut counted inleft, and the loop over every asked permission, and every role giving each, stopped only whenleftreached 0. A role giving nothing any end asks is never found, soleftnever reached 0. Each authority walked |asked| × |roles giving each|, for every scope, twice. Adding a member to a group granted a role (cluster:grant, listing a role of 999 permissions) on 1,000 clusters, by an actor holding conditional grants of 300 roles giving those permissions plus one grant of a role giving onlycluster:odd, took 7.6 s (the audit measured 9.9 s), against 1.4 s without that one grant. The shortcut also misses whenever the granted role is a lister, so that 1.4 s baseline walked too.givers.none, by the roles the ends grant, for every authority of the call, so later authorities don't count it. Roles left to find are let go once the ends pass the latest of their grants. Each permission is looked up among the roles giving it or among those left, whichever is fewer. Not used whereSetRolechecks a role it defines, which resolves that role as it will be. Now 0.53 s with the odd grant and 0.52 s without (b19bb8a: 1.1 s and 1.3 s).asking(what deciding a grant of a role asks: its permissions and those of every role it lists, transitively) was memoized per authority. A group granted a role listing 64 roles of 1,000 permissions on 1,000 clusters, by an actor holding one unread conditional grant of a role giving one of them, took 2.9 s (the audit measured 3.6 s), against 0.1 s without it.askingkeeps its result with the call's sharedgivers(per book, so per call and per pass), except whereSetRolechecks a role it defines. It now counts the role entries it reads (readingEntries), as the rest of the change path does. Now 0.12 s.heldIndexand rangivingAtover every kind of grant, andreadEndingover every unread role, even where every scope held the same grants (all on the tenant). Adding a member to a group grantedcluster.loginunder a condition on 5,000 clusters, by an actor holding conditional grants of 300 roles on the tenant ending after, took 4.4 s (the audit measured 5.9 s), against 0.3 s without them. That contradicted the README's "once for all the scopes it reaches".provenalready keys by) share aheldCommon. It holds what turns on the grants alone: kinds, how long the unconditional ones last, unread grants by role and each role's latest end as first found, and the grants giving each permission. It also holdsreadEnding's positions for each list of ends, found as though none were read, soreadAtreads, of them, the ones each authority hasn't. It is used only for the authority's own grants, before it has read any condition. The sharedunreadis never changed. Read state (read,given,powers,readTo,unreadN) stays per authority, so the second pass under the locks builds its own, and fix: a check denied, and Permissions and Holding left out, what every moment allowed where a conditional grant was replaced as it ran, as extending one does #160's "false" marking stays per authority. The per-scope key is now built withstrconvinstead offmt.Sprint, which took a ninth of the call at 5,000 scopes. Now 1.1 s.docs/architecture.mddescribe the change path's cost as it now is.Testing
New tests, each failing without its part (run on 3b65f4f's
apply.go, or with only that part reverted, keeping the test hooks):TestAChangeToMembersLooksUpTheRolesGivingWhatItAsksOnceWhateverScopesItReaches(part 1, thenonememo). Each cluster's grant ends at its own time, so no scope reuses the positions another found for the same end (part 3). Fix: 18,382 → 22,596 entries from one cluster to 50. Canary fails:read 25542 entries ... and 422050 to one granted it on 50. With only the memo reverted it fails: 18,382 → 42,098.TestAChangeLooksUpNoRolesGivingWhatItAsksForARoleGivingNothingItAsks(part 1, letting go / smaller side). Fix: 17,532 → 18,336 entries with the odd grant. Canary fails:read 17130 entries granting a role, and 25496 beside a grant of a role giving nothing it asks. With only the memo kept it fails the same way.TestAChangeToMembersReadsWhatTheRolesItGrantsListOnceWhateverScopesItReaches(part 2). Each cluster's grant ends at its own time, as above. Fix: 20,805 → 33,839. With the per-callaskingreverted it fails:read 20805 entries ... and 818035 to one granted it on 50. On 3b65f4f'sapply.goit passes (4,801 → 18,227), asaskingdidn't count the entries it read there.TestAChangeToMembersWalksTheActorsGrantsOnceWhateverScopesItReaches(part 3). Fix: 720 → 916 grants walked, 1,628 → 1,922 entries. Canary fails:walked 822 grants and read 1624 entries ... and 20814 and 31514. Without thereadEndingmemo it fails: 720 → 10,716 walked. Withgivingper authority it fails: 1,628 → 11,918 entries.Decisions identical, on this branch, on 3b65f4f, and on this branch with a self-checking patch (#163's
val.patchadapted). The patch panics on any difference betweenreadEnding's reads and a scan of every unread role for every end, betweenaskingand a fresh walk, between the shared index and one built for the authority alone, between a cachedgivingAtand a fresh one, betweengiversand the book, and betweenunderand a scan. Outputs and logs masked for UUIDs and times are byte-identical across all three:ZZ_V260×60: 26,057 lines.ZZ_REPL80×60: 36,899 lines.decidedAsplain 40×120 (4,777 lines) and biased 60×120 (7,085).The validating build checked 8,928 and 12,322
readEndingcalls and 33,357 and 43,808 shared indexes with no panic. The only log difference is its extra stats line.Merged with canary 165131b (#164), cleanly, and run again on the merge, on 165131b and on the merge with the self-checking patch: #163's differential 60×60 (26,057 lines) and its replacement mode 80×60 (36,899), change sequences 80×120 (9,925),
decidedAs40×120 (4,777), conditional power 80×30 (31,892), straddle 40×60 (28,527) and the scope-sharing differential 60×60 (15,752) are byte-identical, and the batch differential, straddle, 300 seeds, has 0 mismatches. Its replacement mode, 60×60 (17,088 lines), differs on one change, whose grant is replaced under its locks: rerun 8 times, it ends refused or in a conflict on 165131b too (3 and 5 times, here 5 and 3).Timings: medians in ms, this branch / 3b65f4f / b19bb8a, alternating builds, 3 rounds (per-call: 8 rounds of 100 calls, then 9 interleaved rounds of 300):
cluster:grant(shortcut hits)cluster.loginon 5,000 clusters, 300 conditional roles giving itSingle-scope shapes are within noise. Apply of 1,000 built-in roles, "last", first measured at 377.5 vs 360.0 ms over 30 runs each, ran every run of one build before the next; interleaved, rotating the order each round, it is 312.8 vs 322.0 ms (b19bb8a 457.9) over 15 runs each. Interleaved over 12 rounds, Apply of 1,000 distinct catalog roles beside 300 held is 442.0 vs 443.3 ms, and per call Apply 5.39 vs 5.46 ms and ChangeMembers 8.23 vs 8.25 ms.
Full suite (
go test -race -shuffle=on -cover ./...) withGODEBUG=fips140=onlyagainst PostgreSQL 18, on 38b33fd (merged with canary 165131b): passed (2393.162s, coverage: 94.9% of statements).go tool -modfile=tools/go.mod golangci-lint run ./...: 0 issues;go mod tidy -diffclean; govulncheck: no affecting vulnerabilities.Checklist
make checkpasses🤖 Generated with pw code