-
Notifications
You must be signed in to change notification settings - Fork 6
refactor: dedicated read and write dispatchers [WPB-21390] #3681
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
refactor: dedicated read and write dispatchers [WPB-21390] #3681
Conversation
# Conflicts: # persistence/src/commonMain/kotlin/com/wire/kalium/persistence/dao/conversation/ConversationDAOImpl.kt # persistence/src/commonMain/kotlin/com/wire/kalium/persistence/dao/message/attachment/MessageAttachmentsDao.kt # persistence/src/commonMain/kotlin/com/wire/kalium/persistence/db/UserDatabaseBuilder.kt
Test Results3 397 tests - 644 3 388 ✅ - 542 3m 0s ⏱️ - 3m 0s Results for commit 5e83f0a. ± Comparison against base commit bdf3161. This pull request removes 4041 and adds 3397 tests. Note that renamed tests count towards both.This pull request removes 111 skipped tests and adds 9 skipped tests. Note that renamed tests count towards both.♻️ This comment has been updated with latest results. |
…read-and-write-dispatchers
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.
Pull Request Overview
This PR refactors the persistence layer to address Application Not Responding (ANR) issues caused by SQLCipher connection pool exhaustion. It introduces separate read and write dispatchers with limited parallelism (3 for reads, 1 for writes) to prevent database operation deadlocks.
Key changes:
- Introduced
ReadDispatcherandWriteDispatchervalue classes wrappingCoroutineDispatcher - Replaced generic
CoroutineContext/queriesContextparameters with typed dispatchers across all DAO implementations - Updated database operations to use appropriate dispatcher based on read/write nature
Reviewed Changes
Copilot reviewed 34 out of 34 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| UserDatabaseBuilder.kt | Creates separate read/write dispatchers with limited parallelism and updates all DAO instantiations |
| Multiple DAO files | Replaces CoroutineContext with ReadDispatcher/WriteDispatcher and wraps operations with appropriate dispatcher |
| MessageDAO.kt | Changes countMessagesForBackup from synchronous to asynchronous function |
| CallDAO.kt | Changes getEstablishedCall from synchronous to asynchronous function |
| CallRepository.kt | Wraps blocking DAO call in runBlocking to handle new async signature |
| Logic layer files | Removes @OptIn(ExperimentalCoroutinesApi::class) annotations now unnecessary |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
persistence/src/commonMain/kotlin/com/wire/kalium/persistence/db/UserDatabaseBuilder.kt
Show resolved
Hide resolved
persistence/src/commonMain/kotlin/com/wire/kalium/persistence/dao/ConnectionDAOImpl.kt
Outdated
Show resolved
Hide resolved
...ce/src/commonMain/kotlin/com/wire/kalium/persistence/dao/conversation/ConversationDAOImpl.kt
Outdated
Show resolved
Hide resolved
persistence/src/commonMain/kotlin/com/wire/kalium/persistence/dao/message/MessageDAOImpl.kt
Show resolved
Hide resolved
...in/kotlin/com/wire/kalium/persistence/dao/messageattachment/MessageAttachmentDraftDaoImpl.kt
Outdated
Show resolved
Hide resolved
persistence/src/commonMain/kotlin/com/wire/kalium/persistence/dao/client/ClientDAOImpl.kt
Show resolved
Hide resolved
logic/src/commonMain/kotlin/com/wire/kalium/logic/data/call/CallRepository.kt
Outdated
Show resolved
Hide resolved
…dao/ConnectionDAOImpl.kt Co-authored-by: Copilot <[email protected]>
…dao/conversation/ConversationDAOImpl.kt Co-authored-by: Copilot <[email protected]>
…-dispatchers' into mo/test/detecated-read-and-write-dispatchers
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.
Pull Request Overview
Copilot reviewed 34 out of 34 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
persistence/src/commonMain/kotlin/com/wire/kalium/persistence/dao/client/ClientDAOImpl.kt
Show resolved
Hide resolved
persistence/src/commonMain/kotlin/com/wire/kalium/persistence/dao/MetadataDAOImpl.kt
Outdated
Show resolved
Hide resolved
Code Review for PR #3681OverviewThis PR addresses ANR issues caused by SQLCipher connection pool exhaustion by introducing separate read and write dispatchers with limited parallelism (3 for reads, 1 for writes). This is a comprehensive refactoring of the persistence layer. Positive Changes1. Architecture - Strong Solution✅ Separate Read/Write Dispatchers: The introduction of
@JvmInline
value class ReadDispatcher(val value: CoroutineDispatcher)
@JvmInline
value class WriteDispatcher(val value: CoroutineDispatcher)2. Consistent Refactoring✅ All DAO implementations have been systematically updated to use the new dispatchers 3. Code Cleanup✅ Removal of unnecessary Critical Issues
|
28e8e46 to
eac052b
Compare
…read-and-write-dispatchers # Conflicts: # persistence/src/commonMain/kotlin/com/wire/kalium/persistence/dao/messageattachment/MessageAttachmentDraftDaoImpl.kt
…read-and-write-dispatchers # Conflicts: # persistence/src/commonMain/kotlin/com/wire/kalium/persistence/dao/message/draft/MessageDraftDAOImpl.kt
|



PR Submission Checklist for internal contributors
The PR Title
SQPIT-764The PR Description
What's new in this PR?
Issues
The application experiences ANR (Application Not Responding) due to SQLCipher connection pool exhaustion, where multiple concurrent database operations deadlock while waiting for available connections.
Causes (Optional)
sqldelight driver is a blocking driver
Solutions
create seperated dispatchers for read and writes with limitedParallelism 3 for reads and 1 for write this way only 4 threads max are blocked for execution while the rest are suspended
Dependencies (Optional)
If there are some other pull requests related to this one (e.g. new releases of frameworks), specify them here.
Needs releases with:
Testing
Test Coverage (Optional)
How to Test
Briefly describe how this change was tested and if applicable the exact steps taken to verify that it works as expected.
Notes (Optional)
Specify here any other facts that you think are important for this issue.
Attachments (Optional)
Attachments like images, videos, etc. (drag and drop in the text box)
PR Post Submission Checklist for internal contributors (Optional)
PR Post Merge Checklist for internal contributors
References
feat(conversation-list): Sort conversations by most emojis in the title #SQPIT-764.