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

Atomically downgrade lock when committing tx to prevent deadlock #1252

Merged
merged 2 commits into from
May 20, 2024

Conversation

coolreader18
Copy link
Collaborator

@coolreader18 coolreader18 commented May 17, 2024

Description of Changes

Also, move the logic with committing and taking the subscription lock into module_subscription_actor. Best reviewed ignoring whitespace.

before/after:
diagram

bfops pushed a commit that referenced this pull request May 18, 2024
…e lock when committing tx to prevent deadlock
@Shubham8287
Copy link
Contributor

Shubham8287 commented May 18, 2024

Ack it. Here is another visualisation focusing on main part

add_subcription:  begin_tx()                 subscription.write()
reducer1:      subscription.read()              begin_tx()
reducer2:                           begin_mut_tx()

So, the reducer 2 lock will not be acquired but It will block the queue (further reads) due to fairness.

@Shubham8287 Shubham8287 self-requested a review May 18, 2024 08:27
todo!("Write skew, you need to implement retries my man, T-dawg.");
}
}
Ok(Ok(())) => EventStatus::Committed(DatabaseUpdate::default()),
Copy link
Contributor

Choose a reason for hiding this comment

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

EventStatus::Commit name confused me while reveiwing, It may be better choice to name it EventStatus::YetToCommit or EventStatus::ReducerSuccess now

ctx: &ExecutionContext,
tx: MutTx,
) -> Result<Result<Arc<ModuleEvent>, WriteSkew>, DBError> {
let subscriptions = self.subscriptions.read();
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
let subscriptions = self.subscriptions.read();
// Take a read lock on `subscriptions` before committing tx
// else it can result in subscriber receiving duplicate updates.
let subscriptions = self.subscriptions.read();

Will prefer not to drop this comment.

}
}

pub struct WriteSkew;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I would recommend to use name WriteConflict because by defination WriteSkew anomoly is something transaction doesn't really detect while commiting unless transaction is tracking its reads.

@coolreader18 coolreader18 added this pull request to the merge queue May 20, 2024
Merged via the queue into master with commit f0c182e May 20, 2024
6 checks passed
@coolreader18 coolreader18 linked an issue May 20, 2024 that may be closed by this pull request
@coolreader18 coolreader18 deleted the noa/fix-deadlock branch May 21, 2024 00:45
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.

Mutable transactions should be downgradable
2 participants