-
Notifications
You must be signed in to change notification settings - Fork 4
Expand grants faster. #255
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
Changes from all commits
24a1823
853696a
3fcadd0
c7ca2f7
2bccd3e
66f9236
d0360b5
445faf2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,27 +8,29 @@ import ( | |
| "go.uber.org/zap" | ||
| ) | ||
|
|
||
| // JSON tags for actions, edges, and nodes are short to minimize size of serialized data when checkpointing | ||
|
|
||
| type EntitlementGraphAction struct { | ||
| SourceEntitlementID string `json:"source_entitlement_id"` | ||
| DescendantEntitlementID string `json:"descendant_entitlement_id"` | ||
| Shallow bool `json:"shallow"` | ||
| ResourceTypeIDs []string `json:"resource_types_ids"` | ||
| PageToken string `json:"page_token"` | ||
| SourceEntitlementID string `json:"sid"` | ||
| DescendantEntitlementID string `json:"did"` | ||
| Shallow bool `json:"s"` | ||
| ResourceTypeIDs []string `json:"rtids"` | ||
| PageToken string `json:"pt"` | ||
| } | ||
|
|
||
| type Edge struct { | ||
| EdgeID int `json:"edge_id"` | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. since we used these previously as a effective pagination token, does this mean ideally for in-place upgades we throw away "old" pagination state, and start over? should "version" the pagination token?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm sure we've broken this before. In an ideal world we'd version this stuff and write migrations, but I think the moneyball solution would be to end the sync if we error unmarshaling the json. I pushed a change that does this.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don;'t think we need a migration, we just need to start the specified sync step over from zero |
||
| SourceID int `json:"source_id"` | ||
| DestinationID int `json:"destination_id"` | ||
| IsExpanded bool `json:"expanded"` | ||
| IsShallow bool `json:"shallow"` | ||
| ResourceTypeIDs []string `json:"resource_type_ids"` | ||
| EdgeID int `json:"id"` | ||
| SourceID int `json:"sid"` | ||
| DestinationID int `json:"did"` | ||
| IsExpanded bool `json:"e"` | ||
| IsShallow bool `json:"s"` | ||
| ResourceTypeIDs []string `json:"rtids"` | ||
| } | ||
|
|
||
| // Node represents a list of entitlements. It is the base element of the graph. | ||
| type Node struct { | ||
| Id int `json:"id"` | ||
| EntitlementIDs []string `json:"entitlementIds"` // List of entitlements. | ||
| EntitlementIDs []string `json:"eids"` // List of entitlements. | ||
| } | ||
|
|
||
| // EntitlementGraph - a directed graph representing the relationships between | ||
|
|
@@ -47,6 +49,7 @@ type EntitlementGraph struct { | |
| Loaded bool `json:"loaded"` | ||
| Depth int `json:"depth"` | ||
| Actions []EntitlementGraphAction `json:"actions"` | ||
| HasNoCycles bool `json:"has_no_cycles"` | ||
| } | ||
|
|
||
| func NewEntitlementGraph(_ context.Context) *EntitlementGraph { | ||
|
|
@@ -56,6 +59,7 @@ func NewEntitlementGraph(_ context.Context) *EntitlementGraph { | |
| EntitlementsToNodes: make(map[string]int), | ||
| Nodes: make(map[int]Node), | ||
| SourcesToDestinations: make(map[int]map[int]int), | ||
| HasNoCycles: false, | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -155,6 +159,7 @@ func (g *EntitlementGraph) AddEntitlement(entitlement *v2.Entitlement) { | |
| if found != nil { | ||
| return | ||
| } | ||
| g.HasNoCycles = false // Reset this since we're changing the graph. | ||
|
|
||
| // Start at 1 in case we don't initialize something and try to get node 0. | ||
| g.NextNodeID++ | ||
|
|
@@ -265,6 +270,8 @@ func (g *EntitlementGraph) AddEdge( | |
| g.DestinationsToSources[dstNode.Id] = make(map[int]int) | ||
| } | ||
|
|
||
| g.HasNoCycles = false // Reset this since we're changing the graph. | ||
|
|
||
| // Start at 1 in case we don't initialize something and try to get edge 0. | ||
| g.NextEdgeID++ | ||
| edge := Edge{ | ||
|
|
||
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.
hmm, are there any side effects with this? When we re-compress the sqlite data file, wouldn't we also need the WAL file(s)?
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.
The WAL file is deleted when the last DB connection is closed. We always close the DB before calling saveC1z(), so the WAL file doesn't exist when we compress. If I comment out the calls to os.Remove() and os.RemoveAll(), the only file in the temp dir is the DB.