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

mds: use unique_ptr to simplify resource mgmt #11543

Merged
merged 1 commit into from
Oct 20, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 5 additions & 14 deletions src/mds/CDir.cc
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@ CDir::CDir(CInode *in, frag_t fg, MDCache *mdcache, bool auth) :
first(2),
dirty_rstat_inodes(member_offset(CInode, dirty_rstat_item)),
projected_version(0), item_dirty(this), item_new(this),
scrub_infop(NULL),
num_head_items(0), num_head_null(0),
num_snap_items(0), num_snap_null(0),
num_dirty(0), committing_version(0), committed_version(0),
Copy link
Contributor

Choose a reason for hiding this comment

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

bloom(null) is redundant

Expand All @@ -195,7 +194,6 @@ CDir::CDir(CInode *in, frag_t fg, MDCache *mdcache, bool auth) :
pop_auth_subtree_nested(ceph_clock_now(g_ceph_context)),
num_dentries_nested(0), num_dentries_auth_subtree(0),
num_dentries_auth_subtree_nested(0),
bloom(NULL),
dir_auth(CDIR_AUTH_DEFAULT)
{
g_num_dir++;
Expand Down Expand Up @@ -639,7 +637,7 @@ void CDir::add_to_bloom(CDentry *dn)
return;
unsigned size = get_num_head_items() + get_num_snap_items();
if (size < 100) size = 100;
bloom = new bloom_filter(size, 1.0 / size, 0);
bloom.reset(new bloom_filter(size, 1.0 / size, 0));
}
/* This size and false positive probability is completely random.*/
bloom->insert(dn->name.c_str(), dn->name.size());
Expand All @@ -652,12 +650,6 @@ bool CDir::is_in_bloom(const string& name)
return bloom->contains(name.c_str(), name.size());
}

void CDir::remove_bloom()
{
delete bloom;
bloom = NULL;
}

void CDir::remove_null_dentries() {
dout(12) << "remove_null_dentries " << *this << dendl;

Expand Down Expand Up @@ -1379,7 +1371,7 @@ void CDir::log_mark_dirty()

void CDir::mark_complete() {
state_set(STATE_COMPLETE);
remove_bloom();
bloom.reset();
}

void CDir::first_get()
Expand Down Expand Up @@ -2915,7 +2907,7 @@ void CDir::scrub_info_create() const
CDir *me = const_cast<CDir*>(this);
fnode_t *fn = me->get_projected_fnode();

scrub_info_t *si = new scrub_info_t();
std::unique_ptr<scrub_info_t> si(new scrub_info_t());

si->last_recursive.version = si->recursive_start.version =
fn->recursive_scrub_version;
Expand All @@ -2925,7 +2917,7 @@ void CDir::scrub_info_create() const
si->last_local.version = fn->localized_scrub_version;
si->last_local.time = fn->localized_scrub_stamp;

me->scrub_infop = si;
me->scrub_infop.swap(si);
}

void CDir::scrub_initialize(const ScrubHeaderRefConst& header)
Expand Down Expand Up @@ -3108,8 +3100,7 @@ void CDir::scrub_maybe_delete_info()
!scrub_infop->last_scrub_dirty &&
!scrub_infop->pending_scrub_error &&
scrub_infop->dirty_scrub_stamps.empty()) {
delete scrub_infop;
scrub_infop = NULL;
scrub_infop.reset();
}
}

Expand Down
14 changes: 7 additions & 7 deletions src/mds/CDir.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "include/types.h"
#include "include/buffer_fwd.h"
#include "mdstypes.h"
#include "common/bloom_filter.hpp"
#include "common/config.h"
#include "common/DecayCounter.h"

Expand All @@ -35,7 +36,6 @@

class CDentry;
class MDCache;
class bloom_filter;

struct ObjectOperation;

Expand Down Expand Up @@ -338,7 +338,7 @@ class CDir : public MDSCacheObject {


protected:
scrub_info_t *scrub_infop;
std::unique_ptr<scrub_info_t> scrub_infop;

// contents of this directory
map_t items; // non-null AND null
Expand Down Expand Up @@ -395,15 +395,13 @@ class CDir : public MDSCacheObject {
friend class C_IO_Dir_OMAP_Fetched;
friend class C_IO_Dir_Committed;

bloom_filter *bloom;
std::unique_ptr<bloom_filter> bloom;
/* If you set up the bloom filter, you must keep it accurate!
* It's deleted when you mark_complete() and is deliberately not serialized.*/

public:
CDir(CInode *in, frag_t fg, MDCache *mdcache, bool auth);
~CDir() {
delete scrub_infop;
remove_bloom();
g_num_dir--;
g_num_dirs++;
}
Expand All @@ -412,7 +410,7 @@ class CDir : public MDSCacheObject {
if (!scrub_infop) {
scrub_info_create();
}
return scrub_infop;
return scrub_infop.get();
}


Expand Down Expand Up @@ -471,7 +469,9 @@ class CDir : public MDSCacheObject {
void add_to_bloom(CDentry *dn);
bool is_in_bloom(const std::string& name);
bool has_bloom() { return (bloom ? true : false); }
void remove_bloom();
void remove_bloom() {
bloom.reset();
}
private:
void link_inode_work( CDentry *dn, CInode *in );
void unlink_inode_work( CDentry *dn );
Expand Down