-
Notifications
You must be signed in to change notification settings - Fork 367
Custodian: a sweeper to delete apps in smaller chunks #2845
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
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
11d1360
on-demand backups
dwwoelfel 323e388
add delete and cancel
dwwoelfel 35a2789
fail earlier
dwwoelfel b4ae99f
missing migration
dwwoelfel c088dfd
don't expose raw error to client
dwwoelfel bd39f6b
wait for the future to unwind
dwwoelfel 6c1e01d
fix pool size and resizing pool
dwwoelfel 21dc77d
Merge branch 'main' of github.com:instantdb/instant into on-demand-ba…
dwwoelfel f6f4458
reduce stuck threshold
dwwoelfel 8de30cb
coderabbit feedback
dwwoelfel c496390
much better cancellation
dwwoelfel 3869ddd
restores from /intern
dwwoelfel b2e9881
cleanup, better error handling
dwwoelfel ee33d01
include superuser email in admin emails
dwwoelfel b3b17f5
add a sweeper to delete apps in smaller chunks
dwwoelfel b36e059
better shutdown
dwwoelfel ffe9635
add a test
dwwoelfel e1cfe27
Merge branch 'main' of github.com:instantdb/instant into custodian
dwwoelfel 66b5f56
stop the hard-deletion sweeper
dwwoelfel e550ab6
guard against deleting apps/attrs that aren't marked for deletion
dwwoelfel e36835e
add attrs, fix a bunch of stuff in production
dwwoelfel 9ed0a22
safer deletion of app and attrs
dwwoelfel f43bbbb
Merge branch 'main' of github.com:instantdb/instant into custodian
dwwoelfel 2aab4c5
monitor inactive slots
dwwoelfel cacf078
fix docstring
dwwoelfel 38ec87d
docstring
dwwoelfel 2fc5d77
pause while failing over
dwwoelfel 9b5cb50
fix the flaky app backups test
dwwoelfel 3689c0c
remove unused functions
dwwoelfel 28228c1
timeout on derefs in tests
dwwoelfel 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| drop table custodian; | ||
|
|
||
| -- Recreate the trigger that cleans up triples_size_updates on attr delete. | ||
| create or replace function clean_triples_size_updates() | ||
| returns trigger as $$ | ||
| begin | ||
| delete from triples_size_updates where triples_size_updates.attr_id = old.id; | ||
| return old; | ||
| end; | ||
| $$ language plpgsql; | ||
|
|
||
| create trigger clean_triples_size_updates_trigger | ||
| before delete on attrs | ||
| for each row | ||
| execute function clean_triples_size_updates(); |
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,52 @@ | ||
| create table custodian ( | ||
| id uuid primary key default gen_random_uuid(), | ||
| -- The app being deleted. Cascade so the terminal `app` delete cleans up its | ||
| -- own plan rows for free. | ||
| app_id uuid not null references apps(id) on delete cascade, | ||
| -- Set when a unit of work is scoped to a single attr (e.g. deleting one | ||
| -- attr's triples). Null means the whole app. | ||
| attr_id uuid references attrs(id) on delete cascade, | ||
| -- What this row deletes: 'triples' | 'transactions' | 'attrs' | 'attr' | 'app' | ||
| type text not null, | ||
| -- The step this one depends on: it can't run until that step is done. Forms a | ||
| -- chain, e.g. for an app: app depends on transactions depends on triples. A | ||
| -- step finishes by deleting its row; `on delete set null` then clears this | ||
| -- pointer on the dependent, so the runnable row is simply the one with | ||
| -- depends_on is null. | ||
| depends_on uuid references custodian(id) on delete set null, | ||
| -- The worker that owns this row (null when unclaimed), set on claim. Doubles | ||
| -- as an owner tag. A worker heartbeats by bumping updated_at as it works; the | ||
| -- reaper frees a row (clears worker_id) whose updated_at has gone stale. | ||
| worker_id text, | ||
| -- 'waiting' (runnable) -> 'working' (claimed by a worker) and back to 'waiting' | ||
| -- on a failed attempt; set to 'failed' once processing has errored enough times | ||
| -- (see `attempts`) so it stops being retried and can be investigated. | ||
| status text not null default 'waiting', | ||
| -- How many times processing this row has errored. We retry a few times before | ||
| -- giving up and marking it 'failed', since some failures are transient. | ||
| attempts integer not null default 0, | ||
| -- The error message from the most recent failure. | ||
| error text, | ||
| created_at timestamptz not null default now(), | ||
| updated_at timestamptz not null default now(), | ||
| -- At most one row per (app, type, attr). `nulls not distinct` so two whole-app | ||
| -- rows (attr_id is null) of the same type collide instead of duplicating. | ||
| constraint custodian_unique unique nulls not distinct (app_id, type, attr_id) | ||
| ); | ||
|
|
||
| create index custodian_attr_id on custodian (attr_id); | ||
| create index custodian_depends_on on custodian (depends_on); | ||
|
|
||
| create index custodian_claimable on custodian (created_at) | ||
| where depends_on is null and worker_id is null and status = 'waiting'; | ||
|
|
||
| create trigger update_custodian_updated_at | ||
| before update on custodian | ||
| for each row | ||
| execute function update_updated_at_column(); | ||
|
|
||
| -- Drop the trigger that cleaned up triples_size_updates on attr delete. The | ||
| -- updater clears out the rows for us, so there's no need to delete them here. | ||
| -- When we delete an app, it causes us to delete too much. | ||
| drop trigger if exists clean_triples_size_updates_trigger on attrs; | ||
| drop function if exists clean_triples_size_updates(); |
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.