Skip to content

Optimize database transactions for checksum processing to eliminate lock contention - #27

Merged
MarkProminic merged 1 commit into
mainfrom
devin/1758791844-optimize-database-transactions
Sep 25, 2025
Merged

MarkProminic merged 1 commit into
mainfrom
devin/1758791844-optimize-database-transactions

Conversation

@devin-ai-integration

Copy link
Copy Markdown

Optimize database transactions for checksum processing to eliminate lock contention

Summary

Fixes "database is locked" errors during concurrent checksum processing by consolidating fragmented database transactions. Previously, each checksum operation created 2 separate transactions (status update → checksum calculation → final update), causing lock contention when 5 concurrent operations competed with monitoring queries. Now both database updates are wrapped in a single sequelize.transaction(), reducing lock windows by 50%.

Key changes:

  • Wrap both File.update() calls in single transaction in processChecksumWithTimeout()
  • Move checksum variable declaration outside transaction scope for SSE access
  • Add dynamic import for sequelize instance
  • Maintain existing timeout monitoring and error handling

Review & Testing Checklist for Human

  • Verify database lock contention is resolved - Test concurrent checksum processing while running monitoring queries (the original issue)
  • Confirm SSE real-time updates still work - Check that file status updates appear correctly in the web interface during processing
  • Test error handling paths - Verify transaction failures don't break SSE or leave files in inconsistent states
  • Monitor transaction hold times - Ensure file I/O happening inside transactions doesn't cause performance degradation

Notes

This addresses the core performance issue identified during file watcher optimization analysis. The transaction scope now includes checksum calculation (file I/O), which could hold database locks slightly longer, but eliminates the much more problematic fragmented transaction pattern.

Link to Devin run: https://app.devin.ai/sessions/a84f1763f38f47c7a556fc6af605272c
Requested by: @MarkProminic

- Wrap both File.update() calls in single sequelize.transaction()
- Eliminates fragmented transactions that cause database lock contention
- Reduces lock windows from 2 separate transactions to 1 per checksum
- Maintains existing SSE functionality and error handling
- Addresses 'database is locked' errors during concurrent processing

Co-Authored-By: mark.gilbert@prominic.net <mark.gilbert@prominic.net>
@devin-ai-integration

Copy link
Copy Markdown
Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@MarkProminic
MarkProminic merged commit 9058d73 into main Sep 25, 2025
1 of 4 checks passed
@MarkProminic
MarkProminic deleted the devin/1758791844-optimize-database-transactions branch September 25, 2025 10:40
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.

1 participant