-
-
Notifications
You must be signed in to change notification settings - Fork 78
Split the duplicate-marker passes out of every reindex #1997
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "context" | ||
| "errors" | ||
| "strings" | ||
| "testing" | ||
| ) | ||
|
|
||
| func companyList(n int) []string { | ||
| out := make([]string, n) | ||
| for i := range out { | ||
| out[i] = "co" | ||
| // Distinct enough for the error message; the loop never inspects the values. | ||
| out[i] += string(rune('a' + i%26)) | ||
| } | ||
| return out | ||
| } | ||
|
|
||
| // One dead batch must not starve the rest — that is the whole reason the pass is | ||
| // batched with per-batch fault isolation rather than one transaction. | ||
| func TestForCompanyBatchesIsolatesOneFailure(t *testing.T) { | ||
| companies := companyList(3 * companyBatchSize) | ||
| var calls int | ||
| total, err := forCompanyBatches(context.Background(), companies, func(_ context.Context, batch []string) (int64, error) { | ||
| calls++ | ||
| if calls == 2 { | ||
| return 0, errors.New("statement timeout") | ||
| } | ||
| return int64(len(batch)), nil | ||
| }) | ||
| if calls != 3 { | ||
| t.Fatalf("ran %d batches, want all 3 attempted despite the failure", calls) | ||
| } | ||
| if want := int64(2 * companyBatchSize); total != want { | ||
| t.Fatalf("total = %d, want %d — the two healthy batches must still count", total, want) | ||
| } | ||
| if err == nil { | ||
| t.Fatal("a failed batch must surface as an aggregate error") | ||
| } | ||
| } | ||
|
|
||
| // A cancelled context ends the pass. Every remaining batch would fail instantly | ||
| // against the same dead context, so continuing reports one deadline as hundreds of | ||
| // separate failures — which is exactly what obscured the 2026-08-16 timeout. | ||
| func TestForCompanyBatchesStopsOnCancellation(t *testing.T) { | ||
| companies := companyList(10 * companyBatchSize) | ||
| ctx, cancel := context.WithCancel(context.Background()) | ||
| var calls int | ||
| total, err := forCompanyBatches(ctx, companies, func(ctx context.Context, batch []string) (int64, error) { | ||
| calls++ | ||
| if calls == 2 { | ||
| cancel() | ||
| return 0, ctx.Err() | ||
| } | ||
| return int64(len(batch)), nil | ||
| }) | ||
| if calls != 2 { | ||
| t.Fatalf("ran %d batches, want it to stop at the cancelled one (2)", calls) | ||
| } | ||
| if !errors.Is(err, context.Canceled) { | ||
| t.Fatalf("err = %v, want it to carry context.Canceled so the caller can tell a deadline from a bad batch", err) | ||
| } | ||
| // The count must be the batches that COMPLETED, not the ones that failed: the | ||
| // cancellation branch runs before the failure is counted, so reporting failures | ||
| // there would always say zero and hide how far the pass actually got. | ||
| if !strings.Contains(err.Error(), "after 1 completed batches") { | ||
| t.Fatalf("err = %q, want it to report the 1 batch that completed before the cancellation", err) | ||
| } | ||
| // Work done before the cancellation is still reported: the pass is best-effort | ||
| // and its markers are already written. | ||
| if want := int64(companyBatchSize); total != want { | ||
| t.Fatalf("total = %d, want %d from the batch that completed", total, want) | ||
| } | ||
| } |
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,57 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "slices" | ||
| "strings" | ||
| "testing" | ||
| ) | ||
|
|
||
| // The fold moved out of the SQL and into Go for the planner's sake, so what it | ||
| // produces must still be byte-identical to what `replace(company_slug, '-', ”)` | ||
| // produced — the query compares the array against that same expression over the | ||
| // column, and any divergence silently stops matching rows rather than erroring. | ||
| func TestFoldCompanySlugs(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| in []string | ||
| want []string | ||
| }{ | ||
| {"strips every hyphen, not just the first", []string{"cfo-insights-gmbh"}, []string{"cfoinsightsgmbh"}}, | ||
| {"leaves an unhyphenated slug alone", []string{"cfoinsights"}, []string{"cfoinsights"}}, | ||
| // The collision is the whole point of folding: one source spells an employer | ||
| // "CFO Insights", another "Cfoinsights", and the two slugs must agree. | ||
| {"two spellings fold together", []string{"cfo-insights", "cfoinsights"}, []string{"cfoinsights", "cfoinsights"}}, | ||
| {"keeps duplicates rather than collapsing them", []string{"a-b", "ab"}, []string{"ab", "ab"}}, | ||
| {"empty input yields empty output", []string{}, []string{}}, | ||
| {"a slug that is only hyphens folds to empty", []string{"---"}, []string{""}}, | ||
| } | ||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| got := foldCompanySlugs(tt.in) | ||
| if !slices.Equal(got, tt.want) { | ||
| t.Fatalf("foldCompanySlugs(%q) = %q, want %q", tt.in, got, tt.want) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| // Order and length must survive the fold: the array is compared positionally by | ||
| // nothing, but a caller batching by companyBatchSize relies on one folded entry per | ||
| // input company — a shorter result would silently drop companies from the batch. | ||
| func TestFoldCompanySlugsPreservesLength(t *testing.T) { | ||
| in := make([]string, 500) | ||
| for i := range in { | ||
| in[i] = "company-" + strings.Repeat("x", i%7) + "-slug" | ||
| } | ||
| if got := foldCompanySlugs(in); len(got) != len(in) { | ||
| t.Fatalf("folded %d companies into %d entries", len(in), len(got)) | ||
| } | ||
| } | ||
|
|
||
| // A nil batch must not panic: forCompanyBatches never emits one today, but the | ||
| // helper is a plain function and the query would simply match nothing. | ||
| func TestFoldCompanySlugsNil(t *testing.T) { | ||
| if got := foldCompanySlugs(nil); len(got) != 0 { | ||
| t.Fatalf("foldCompanySlugs(nil) = %q, want empty", got) | ||
| } | ||
| } |
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
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.