WIP: Prune processed remote activities and old remote tombstones #7993

Draft
lambadalambda wants to merge 5 commits from feature/prune-processed-activities into feature/bounded-retention

Builds on #7980 (base branch feature/bounded-retention; retarget to develop once that is merged).

Summary

After the thread eviction of #7980, a large part of what remains is remote data that only mattered while it was being processed. The retention worker now also prunes it:

  • Remote Delete, Undo and Update activities older than processed_activity_days (default 7). Their side effects are applied on arrival; the stored copy only serves to recognise duplicate deliveries (Federator returns :already_present for a known activity id), hence the grace period. An Update that a local user still has a notification for is kept (edit notifications would otherwise cascade away). Walked by activity id with a persisted cursor, like the thread eviction.
  • Remote tombstones deleted more than tombstone_days ago (default 30), together with remote activities still pointing at them (normally the Delete). A tombstone stops a deleted post from being fetched again while its thread is active; after that, a fetch just gets a 410. Tombstones a local activity points at are kept (admin deletions of remote posts). Walked in deletion order with a cursor over a new partial index objects (updated_at, id) WHERE type = 'Tombstone', so kept ones are not rescanned.
  • Small refactor: flake id helpers moved to Retention.Cursor.

Measured on a copy of lain.com (after the #7980 walk)

  • 1,782,052 remote Delete/Undo/Update activities pruned in 109 runs (6.3 s average per 50k walked); exactly the ones older than 7 days, minus two Updates with notifications.
  • 1,130,662 remote tombstones pruned in 24 runs (16 s average). Kept: 4,850 younger than 30 days, 2,707 that local moderation Deletes point at, 102 local ones.
  • Notifications, local activities and local Delete/Undo/Update unchanged.
  • Pleroma data 14.6 GB → 12 GB after VACUUM FULL (activities 7.4 → 5.1 GB, objects 3.3 → 2.9 GB).
  • Index build: 11 s, 34 MB.

Known limitations

  • A Delete or Update that arrives again after the grace period is processed again (a Delete of an already deleted post re-tombstones it).
  • Rows are deleted with delete_all, so cached copies stay until their cache TTL, as with the thread eviction.

Testing

  • mix test test/pleroma/retention test/pleroma/retention_test.exs test/pleroma/workers/cron/retention_worker_test.exs test/mix/tasks/pleroma/database_test.exs test/pleroma/docs test/pleroma/config (124 tests, 0 failures). Full suite: only the exiftool tests fail locally (binary not installed).
Builds on #7980 (base branch `feature/bounded-retention`; retarget to `develop` once that is merged). ## Summary After the thread eviction of #7980, a large part of what remains is remote data that only mattered while it was being processed. The retention worker now also prunes it: - **Remote Delete, Undo and Update activities** older than `processed_activity_days` (default 7). Their side effects are applied on arrival; the stored copy only serves to recognise duplicate deliveries (`Federator` returns `:already_present` for a known activity id), hence the grace period. An Update that a local user still has a notification for is kept (edit notifications would otherwise cascade away). Walked by activity id with a persisted cursor, like the thread eviction. - **Remote tombstones** deleted more than `tombstone_days` ago (default 30), together with remote activities still pointing at them (normally the Delete). A tombstone stops a deleted post from being fetched again while its thread is active; after that, a fetch just gets a 410. Tombstones a local activity points at are kept (admin deletions of remote posts). Walked in deletion order with a cursor over a new partial index `objects (updated_at, id) WHERE type = 'Tombstone'`, so kept ones are not rescanned. - Small refactor: flake id helpers moved to `Retention.Cursor`. ## Measured on a copy of lain.com (after the #7980 walk) - 1,782,052 remote Delete/Undo/Update activities pruned in 109 runs (6.3 s average per 50k walked); exactly the ones older than 7 days, minus two Updates with notifications. - 1,130,662 remote tombstones pruned in 24 runs (16 s average). Kept: 4,850 younger than 30 days, 2,707 that local moderation Deletes point at, 102 local ones. - Notifications, local activities and local Delete/Undo/Update unchanged. - Pleroma data 14.6 GB → 12 GB after `VACUUM FULL` (activities 7.4 → 5.1 GB, objects 3.3 → 2.9 GB). - Index build: 11 s, 34 MB. ## Known limitations - A Delete or Update that arrives again after the grace period is processed again (a Delete of an already deleted post re-tombstones it). - Rows are deleted with `delete_all`, so cached copies stay until their cache TTL, as with the thread eviction. ## Testing - `mix test test/pleroma/retention test/pleroma/retention_test.exs test/pleroma/workers/cron/retention_worker_test.exs test/mix/tasks/pleroma/database_test.exs test/pleroma/docs test/pleroma/config` (124 tests, 0 failures). Full suite: only the exiftool tests fail locally (binary not installed).
Makes id_at/1, after?/2 and local_prefix/0 usable from other retention
walks.
Their side effects are applied on arrival; the stored copy only serves to
recognise duplicate deliveries. Walk activities by id like the thread
eviction and drop remote ones older than processed_activity_days (7 by
default), unless a notification still points at them.
A tombstone stops a deleted post from being fetched again while its
thread is active. After tombstone_days (30 by default) drop remote ones,
with remote activities still pointing at them, unless a local activity
does. Tombstones are walked in deletion order with a persisted cursor
over a new partial index, so kept ones are not rescanned every run.
Both walks ignore a zero batch size and negative day counts.
docs(retention): document pruning of processed activities and tombstones
All checks were successful
ci/woodpecker/pr/changelog Pipeline was successful
ci/woodpecker/pr/lint Pipeline was successful
ci/woodpecker/pr/unit-testing-elixir-1.15 Pipeline was successful
ci/woodpecker/pr/unit-testing-elixir-1.19 Pipeline was successful
d6d4ce9f54
fix(retention): check tombstones against local activities through the index
All checks were successful
ci/woodpecker/pr/changelog Pipeline was successful
ci/woodpecker/pr/lint Pipeline was successful
ci/woodpecker/pr/unit-testing-elixir-1.15 Pipeline was successful
ci/woodpecker/pr/unit-testing-elixir-1.19 Pipeline was successful
39a48ccb74
The correlated NOT EXISTS became a hashed subplan that read every local
activity on each run (on lain.com 586k rows of random reads, minutes, and
the site slowed down). Now the batch's remote tombstone ids are looked up
with associated_object_id = ANY(...) in chunks of 1000, which uses
activities_create_objects_index: 5000 tombstones in 6.5 s there, cold.
All checks were successful
ci/woodpecker/pr/changelog Pipeline was successful
ci/woodpecker/pr/lint Pipeline was successful
ci/woodpecker/pr/unit-testing-elixir-1.15 Pipeline was successful
ci/woodpecker/pr/unit-testing-elixir-1.19 Pipeline was successful
This pull request is marked as a work in progress.
This branch is out-of-date with the base branch
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin feature/prune-processed-activities:feature/prune-processed-activities
git switch feature/prune-processed-activities

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch feature/bounded-retention
git merge --no-ff feature/prune-processed-activities
git switch feature/prune-processed-activities
git rebase feature/bounded-retention
git switch feature/bounded-retention
git merge --ff-only feature/prune-processed-activities
git switch feature/prune-processed-activities
git rebase feature/bounded-retention
git switch feature/bounded-retention
git merge --no-ff feature/prune-processed-activities
git switch feature/bounded-retention
git merge --squash feature/prune-processed-activities
git switch feature/bounded-retention
git merge --ff-only feature/prune-processed-activities
git switch feature/bounded-retention
git merge feature/prune-processed-activities
git push origin feature/bounded-retention
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
pleroma/pleroma!7993
No description provided.