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

meta/rename: lock both src and dst parent for rename op to avoid txn conflicts and performance #5574

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

polyrabbit
Copy link
Contributor

Follow-up on #5549 - after uploading to a temporary file, gateway uses rename to move it to the target path. In current implementation, rename only locks parentSrc (in normal cases). #5549 adds an additional hierarchy to reduce conflicts on parentSrc, but conflicts still occur a lot on parentDst when user writes to the same directory concurrently.

So we should lock both parentSrc and parentDst in tkv/sql engines, in consistent with the redis engine.

… performance

Signed-off-by: Changxin Miao <miaochangxin@step.ai>
@anysql
Copy link
Contributor

anysql commented Jan 18, 2025

In txBatchLock there is problem, need to lock according to txLock id, not by inode.

Get a map of (inode % nlocks), and lock them in order.

By the way, we use optimistic lock for parent dir update in sql engine without holding the txLock to improve concurrency.

@polyrabbit
Copy link
Contributor Author

polyrabbit commented Jan 18, 2025

This PR already locks in order by lock_key(inode%nlocks), not by inode - there is a sort in the beginning. UT also has one case for this possibility.

By the way, we use optimistic lock for parent dir update in sql engine without holding the txLock to improve concurrency.

In tikv txn conflict is expensive, also the wait time caused by exponential backoff further reduces performance. It's better to resolve conflicts locally rather than remotely. I suppose the same rule applies to the sql engine?

Copy link

codecov bot commented Jan 19, 2025

Codecov Report

Attention: Patch coverage is 95.65217% with 1 line in your changes missing coverage. Please review.

Project coverage is 21.55%. Comparing base (c8e0516) to head (136c3ae).
Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
pkg/meta/sql.go 0.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main    #5574       +/-   ##
===========================================
- Coverage   50.60%   21.55%   -29.05%     
===========================================
  Files          30       29        -1     
  Lines       19809    19184      -625     
===========================================
- Hits        10025     4136     -5889     
- Misses       8348    14558     +6210     
+ Partials     1436      490      -946     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Signed-off-by: Changxin Miao <miaochangxin@step.ai>
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.

2 participants