This diff adds a function that performs the core cleanup logic. Its logic should be fail-proof: failure of any steps should prevent blob deletion.
The algorithm (also documented in code comments):
- Get both blobs and holders rows that are marked as "unchecked".
- Organize them into structures that have information about blob-holder assignments and their existence.
- Filter out entries that contain both blob and holders - they're valid.
- Get more information about entries that contain only blob or only holders:
- For holders, get the blob hash and check if it exists in DB
- For blobs, check if at least 1 holder exists in DB
- Update the struct with query results and repeat step 3.
- Delete rows that still contain only blob or only holders. Mark others as "checked".
Depends on D9351