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: use unique_ptr #11837

Merged
merged 3 commits into from Nov 15, 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
29 changes: 12 additions & 17 deletions src/client/Client.cc
Expand Up @@ -247,7 +247,7 @@ Client::Client(Messenger *m, MonClient *mc)
objecter_finisher(m->cct),
tick_event(NULL),
monclient(mc), messenger(m), whoami(mc->get_global_id()),
cap_epoch_barrier(0), fsmap(nullptr), fsmap_user(nullptr),
cap_epoch_barrier(0),
last_tid(0), oldest_tid(0), last_flush_tid(1),
initialized(false), authenticated(false),
mounted(false), unmounting(false),
Expand Down Expand Up @@ -283,7 +283,7 @@ Client::Client(Messenger *m, MonClient *mc)
messenger = m;

// osd interfaces
mdsmap = new MDSMap;
mdsmap.reset(new MDSMap);
objecter = new Objecter(cct, messenger, monclient, NULL,
0, 0);
objecter->set_client_incarnation(0); // client always 0, for now.
Expand Down Expand Up @@ -314,8 +314,6 @@ Client::~Client()

delete filer;
delete objecter;
delete mdsmap;
delete fsmap;

delete logger;
}
Expand Down Expand Up @@ -2513,9 +2511,7 @@ bool Client::ms_dispatch(Message *m)

void Client::handle_fs_map(MFSMap *m)
{
delete fsmap;
fsmap = new FSMap;
*fsmap = m->get_fsmap();
fsmap.reset(new FSMap(m->get_fsmap()));
m->put();

signal_cond_list(waiting_for_fsmap);
Expand All @@ -2525,8 +2521,7 @@ void Client::handle_fs_map(MFSMap *m)

void Client::handle_fs_map_user(MFSMapUser *m)
{
delete fsmap_user;
fsmap_user = new FSMapUser;
fsmap_user.reset(new FSMapUser);
*fsmap_user = m->get_fsmap();
m->put();

Expand All @@ -2546,8 +2541,9 @@ void Client::handle_mds_map(MMDSMap* m)

ldout(cct, 1) << "handle_mds_map epoch " << m->get_epoch() << dendl;

MDSMap *oldmap = mdsmap;
mdsmap = new MDSMap;
std::unique_ptr<MDSMap> oldmap(new MDSMap);
oldmap.swap(mdsmap);

mdsmap->decode(m->get_encoded());

// Cancel any commands for missing or laggy GIDs
Expand Down Expand Up @@ -2619,7 +2615,6 @@ void Client::handle_mds_map(MMDSMap* m)
// kick any waiting threads
signal_cond_list(waiting_for_mdsmap);

delete oldmap;
m->put();

monclient->sub_got("mdsmap", mdsmap->get_epoch());
Expand Down Expand Up @@ -5338,7 +5333,7 @@ int Client::resolve_mds(
const std::string &mds_spec,
std::vector<mds_gid_t> *targets)
{
assert(fsmap != nullptr);
assert(fsmap);
assert(targets != nullptr);

mds_role_t role;
Expand Down Expand Up @@ -5446,20 +5441,20 @@ int Client::fetch_fsmap(bool user)
ldout(cct, 10) << __func__ << " learned FSMap version " << fsmap_latest << dendl;

if (user) {
if (fsmap_user == nullptr || fsmap_user->get_epoch() < fsmap_latest) {
if (!fsmap_user || fsmap_user->get_epoch() < fsmap_latest) {
monclient->sub_want("fsmap.user", fsmap_latest, CEPH_SUBSCRIBE_ONETIME);
monclient->renew_subs();
wait_on_list(waiting_for_fsmap);
}
assert(fsmap_user != nullptr);
assert(fsmap_user);
assert(fsmap_user->get_epoch() >= fsmap_latest);
} else {
if (fsmap == nullptr || fsmap->get_epoch() < fsmap_latest) {
if (!fsmap || fsmap->get_epoch() < fsmap_latest) {
monclient->sub_want("fsmap", fsmap_latest, CEPH_SUBSCRIBE_ONETIME);
monclient->renew_subs();
wait_on_list(waiting_for_fsmap);
}
assert(fsmap != nullptr);
assert(fsmap);
assert(fsmap->get_epoch() >= fsmap_latest);
}
ldout(cct, 10) << __func__ << " finished waiting for FSMap version "
Expand Down
6 changes: 3 additions & 3 deletions src/client/Client.h
Expand Up @@ -264,7 +264,7 @@ class Client : public Dispatcher, public md_config_obs_t {
CommandHook m_command_hook;

// cluster descriptors
MDSMap *mdsmap;
std::unique_ptr<MDSMap> mdsmap;

SafeTimer timer;

Expand Down Expand Up @@ -320,8 +320,8 @@ class Client : public Dispatcher, public md_config_obs_t {

// FSMap, for when using mds_command
list<Cond*> waiting_for_fsmap;
FSMap *fsmap;
FSMapUser *fsmap_user;
std::unique_ptr<FSMap> fsmap;
std::unique_ptr<FSMapUser> fsmap_user;

// MDS command state
CommandTable<MDSCommandOp> command_table;
Expand Down