Skip to content
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

fix(datastore): change OutgoingMutationQueue use TaskQueue for state transitions #3720

Merged
merged 2 commits into from
May 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@ final class OutgoingMutationQueue: OutgoingMutationQueueBehavior {
private let operationQueue: OperationQueue

/// A DispatchQueue for synchronizing state on the mutation queue
private let mutationDispatchQueue = DispatchQueue(
label: "com.amazonaws.OutgoingMutationQueue",
target: DispatchQueue.global()
)
private let mutationDispatchQueue = TaskQueue<Void>()

private weak var api: APICategoryGraphQLBehaviorExtended?
private weak var reconciliationQueue: IncomingEventReconciliationQueue?
Expand All @@ -55,7 +52,7 @@ final class OutgoingMutationQueue: OutgoingMutationQueueBehavior {

let operationQueue = OperationQueue()
operationQueue.name = "com.amazonaws.OutgoingMutationOperationQueue"
operationQueue.underlyingQueue = mutationDispatchQueue
operationQueue.qualityOfService = .default
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think the default is .default so no need to set this

Copy link
Member Author

@5d 5d May 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the doc, the default value for the OperationQueue is NSOperationQualityOfServiceBackground. I set it to the .default because DispatchQueue.global() uses a default quality of service (qos = .default).

For queues you create yourself, the default value is NSOperationQualityOfServiceBackground. For the queue returned by the main method, the default value is NSOperationQualityOfServiceUserInteractive and cannot be changed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, got it, thanks

operationQueue.maxConcurrentOperationCount = 1
operationQueue.isSuspended = true

Expand Down Expand Up @@ -139,6 +136,10 @@ final class OutgoingMutationQueue: OutgoingMutationQueueBehavior {

queryMutationEventsFromStorage { [weak self] in
guard let self = self else { return }
guard case .starting = self.stateMachine.state else {
self.log.debug("Unexpected state transition while performing `doStart()` during `.starting` state. Current state: \(self.stateMachine.state).")
return
}

self.operationQueue.isSuspended = false
// State machine notification to ".receivedSubscription" will be handled in `receive(subscription:)`
Expand Down
Loading