Details
-
Sub-task
-
Status: Open
-
Major
-
Resolution: Unresolved
-
None
-
None
-
None
-
None
Description
Concurrent operations on directory tree may cause Quota updates and verification to not be thread-safe.
For example:
- Supposing there is directory /a/b and quota is on inode a and b
- There are some directories and files under /a/b, such as: /a/b/c/d1, /a/b/d/f1.txt
- Supposing there is a create operation under /a/b/c/d1 and there is a addBlock operation on /a/b/d/f1.txt
- These two operations can be handled concurrently by namenode
- They will update the quota on inode a concurrently since these operations just hold the read lock of the inode a and b.
- so we should make quota-related thread safe.
There are two solutions to make quota-related thread safe。
Solution one: Hold the write lock of the first iNode with Quota set when resolvePath
- Directly hold the write lock of iNode a so that all operations involving subtree /a can be handled safety.
- Due to lower concurrency, maximum improvements cannot be achieved.
- But the implementation is simple and straightforward.
Solution two: Lock all QuotaFeatures during quota verification or update
- Still hold the read lock of iNode a and b
- Lock all QuotaFeatures involved in this operations, when validating or updating quotas.
- Maximum improvements can be achieved.
- But the implementation is a little complex
- Add a lock for each QuotaFeature
- Acquire locks for all involving QuotaFeature