-
Notifications
You must be signed in to change notification settings - Fork 87
feat: db account storage cleanup task #1296
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
base: next
Are you sure you want to change the base?
Conversation
| #[derive(Clone)] | ||
| pub struct Db { | ||
| pool: deadpool_diesel::Pool<ConnectionManager, deadpool::managed::Object<ConnectionManager>>, | ||
| notify_cleanup_task: tokio::sync::mpsc::Sender<BlockNumber>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Depending on what we do with the validator database (whether we re-use this or not), it would be good to make this task optional/disable-able
| // Strategy: For each vault_key, keep the latest entry (is_latest_update=true) and the | ||
| // most recent MAX_HISTORICAL_ENTRIES_PER_ACCOUNT historical entries, deleting the rest. | ||
| // | ||
| // Unfortunately, Diesel doesn't support window functions (ROW_NUMBER OVER) in its type-safe | ||
| // API, so we must use raw SQL for this complex deletion pattern. This is necessary because: | ||
| // 1. We need to partition by vault_key and order by block_num | ||
| // 2. We need to delete based on row ranking within each partition | ||
| // 3. The table is created WITHOUT ROWID, so we use the primary key (account_id, block_num, | ||
| // vault_key) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure we need to keep MAX_HISTORICAL_ENTRIES_PER_ACCOUNT - we just need to make sure we have the data for the last
DELETE FROM account_vault_assets
WHERE
block_num < chain_tip - n
AND is_latest_update = falseTo make this query efficient, we may need to add indexes on block_num and is_latest_update fields.
This methodology should also apply to the account_storage_map_values table (and in the future to the accounts table).
Ref #1185 step 5.