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

dlock: solve the concurrency issues between discard and flatten #312

Merged
merged 1 commit into from
Apr 30, 2021

Conversation

SeanHai
Copy link
Contributor

@SeanHai SeanHai commented Apr 12, 2021

…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

  • Relevant documentation/comments is changed or added
  • I acknowledge that all my contributions will be made under the project's license

@SeanHai SeanHai changed the title dlock: add dlock to solve the concurrency issues between discard and … dlock: solve the concurrency issues between discard and flatten Apr 12, 2021
@SeanHai SeanHai force-pushed the curve_discard_flatten branch 2 times, most recently from 2a31a30 to 0574f3f Compare April 12, 2021 12:19
@SeanHai
Copy link
Contributor Author

SeanHai commented Apr 12, 2021

recheck

@SeanHai SeanHai force-pushed the curve_discard_flatten branch 7 times, most recently from 3a6e525 to 154bc76 Compare April 14, 2021 04:31
@SeanHai
Copy link
Contributor Author

SeanHai commented Apr 14, 2021

recheck

@SeanHai SeanHai force-pushed the curve_discard_flatten branch 6 times, most recently from 7a1df59 to 152ea61 Compare April 20, 2021 12:43
@@ -231,6 +232,25 @@ int CloneServiceManager::Flatten(

auto cloneInfoMetric = std::make_shared<CloneInfoMetric>(taskId);
auto closure = std::make_shared<CloneClosure>();
Copy link
Member

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.

Copy link
Contributor Author

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_) {
Copy link
Member

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use gmock in test

Copy link
Contributor Author

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_);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing lock on mds

Copy link
Contributor Author

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.

std::string pfx;
int retryTimes;
// the interface timeout,unit is millisecond
int timeout;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

XX_timeoutMS?

Copy link
Contributor

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

Copy link
Contributor Author

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

// the interface timeout,unit is millisecond
int timeout;
// the session and lease timeout, unit is second
int ttl;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

like this: ttlSec

Copy link
Contributor Author

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();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

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)

Copy link
Contributor Author

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also remark with //TODO

Copy link
Contributor Author

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();
Copy link
Contributor

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();'

Copy link
Contributor Author

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() {
Copy link
Contributor

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()?

Copy link
Contributor Author

@SeanHai SeanHai Apr 26, 2021

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();

Copy link
Contributor

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?

Copy link
Contributor Author

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() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

Copy link
Contributor Author

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)

Copy link
Contributor

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not delete?

Copy link
Contributor Author

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_) {
Copy link
Contributor

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();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do nothing after lock?

Copy link
Contributor Author

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) {
Copy link
Contributor

@ilixiaocui ilixiaocui Apr 26, 2021

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

@SeanHai SeanHai force-pushed the curve_discard_flatten branch 4 times, most recently from 8230201 to ec9de0d Compare April 27, 2021 11:17
return errCode;
}

// int DLock::TryLock() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remarks with //TODO

src/common/concurrent/dlock.cpp Show resolved Hide resolved
src/common/concurrent/dlock.cpp Show resolved Hide resolved
*
* @return error code EtcdErrCode
*/
// int TryLock();
Copy link
Contributor

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() {
Copy link
Contributor

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?

test/common/dlock_test.cpp Show resolved Hide resolved
@xu-chaojie xu-chaojie merged commit c75f32b into opencurve:master Apr 30, 2021
ilixiaocui pushed a commit to ilixiaocui/curve that referenced this pull request Feb 6, 2023
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.

3 participants