-
Notifications
You must be signed in to change notification settings - Fork 522
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
dlock: solve the concurrency issues between discard and flatten #312
Conversation
2a31a30
to
0574f3f
Compare
recheck |
3a6e525
to
154bc76
Compare
recheck |
7a1df59
to
152ea61
Compare
@@ -231,6 +232,25 @@ int CloneServiceManager::Flatten( | |||
|
|||
auto cloneInfoMetric = std::make_shared<CloneInfoMetric>(taskId); | |||
auto closure = std::make_shared<CloneClosure>(); |
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.
not only Flatten has this bug, 'not lazy clone' also should fix.
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.
not only Flatten has this bug, 'not lazy clone' also should fix.
The file is invisible before not lazy clone task finished, so it will not meet with discard.
@@ -231,6 +232,25 @@ int CloneServiceManager::Flatten( | |||
|
|||
auto cloneInfoMetric = std::make_shared<CloneInfoMetric>(taskId); | |||
auto closure = std::make_shared<CloneClosure>(); | |||
|
|||
// init dlock | |||
if (!useMockDLock_) { |
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.
unit test like this test nothing, add some intergration test
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.
use gmock in test
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.
alread use MockDLock, but the dlock is inited in Flatten based on cloneInfo.destId
even if set the mockDlock, it will be overwritten here. so a judgment is needed here anymore.
have modified the code.
} | ||
} | ||
|
||
DLockGuard dlockGuard(dlock_); |
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.
missing lock on mds
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.
missing lock on mds
The dlock of discard on mds is in another pr latter.
src/common/concurrent/dlock.h
Outdated
std::string pfx; | ||
int retryTimes; | ||
// the interface timeout,unit is millisecond | ||
int timeout; |
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.
XX_timeoutMS?
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.
Unit included in the name
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.
Unit included in the name
done
src/common/concurrent/dlock.h
Outdated
// the interface timeout,unit is millisecond | ||
int timeout; | ||
// the session and lease timeout, unit is second | ||
int ttl; |
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.
like this: ttlSec
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.
like this: ttlSec
done
* | ||
* @return error code EtcdErrCode | ||
*/ | ||
// int TryLock(); |
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.
?
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.
?
EtcdMutexTryLock (not support at etcd v3.4)
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.
EtcdMutexTryLock (not support at etcd v3.4)
add comment
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.
also remark with //TODO
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.
done
* | ||
* @return error code EtcdErrCode | ||
*/ | ||
virtual int Unlock(); |
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.
why return value 'int' ?not same as 'virtual int64_t Init();'
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.
why return value 'int' ?not same as 'virtual int64_t Init();'
becase the "GetErrCode" in etcdclient.go is unit32 type, if return C.int64_t will get error below:
cannot use GetErrCode(EtcdLock, err) (type uint32) as type _Ctype_long in return argument
lock_->Lock(); | ||
} | ||
|
||
~DLockGuard() { |
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.
Do I have to manually call Release()?
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.
Do I have to manually call Release()?
yes.
after set dlock in task's closure,then Release, and Unlock in callback function
DLockGuard dlockGuard(dlock_);
closure->SetDLock(dlock_);
dlockGuard.Release();
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.
Does Releaese() used to avoid repeated destruction?
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.
Does Releaese() used to avoid repeated destruction?
the Release() is used to not destructed and give the unlock to task callback
~DLockGuard() {
if (!release_) {
lock_->Unlock();
}
}
return errCode; | ||
} | ||
|
||
// int DLock::TryLock() { |
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.
?
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.
?
EtcdMutexTryLock (not support at etcd v3.4)
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.
Remarks with //TODO
return GetErrCode(EtcdLock, err) | ||
} | ||
|
||
// //export EtcdMutexTryLock (not support at etcd v3.4) |
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.
why not delete?
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.
why not delete?
if use newer version etcd later, it can be used immediately
@@ -231,6 +232,25 @@ int CloneServiceManager::Flatten( | |||
|
|||
auto cloneInfoMetric = std::make_shared<CloneInfoMetric>(taskId); | |||
auto closure = std::make_shared<CloneClosure>(); | |||
|
|||
// init dlock | |||
if (!useMockDLock_) { |
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.
use gmock in test
|
||
DLockGuard dlockGuard(dlock_); | ||
closure->SetDLock(dlock_); | ||
dlockGuard.Release(); |
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.
do nothing after lock?
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.
do nothing after lock?
unlock fater task finished in task Run()
@@ -362,6 +366,12 @@ class CloneServiceManager { | |||
*/ | |||
virtual int RecoverCloneTask(); | |||
|
|||
// for test | |||
void SetDLock(std::shared_ptr<DLock> dlock) { |
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.
not just for test
use in src/snapshotcloneserver/clone/clone_service_manager.h
8230201
to
ec9de0d
Compare
return errCode; | ||
} | ||
|
||
// int DLock::TryLock() { |
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.
Remarks with //TODO
* | ||
* @return error code EtcdErrCode | ||
*/ | ||
// int TryLock(); |
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.
also remark with //TODO
lock_->Lock(); | ||
} | ||
|
||
~DLockGuard() { |
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.
Does Releaese() used to avoid repeated destruction?
ec9de0d
to
e2024e9
Compare
e2024e9
to
911acd7
Compare
Fixed typo in README
…flatten
What problem does this PR solve?
Issue Number: close #xxx
Problem Summary:
What is changed and how it works?
What's Changed:
How it Works:
Side effects(Breaking backward compatibility? Performance regression?):
Check List