-
Notifications
You must be signed in to change notification settings - Fork 4
Grant expansion: Remove expandable annotation after processing expandable grant. #601
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…able grant. When compacting syncs, we spend a lot of time expanding grants that have already been expanded. So now we remove the expandable annotation after putting the grant in the graph. Also improved the grant expand test to validate that we get the correct number of grants and that expandable annotations are removed.
WalkthroughThis pull request refactors grant expansion persistence by extracting Changes
Sequence DiagramsequenceDiagram
participant Syncer as Syncer
participant Graph as Graph Builder
participant Store as ExpanderStore
participant Batch as PutGrantsInChunks
Syncer->>Graph: Build entitlement graph
Graph-->>Syncer: Graph complete
loop For each fetched grant
Syncer->>Syncer: Check for GrantExpandable annotation
alt Has GrantExpandable
Syncer->>Syncer: Remove annotation<br/>Update grant record
Syncer->>Syncer: Accumulate in updatedGrants batch
end
alt Batch reaches size 10000
Syncer->>Batch: PutGrantsInChunks(ctx, store, batch, 10000)
Batch->>Store: PutGrants(ctx, grants...)
Store-->>Batch: Success/Error
Batch-->>Syncer: Updated grants
Syncer->>Syncer: Reset batch
end
end
alt Remaining grants in batch
Syncer->>Batch: PutGrantsInChunks(ctx, store, remaining, 0)
Batch->>Store: PutGrants(ctx, grants...)
Store-->>Batch: Success/Error
Batch-->>Syncer: Updated grants
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Areas requiring extra attention:
Possibly related PRs
Suggested reviewers
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
|
|
||
| // Remove expandable annotation from descendant grant now that we've added it to the graph. | ||
| // That way if this sync is part of a compaction, expanding grants at the end of compaction won't redo work. | ||
| newAnnos := make(annotations.Annotations, 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we ever do implement a two pass system, we could handle this bit then.
| grant.SetAnnotations(newAnnos) | ||
| l.Debug("removed expandable annotation from grant", zap.String("grant_id", grant.GetId())) | ||
| updatedGrants = append(updatedGrants, grant) | ||
| updatedGrants, err = expand.PutGrantsInChunks(ctx, s.store, updatedGrants, 10000) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we should capture that the grant was expandable but we already did the work.
When compacting syncs, we spend a lot of time expanding grants that have already been expanded. So now we remove the expandable annotation after putting the grant in the graph. Also improved the grant expand test to validate that we get the correct number of grants and that expandable annotations are removed.
This annotation is only used by the expansion code. Nothing else checks whether it exists, so it's safe to delete.
Summary by CodeRabbit
Release Notes
Bug Fixes
Performance
Tests
✏️ Tip: You can customize this high-level summary in your review settings.