-
Notifications
You must be signed in to change notification settings - Fork 3
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
Take two triples in atomic way #64
Take two triples in atomic way #64
Conversation
Why not use |
@ChaoticTempest atomic and transaction do not allow us to have conditional logic, return errors, etc. |
From what I see, Lua scripts are the only thing we can use to make all these operations in a completely isolated way. |
I took a look at benchmarks and Lua scripts actually don't have a huge performance impact (around +4-5%) but that's fine in the grand scheme of things |
id0: &TripleId, | ||
id1: &TripleId, |
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.
TripleId
implements Copy
so no need to pass by reference. It's also cheaper to pass it by value than reference here too since pointers are fat (i.e. 8 bytes in 64bit systems)
@@ -54,20 +54,88 @@ impl TripleStorage { | |||
Ok(result) | |||
} | |||
|
|||
pub async fn take(&self, id: &TripleId) -> StoreResult<Triple> { | |||
pub async fn take_two(&self, id1: &TripleId, id2: &TripleId) -> StoreResult<(Triple, Triple)> { |
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.
same with this one
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.
Looks good!
Making all operations atomic prevents race conditions, especially in multithreaded and multi-node design. It also decreases the number of Redis calls and simplifies the code, although we lose some error types.
I plan to adopt this approach in other places if we stick with it.