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

client: fix segment fault in SourceReader #358

Merged
merged 1 commit into from
May 24, 2021

Conversation

wu-hanqing
Copy link
Contributor

@wu-hanqing wu-hanqing commented May 19, 2021

What problem does this PR solve?

Problem Summary:

After #172 and #209, source volume data of the clone volume can be read within the client through SourceReader, and each source volume was also opened and represented by a FileInstance, but FileInstance::mdsclient_ points to FileClient::mdsClient_, so after FileClient is destroyed, FileInstance::mdsclient_ becomes dangling pointer.

What is changed and how it works?

What's Changed:

To fix this problem, we let FileClient::mdsClient_ be a shared_ptr, and each FileInstance holds ownership of it.

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

@wu-hanqing wu-hanqing force-pushed the fix/source-reader-segv branch 2 times, most recently from 75c0f8a to 5f04650 Compare May 19, 2021 07:29
struct LeaseRefreshResult;

// MDSClient是client与MDS通信的唯一窗口
class MDSClient {
class MDSClient : public MDSClientBase,
Copy link
Member

Choose a reason for hiding this comment

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

Why dose ‘MDSClient’ change to inherit from 'MDSClientBase' ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

After removing the option from MDSClientBase, it becomes an empty class. So if we define a member variable of class MDSClientBase, it at least occupies 1-byte memory. To avoid taking up extra space, inherit it is a good solution. Also, make MDSClient inherits from MDSClientBase has no bad effect.

@@ -100,7 +96,7 @@ class MDSClientBase {
* @param: metaServerOpt为mdsclient的配置信息
Copy link
Contributor

Choose a reason for hiding this comment

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

change the function description

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now, this function is useless, so I just delete it.

@@ -81,20 +63,28 @@ LIBCURVE_ERROR MDSClient::Initialize(const MetaServerOption& metaServerOpt) {

metaServerOpt_ = metaServerOpt;

int rc = mdsClientBase_.Init(metaServerOpt_);
int rc = MDSClientBase::Init();
Copy link
Contributor

Choose a reason for hiding this comment

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

MDSClientBase::Init() now is return 0 directly, Whether this judgment is needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fix

@@ -200,8 +201,7 @@ struct MDSClientMetric {
explicit MDSClientMetric(const std::string& prefix_ = "")
: prefix(!prefix_.empty()
? prefix_
: "curve_mds_client_" +
std::to_string(reinterpret_cast<uint64_t>(this))),
: "curve_mds_client_" + common::ToHexString(this)),
Copy link
Contributor

Choose a reason for hiding this comment

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

why change to hexString? give an example for prefix

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The prefix in here is just to distinguish different MDSClientMetric's instances because for a specific name, bvar only expose once. So, I just add the instance's address in the prefix, and change the address to hex string is more obvious.

After opencurve#172 and opencurve#209, source volume data of the clone volume
can be read within the client through SourceReader, and each
source volume was also opened and represented by a FileInstance,
but `FileInstance::mdsclient_` points to `FileClient::mdsClient_`,
so after FileClient is destroyed, `FileInstance::mdsclient_`
becomes dangling pointer.

To fix this problem, we let `FileClient::mdsClient_` be a shared_ptr,
and each FileInstance holds ownership of it.

Signed-off-by: Hanqing Wu <wuhanqing@corp.netease.com>
@xu-chaojie xu-chaojie merged commit fbefdb0 into opencurve:master May 24, 2021
@wu-hanqing wu-hanqing deleted the fix/source-reader-segv branch May 25, 2021 10:52
ilixiaocui pushed a commit to ilixiaocui/curve that referenced this pull request Feb 6, 2023
add k8s scheduler GSoC 2021 entry
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.

None yet

3 participants