-
Notifications
You must be signed in to change notification settings - Fork 472
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
Introduce MDel do the batch delete and use MultiLockGuard guarantee atomicity #1712
Conversation
…tomicity Previously, the DEL/UNLINK commands looped through each key to delete a single key. We need to change to batch delete (write), and also the original implementation did not lock the keys and will break atomicity. This PR introduces a new Mdel function, which uses MultiLockGuard to lock all the keys to guarantee atomicity, and use batch to do the final delete (write). Now it will be only used in DEL / UNLINKE commands. Noticed that our DEL / UNLINK test coverage was not sufficient, added some simple coverage tests to cover it. Fixes for DEL / UNLINK issues in 1692.
We may have the deadlock in ZSet::InterStore(as well as other similar APIs) if the dst key was inside the source key list since the OverWrite function will also lock the dst key: https://github.com/apache/kvrocks/blob/unstable/src/types/redis_zset.cc#L635 This issue was found by TSAN in CI: https://github.com/apache/kvrocks/actions/runs/6022265431/job/16338859035?pr=1712 |
@git-hulk Good point. |
I guess we should lock all the keys including the destination inside the |
Yes, I think it can resolve this issue. |
I submit another issue to track this since it's related but NOT introduced by this PR. #1715 |
Or can it be ok without locking the dst key? since we are doing a overwrite |
@enjoy-binbin I think we need to serialize write operations on the key to avoid "lost updates". However, you made me rethink the previous sentence because we deal with overwriting :) |
Is it possible to lock the dst key only and use the read snapshot like SDIFFSTORE/SINTERSTORE? |
@git-hulk can you describe this a bit more? (for example posting a pseudo code) |
Sure. For now, SDIFFSTORE is implemented in two steps:
Please refer https://github.com/apache/kvrocks/blob/unstable/src/types/redis_set.cc#L433 |
actually now we will lock the source keys. it was added in #1700, maybe we should remove the source keys locks?
edit: ohh, i think i got your point. maybe we should split InterStore to two function, one do the inter and the other one do the store, just like the Set apis. I wanted to do it (adding a ZINTER command) before, but because we already had a pending #1517 |
Great, thank you! |
i pushed a commit c51975b split InterStore to two function, one do the inter and the other one do the store, just like the Set apis. to see if the CI can pass |
CI TSAN show ZINTERSTORE may has a deadlock after introducing locks to DEL in apache#1712. In ZSet::InterStore if the dst key was inside the source key list we may have a deadlock since the OverWrite function will also lock the dst key. In this PR, we split Inter in ZSet::InterStore into a separate function, just like the Set apis. After this PR, after the CI verification in apache#1712, it can pass the CI verification now.
i see the CI is passed, so the split change can fix the deadlock, i am going to submit another PR to make the change, am revert the change in this PR (after we merge the new PR see #1726, we can re-merge it) |
lock-order-inversion found in TSan https://github.com/apache/kvrocks/actions/runs/6062050794/job/16447962572?pr=1712 |
CI TSAN show ZINTERSTORE may has a deadlock after introducing locks to DEL in #1712. In ZSet::InterStore if the dst key was inside the source key list we may have a deadlock since the OverWrite function will also lock the dst key. In this PR, we split Inter in ZSet::InterStore into a separate function, just like the Set apis. After this PR, after the CI verification in #1712, it can pass the CI verification now. Closes #1715 This PR also do a saved_cnt cleanup since it is same as members.size().
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.
General LGTM. Just some nits.
Co-authored-by: mwish <1506118561@qq.com>
Previously, the DEL/UNLINK commands looped through each key to
delete a single key. We need to change to batch delete (write),
and also the original implementation did not lock the keys and
will break atomicity.
This PR introduces a new Mdel function, which uses MultiLockGuard
to lock all the keys to guarantee atomicity, and use batch to do
the final delete (write).
Now it will be only used in DEL / UNLINKE commands. Noticed that
our DEL / UNLINK test coverage was not sufficient, added some simple
coverage tests to cover it.
Fixes for DEL / UNLINK issues in #1692.
unrelated change: in Exists for loop Get, return an execution error
when
!s.ok() && !s.IsNotFound()
without continuing the operation(because it will be some internal RocksDB error).