-
Notifications
You must be signed in to change notification settings - Fork 5
perf(pebble): unlink spill chunks during merge, sort resources on import #1107
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
Open
kans
wants to merge
10
commits into
main
Choose a base branch
from
kans/pebble-sanitize
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
60770e8
perf(pebble): unlink spill chunks during merge, sort resources on import
kans 4034161
perf(pebble): route the remaining merges through the shared spill cursor
kans 3d980ac
test(pebble): cover the cross-chunk fold in the migration merge
kans 685506b
test(pebble): close the index sorters before the staging dir goes away
kans b9e8366
docs(pebble): fix comments left stale or muddy by the spill-cursor work
kans 802d21c
feat(c1zsanitize): route pebble destinations through the bulk-import …
kans 216d59f
fix(pebble): size the bulk import's record sorters for record-carryin…
kans 5aba21f
fix(pebble): move the bulk import's grant shards to 128MiB spill chunks
kans 1b0058b
fix(pebble): export ErrBulkImportDuplicateKey and true up operator-fa…
kans 27a3042
docs(pebble): widen two docs the review round proved too narrow
kans File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| package c1zsanitize | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
|
|
||
| v2 "github.com/conductorone/baton-sdk/pb/c1/connector/v2" | ||
| "github.com/conductorone/baton-sdk/pkg/dotc1z/engine/pebble" | ||
| ) | ||
|
|
||
| // recordSink is where sanitizeSync's copy loops write the four record | ||
| // families. It is exactly the method subset of connectorstore.Writer those | ||
| // loops use, so a sqlite destination satisfies it as-is (upserting Put* | ||
| // path); a pebble destination substitutes bulkImportSink so the same | ||
| // transform loops feed the engine's bulk-import fast path instead. | ||
| type recordSink interface { | ||
| PutResourceTypes(ctx context.Context, resourceTypes ...*v2.ResourceType) error | ||
| PutResources(ctx context.Context, resources ...*v2.Resource) error | ||
| PutEntitlements(ctx context.Context, entitlements ...*v2.Entitlement) error | ||
| PutGrants(ctx context.Context, grants ...*v2.Grant) error | ||
| } | ||
|
|
||
| // bulkImportSink adapts a pebble BulkSyncImport to recordSink. The bulk | ||
| // contract (fresh sync, nothing else writes until Finish) holds on the | ||
| // sanitize path by construction: StartNewSync marked the destination sync | ||
| // fresh, resumable+pebble is rejected up front so every checkpoint call is | ||
| // a no-op, and assets are copied only after finish() has ingested. | ||
| // | ||
| // Semantics vs. the Put* path: Put* upserts, the bulk path does not. A | ||
| // source sync carrying two records with the same sanitized external id now | ||
| // fails the import (resource types/resources/entitlements) or folds with a | ||
| // warning (grants) instead of silently last-write-wins. A valid c1z has | ||
| // unique external ids per sync, so this only surfaces on corrupt input. | ||
| // | ||
| // Grants flow through a single shard: the sanitizer's grant loop is | ||
| // sequential, so shard fan-out would add nothing. | ||
| type bulkImportSink struct { | ||
| eng *pebble.Engine | ||
| bi *pebble.BulkSyncImport | ||
| shard *pebble.BulkGrantShard | ||
| syncID string | ||
| } | ||
|
|
||
| // startBulkImportSink opens a bulk import on the destination's current | ||
| // fresh sync. tmpDir stages spill files ("" = system temp dir). | ||
| func startBulkImportSink(ctx context.Context, eng *pebble.Engine, syncID string, tmpDir string) (*bulkImportSink, error) { | ||
| bi, err := eng.StartBulkSyncImport(ctx, syncID, tmpDir) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("start bulk import: %w", err) | ||
| } | ||
| shard, err := bi.NewGrantShard() | ||
| if err != nil { | ||
| bi.Abort() | ||
| return nil, fmt.Errorf("open grant shard: %w", err) | ||
| } | ||
| return &bulkImportSink{eng: eng, bi: bi, shard: shard, syncID: syncID}, nil | ||
| } | ||
|
|
||
| func (s *bulkImportSink) PutResourceTypes(ctx context.Context, resourceTypes ...*v2.ResourceType) error { | ||
| // copyResourceTypes writes the full set once, sorted by output id, | ||
| // which is the sorted-by-external-id arrival AddResourceTypes requires. | ||
| return s.bi.AddResourceTypes(ctx, resourceTypes...) | ||
| } | ||
|
|
||
| func (s *bulkImportSink) PutResources(ctx context.Context, resources ...*v2.Resource) error { | ||
| return s.bi.AddResources(ctx, resources...) | ||
| } | ||
|
|
||
| func (s *bulkImportSink) PutEntitlements(ctx context.Context, entitlements ...*v2.Entitlement) error { | ||
| return s.bi.AddEntitlements(ctx, entitlements...) | ||
| } | ||
|
|
||
| func (s *bulkImportSink) PutGrants(ctx context.Context, grants ...*v2.Grant) error { | ||
| return s.shard.AddGrants(ctx, grants...) | ||
| } | ||
|
|
||
| // finish seals the grant shard and ingests the import. After it returns | ||
| // nil the destination sync holds every record the sink received and the | ||
| // writer path (PutAsset, EndSync) may be used again. | ||
| func (s *bulkImportSink) finish(ctx context.Context) error { | ||
| s.shard.Close() | ||
| return s.bi.Finish(ctx) | ||
| } | ||
|
|
||
| // abort discards a still-open import's staged spill files. Deferred by | ||
| // sanitizeSync to cover error exits before finish is reached; once Finish | ||
| // has run — success or failure — it has marked the import done and torn | ||
| // down its own staging, and Abort is a no-op. | ||
| func (s *bulkImportSink) abort() { | ||
| s.bi.Abort() | ||
| } | ||
|
|
||
| // stashStats hands the import's record counts (plus the asset count, which | ||
| // rides outside the import) to the engine as the sync's stats sidecar, so | ||
| // EndSync persists stats directly instead of re-scanning the freshly | ||
| // ingested keyspaces. | ||
| func (s *bulkImportSink) stashStats(assetCount int64) { | ||
| rec := s.bi.ComputedStats() | ||
| rec.SetAssets(assetCount) | ||
| s.eng.StashComputedSyncStats(s.syncID, rec) | ||
| } |
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.