Skip to content

Conversation

dan-chis19
Copy link

This update is to avoid crashes when the database is under high buffermapping contention. Current code does not account for when a database is under heavy usage of buffers. Found that under heavy contention the spinlock can take too long resulting in a PANIC and a crash. Recommend implementing error handling where a timeout occurs and exponential backoff reduces number of requests for the buffer header after each failure.

Key improvements in this version:

Added a timeout mechanism using MAX_SPIN_ATTEMPTS
Uses TryLockBufHdr instead of spinning indefinitely
Implements exponential backoff up to 1ms when retrying lock acquisition
Yields to other processes every 1000 buffers
Includes better error reporting with buffer details
Checks for interrupts periodically to allow query cancellation

Some notes:

The MAX_SPIN_ATTEMPTS value might need adjustment based on your specific workload
The sleep durations (10μs per attempt, capped at 1ms) might need tuning
The yield interval (1000 buffers) could be adjusted based on system characteristics
This version is much more resilient to spinlock contention and less likely to cause system-wide issues under heavy load. It will fail gracefully rather than potentially hanging indefinitely.

This update is to avoid crashes when the database is under high buffermapping contention. Current code does not account for when a database is under heavy usage of buffers. Recommend implementing error handling where a timeout occurs and exponential backoff reduces number of requests for the buffer header after each failure.
@postgres-mirror
Copy link
Collaborator

Thanks for your Pull Request! 😄 This repo on GitHub is just a mirror of our real git repositories though, and can't really handle PRs. 😦 Hopefully you can redo the PR, and direct it to the git.postgresql.org repos? We have a developer guide, if that helps: https://wiki.postgresql.org/wiki/So,_you_want_to_be_a_developer%3F.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants