Skip to content

mds: add ref counting to LogSegment#62554

Merged
vshankar merged 1 commit intoceph:mainfrom
mchangir:mds-add-ref-counting-to-LogSegment
Jul 25, 2025
Merged

mds: add ref counting to LogSegment#62554
vshankar merged 1 commit intoceph:mainfrom
mchangir:mds-add-ref-counting-to-LogSegment

Conversation

@mchangir
Copy link
Contributor

@mchangir mchangir commented Mar 28, 2025

Fixes: https://tracker.ceph.com/issues/70723
Signed-off-by: Milind Changire mchangir@redhat.com

Contribution Guidelines

  • To sign and title your commits, please refer to Submitting Patches to Ceph.

  • If you are submitting a fix for a stable branch (e.g. "quincy"), please refer to Submitting Patches to Ceph - Backports for the proper workflow.

  • When filling out the below checklist, you may click boxes directly in the GitHub web UI. When entering or editing the entire PR message in the GitHub web UI editor, you may also select a checklist item by adding an x between the brackets: [x]. Spaces and capitalization matter when checking off items this way.

Checklist

  • Tracker (select at least one)
    • References tracker ticket
    • Very recent bug; references commit where it was introduced
    • New feature (ticket optional)
    • Doc update (no ticket needed)
    • Code cleanup (no ticket needed)
  • Component impact
    • Affects Dashboard, opened tracker ticket
    • Affects Orchestrator, opened tracker ticket
    • No impact that needs to be tracked
  • Documentation (select at least one)
    • Updates relevant documentation
    • No doc update is appropriate
  • Tests (select at least one)
Show available Jenkins commands

@github-actions github-actions bot added the cephfs Ceph File System label Mar 28, 2025
@mchangir mchangir force-pushed the mds-add-ref-counting-to-LogSegment branch 3 times, most recently from 59e5177 to 9751c70 Compare March 30, 2025 15:35
src/mds/MDLog.h Outdated
class LogSegment;
class ESubtreeMap;

using LogSegmentRef = boost::intrusive_ptr<LogSegment>;
Copy link
Contributor

Choose a reason for hiding this comment

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

Ugh.. where are intrusive_ptr_add_ref and intrusive_ptr_release implemented? o_O

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh I see, LogSegment is a subclass of RefCountedObject. Interesting.

src/mds/CDir.h Outdated
class MDCache;
class LogSegment;

using LogSegmentRef = boost::intrusive_ptr<LogSegment>;
Copy link
Contributor

Choose a reason for hiding this comment

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

Generally, using using keyword is discouraged in header files, especially when its done outside the scope of the class itself (CDir in this case).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll move all such instances inside the class definitions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  • rebased
  • moved using LogSegmentRef = inside class definitions

@mchangir mchangir force-pushed the mds-add-ref-counting-to-LogSegment branch from 9751c70 to 6f68417 Compare April 16, 2025 09:14
@github-actions
Copy link

This pull request can no longer be automatically merged: a rebase is needed and changes have to be manually resolved

@mchangir mchangir force-pushed the mds-add-ref-counting-to-LogSegment branch from 6f68417 to a862e7c Compare April 23, 2025 14:17
@mchangir mchangir force-pushed the mds-add-ref-counting-to-LogSegment branch from a862e7c to fffa4d9 Compare May 7, 2025 02:09
@mchangir
Copy link
Contributor Author

mchangir commented May 7, 2025

rebased

@mchangir mchangir force-pushed the mds-add-ref-counting-to-LogSegment branch from fffa4d9 to 4403702 Compare June 10, 2025 14:44
@mchangir
Copy link
Contributor Author

Note: PR has been revised completely

adjust_subtree_auth(mydir, mds->get_nodeid());

LogSegment *ls = mds->mdlog->get_current_segment();
std::shared_ptr<LogSegment> &ls = mds->mdlog->get_current_segment();
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
std::shared_ptr<LogSegment> &ls = mds->mdlog->get_current_segment();
auto&& ls = mds->mdlog->get_current_segment();

is more robust. I'd also like to see:

using LogSegmentRef = std::shared_ptr<LogSegment>;

in the headers.

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

Copy link
Contributor

Choose a reason for hiding this comment

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

OK, I had advised @mchangir to not use using keyword in headers. I see now, this is being done via a new header as per #62554 (comment)

Copy link
Contributor

Choose a reason for hiding this comment

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

So, it looks like using in header is fine iff it's a separate header and this header is only included in cc source, yes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Following are the headers in which LogSegmentRef.h is included:

src/mds/CDentry.h:#include "LogSegmentRef.h"
src/mds/CDir.h:#include "LogSegmentRef.h"
src/mds/CInode.h:#include "LogSegmentRef.h"
src/mds/LogEvent.h:#include "LogSegmentRef.h"
src/mds/MDCache.h:#include "LogSegmentRef.h"
src/mds/MDLog.h:#include "LogSegmentRef.h"
src/mds/MDSTableClient.h:#include "LogSegmentRef.h"
src/mds/Migrator.h:#include "LogSegmentRef.h"
src/mds/Mutation.h:#include "LogSegmentRef.h"
src/mds/Server.h:#include "LogSegmentRef.h"
src/mds/events/EMetaBlob.h:#include "../LogSegmentRef.h"

as class function prototypes also make a reference to LogSegmentRef ... otherwise the compiler will spew errors about undefined symbols.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

or, maybe include LogSegmentRef.h in the .cc before any other header included in the .cc makes a reference to LogSegmentRef ?

Copy link
Member

Choose a reason for hiding this comment

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

I think as long as you include LogSegmentRef.h in LogSegment.h, you can avoid explicitly including it in most of those .cc files. You only need the separate header for places where you do not want to include LogSegment.h for circular dependency reasons.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's not many files that both LogSegment.h and LogSegmentRef.h get included. Here's the list:

$ git grep -E 'LogSegment\.h'
src/mds/CDentry.cc:#include "LogSegment.h"
src/mds/CDir.cc:#include "LogSegment.h"
src/mds/CInode.cc:#include "LogSegment.h"
src/mds/MDLog.h:#include "LogSegment.h"
src/mds/MDSTableClient.cc:#include "LogSegment.h"
src/mds/SegmentBoundary.h:#include "LogSegment.h"
src/mds/events/EMetaBlob.h:#include "../LogSegment.h"
src/mds/journal.cc:#include "LogSegment.h"

$ git grep -E 'LogSegmentRef\.h'
src/mds/CDentry.h:#include "LogSegmentRef.h"
src/mds/CDir.h:#include "LogSegmentRef.h"
src/mds/CInode.h:#include "LogSegmentRef.h"
src/mds/LogEvent.h:#include "LogSegmentRef.h"
src/mds/MDCache.h:#include "LogSegmentRef.h"
src/mds/MDLog.h:#include "LogSegmentRef.h"
src/mds/MDSTableClient.h:#include "LogSegmentRef.h"
src/mds/Migrator.h:#include "LogSegmentRef.h"
src/mds/Mutation.h:#include "LogSegmentRef.h"
src/mds/Server.h:#include "LogSegmentRef.h"
src/mds/events/EMetaBlob.h:#include "../LogSegmentRef.h"
src/mds/journal.cc:#include "LogSegmentRef.h"

so the only common files among two lists are:

src/mds/MDLog.h
src/mds/events/EMetaBlob.h
src/mds/journal.cc

I've mostly included LogSegmentRef.h in files where there was no reference to LogSegment.h. I haven't tested what happens if I include LogSegmentRef.h via LogSegment.h.

@mchangir mchangir force-pushed the mds-add-ref-counting-to-LogSegment branch from 4403702 to 959d2e2 Compare June 11, 2025 17:47
Copy link
Member

@batrick batrick left a comment

Choose a reason for hiding this comment

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

otherwise LGTM

@mchangir mchangir force-pushed the mds-add-ref-counting-to-LogSegment branch from 959d2e2 to 3154072 Compare June 12, 2025 08:04
@mchangir mchangir requested a review from batrick June 12, 2025 08:07
*
*/

using LogSegmentRef = std::shared_ptr<LogSegment>;
Copy link
Member

Choose a reason for hiding this comment

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

Create a new header file mds/LogSegmentRef.h which is just:

<copyright>
#pragma once
class LogSegment;
using LogSegmentRef = std::shared_ptr<LogSegment>;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

should this header be included in all the files that has using LogSegmentRef = defined and replace this declaration ?

Copy link
Member

Choose a reason for hiding this comment

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

yes

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

Copy link
Member

Choose a reason for hiding this comment

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

@mchangir I think you forgot to stage the LogSegmentRef.h header.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks for taking a look ... I've now included LogSegmentRef.h in the commit.

@mchangir mchangir force-pushed the mds-add-ref-counting-to-LogSegment branch from 3154072 to a51b170 Compare June 13, 2025 04:05
@mchangir mchangir requested a review from batrick June 13, 2025 04:07
Fixes: https://tracker.ceph.com/issues/70723
Signed-off-by: Milind Changire <mchangir@redhat.com>
@mchangir mchangir force-pushed the mds-add-ref-counting-to-LogSegment branch from a51b170 to fe3b415 Compare July 8, 2025 00:52
@vshankar
Copy link
Contributor

This PR is under test in https://tracker.ceph.com/issues/72210.

Copy link
Contributor

@vshankar vshankar left a comment

Choose a reason for hiding this comment

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

@vshankar vshankar merged commit 742cb59 into ceph:main Jul 25, 2025
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cephfs Ceph File System needs-qa

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants