Skip to content

fix: avoid too many concurrent db queries when cache becomes invalid#699

Merged
icewind1991 merged 2 commits into
mainfrom
bugfix/noid/reduce-db-access-when-updating-storagemapping
May 18, 2026
Merged

fix: avoid too many concurrent db queries when cache becomes invalid#699
icewind1991 merged 2 commits into
mainfrom
bugfix/noid/reduce-db-access-when-updating-storagemapping

Conversation

@nilsding
Copy link
Copy Markdown
Member

In large installations it's more likely that multiple storage_update events are processed at the same time. When the storage mapping cache becomes invalid each of these events would try to query the database to update the cache.

Apart from causing additional load on the database this would also exhaust sqlx's internal connection pool when more event handling threads are running than there are available database connections -- in this case the Failed to query database: pool timed out while waiting for an open connection message is logged.

This PR changes how the storage mapping cache is updated once it becomes invalid by trying to reduce the chance of multiple threads querying the database at once. Other callers should then still retrieve the old cached mapping during the time the cache is updated.

In large installations it's more likely to process multiple storage_update
events at the same time.  When the storage mapping cache becomes invalid
each of these events would try to query the database to update the cache.

Apart from causing additional load on the database this would also exhaust
sqlx's internal connection pool when more event handling threads are running
than there are available database connections -- in this case the `Failed to
query database: pool timed out while waiting for an open connection` message
is logged.

This commit changes how the storage mapping cache is updated once it becomes
invalid by trying to reduce the chance of multiple threads querying the
database at once.  Other callers should then still retrieve the old cached
mapping during the time the cache is updated.

Signed-off-by: Jyrki Gadinger <[email protected]>
@nilsding nilsding self-assigned this Apr 24, 2026
@nilsding nilsding added 3. to review Performance 🚀 rust Pull requests that update rust code labels Apr 24, 2026
@icewind1991 icewind1991 merged commit 20eec4b into main May 18, 2026
44 checks passed
@icewind1991 icewind1991 deleted the bugfix/noid/reduce-db-access-when-updating-storagemapping branch May 18, 2026 15:14
rizlas pushed a commit to ConsortiumGARR/notify_push that referenced this pull request May 19, 2026
…-access-when-updating-storagemapping

fix: avoid too many concurrent db queries when cache becomes invalid
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3. to review Performance 🚀 rust Pull requests that update rust code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants