-
Notifications
You must be signed in to change notification settings - Fork 17
Core Data Concurrency update #151
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
Conversation
…rmAndWaitThrowing - Add NSManagedObjectContext extension to handle to capture any thrown error and return the result - Update public Repository methods to use backgroundContext.performAndWaitThrowing - Move fetch/delete logic into private _locked helper - Remove direct off-queue fetch/save calls to fix concurrency rule violations - Add doc comments
- Add NSManagedObjectContextExtensionTests - Expand BacktraceDatabaseTests to add concurrent read/write operations, maxRecordCount and retry count Tests
return result | ||
} | ||
|
||
// Swift 5 approach |
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.
swift 5 approach is cleaner
try backgroundContext.save() | ||
} | ||
// File storage outside the Core Data backgroundContext (optional concurrency). | ||
// TODO: Verify AttributesStorage for concurrency |
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.
Initial verification of AttributesStorage
did not reveal any issues.
result = Swift.Result(catching: block) | ||
} | ||
guard let outcome = result else { | ||
throw PerformAndWaitError.blockDidNotRun |
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.
edge case
} | ||
|
||
// concurrent reads | ||
for _ in 1...5 { |
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.
higher concurrent reads/writes take a lot of time.
Refactors PersistentRepository to safely perform Core Data operations.
Why?
When in concurrency debugging mode
-com.apple.CoreData.ConcurrencyDebug 1
; any direct call into the context methods from an unexpected thread or queue immediately triggers a concurrency violation.This requires that a private queue context
.privateQueueConcurrencyType
must be accessed exclusively through itsperform(_:)
orperformAndWait(_:)
methods, which schedule all reads/writes on its private serial queue.Changes:
ref: BT-5464