-
Notifications
You must be signed in to change notification settings - Fork 13
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
More thoroughly clean up current admin privileges table. #54
Conversation
requires PostgreSQL 9.4
TIL! |
How often is this called and what's a typical under-load size for the table? Just trying to figure out if the 10x difference in these calls is worth it:
What kind of speed ups did you see? |
I'm afraid I no longer remember, we were allowing PostgreSQL 9.3 back when I was looking into this! Normally the table's fairly empty as there aren't normally many transactions by admins in progress; it's cleaned up every ten seconds I think, something like that, so in the typical case nobody should notice any difference. This PR protects against a pathological case: a long-running transaction at a time when admins are up to stuff. A high fraction of the rows on this table might refer to completed transactions but if they started after that long-running transaction then they'll simply accumulate until it completes. |
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.
👍
Makes sense. Only running in the background, I can't imagine it will have much of an impact either:
public class LightAdminPrivilegesCleanup implements Runnable {
...
/**
* Start a new scheduled repeating task for cleaning up the <tt>_current_admin_privileges</tt> database table.
...
* @param delay the interval to wait in between cleanups, in seconds
*/
public LightAdminPrivilegesCleanup(SqlAction sqlAction, int delay) {
...
/* require delay of at least half the interval */
halfDelayMs = 500L * delay;
}
@Override
public void run() {
if (latestRunEnded + halfDelayMs < System.currentTimeMillis()) {
LOGGER.debug("running periodic cleanup of _current_admin_privileges table");
} else {
/* simple emulation of ThreadPoolTaskScheduler.scheduleWithFixedDelay */
LOGGER.debug("skipping periodic cleanup of _current_admin_privileges table");
return;
}
sqlAction.deleteOldAdminPrivileges(transactionIds);
transactionIds = sqlAction.findOldAdminPrivileges();
latestRunEnded = System.currentTimeMillis();
}
Just found this on merge-ci:
cc: @mtbc |
Thank you, I should look into that! |
Uses metadata introduced in PostgreSQL 9.4 to more aggressively trim the
_current_admin_privileges
table. It must include the rows pertaining to the currently active transactions but, otherwise, the smaller the table, the faster the checks.