Merge pull request #12276 from kylinstorage/wip-cleanup-makeshared

cleanup: use std::make_shared to replace new

Reviewed-by: John Spray <john.spray@redhat.com>
This commit is contained in:
John Spray 2017-01-06 13:11:03 +00:00 committed by GitHub
commit a7b0b1f37d
22 changed files with 58 additions and 58 deletions

View File

@ -562,7 +562,7 @@ int main(int argc, const char **argv)
::encode(v, final);
::encode(mapbl, final);
MonitorDBStore::TransactionRef t(new MonitorDBStore::Transaction);
auto t(std::make_shared<MonitorDBStore::Transaction>());
// save it
t->put("monmap", v, mapbl);
t->put("monmap", "latest", final);

View File

@ -197,7 +197,7 @@ void LogChannel::update_config(map<string,string> &log_to_monitors,
set_log_prio(prio);
if (to_graylog && !graylog) { /* should but isn't */
graylog = ceph::logging::Graylog::Ref(new ceph::logging::Graylog("clog"));
graylog = std::make_shared<ceph::logging::Graylog>("clog");
} else if (!to_graylog && graylog) { /* shouldn't but is */
graylog.reset();
}

View File

@ -219,7 +219,7 @@ public:
if (channels.count(name))
c = channels[name];
else {
c = LogChannelRef(new LogChannel(cct, this, name));
c = std::make_shared<LogChannel>(cct, this, name);
channels[name] = c;
}
return c;

View File

@ -43,7 +43,7 @@ public:
isal = false;
}
if (compressor == 0 || has_isal != isal) {
compressor = CompressorRef(new ZlibCompressor(isal));
compressor = std::make_shared<ZlibCompressor>(isal);
has_isal = isal;
}
*cs = compressor;

View File

@ -191,7 +191,7 @@ void Log::start_graylog()
{
pthread_mutex_lock(&m_flush_mutex);
if (! m_graylog.get())
m_graylog = Graylog::Ref(new Graylog(m_subs, "dlog"));
m_graylog = std::make_shared<Graylog>(m_subs, "dlog");
pthread_mutex_unlock(&m_flush_mutex);
}

View File

@ -1890,7 +1890,7 @@ void CInode::finish_scatter_update(ScatterLock *lock, CDir *dir,
dout(10) << "finish_scatter_update " << fg << " journaling accounted scatterstat update v" << inode_version << dendl;
MDLog *mdlog = mdcache->mds->mdlog;
MutationRef mut(new MutationImpl);
auto mut(std::make_shared<MutationImpl>());
mut->ls = mdlog->get_current_segment();
inode_t *pi = get_projected_inode();

View File

@ -2261,7 +2261,7 @@ bool Locker::check_inode_max_size(CInode *in, bool force_wrlock,
}
}
MutationRef mut(new MutationImpl);
auto mut(std::make_shared<MutationImpl>());
mut->ls = mds->mdlog->get_current_segment();
inode_t *pi = in->project_inode();
@ -2925,7 +2925,7 @@ void Locker::_do_snap_update(CInode *in, snapid_t snap, int dirty, snapid_t foll
EUpdate *le = new EUpdate(mds->mdlog, "snap flush");
mds->mdlog->start_entry(le);
MutationRef mut(new MutationImpl);
auto mut(std::make_shared<MutationImpl>());
mut->ls = mds->mdlog->get_current_segment();
// normal metadata updates that we can apply to the head as well.
@ -3220,7 +3220,7 @@ bool Locker::_do_cap_update(CInode *in, Capability *cap,
inode_t *pi = in->project_inode(px);
pi->version = in->pre_dirty();
MutationRef mut(new MutationImpl);
auto mut(std::make_shared<MutationImpl>());
mut->ls = mds->mdlog->get_current_segment();
_update_cap_fields(in, dirty, m, pi);
@ -4225,7 +4225,7 @@ void Locker::scatter_writebehind(ScatterLock *lock)
dout(10) << "scatter_writebehind " << in->inode.mtime << " on " << *lock << " on " << *in << dendl;
// journal
MutationRef mut(new MutationImpl);
auto mut(std::make_shared<MutationImpl>());
mut->ls = mds->mdlog->get_current_segment();
// forcefully take a wrlock

View File

@ -515,7 +515,7 @@ void MDCache::_create_system_file(CDir *dir, const char *name, CInode *in, MDSIn
SnapRealm *realm = dir->get_inode()->find_snaprealm();
dn->first = in->first = realm->get_newest_seq() + 1;
MutationRef mut(new MutationImpl);
auto mut(std::make_shared<MutationImpl>());
// force some locks. hacky.
mds->locker->wrlock_force(&dir->inode->filelock, mut);
@ -964,7 +964,7 @@ void MDCache::try_subtree_merge_at(CDir *dir, bool do_eval)
inode_t *pi = in->project_inode();
pi->version = in->pre_dirty();
MutationRef mut(new MutationImpl);
auto mut(std::make_shared<MutationImpl>());
mut->ls = mds->mdlog->get_current_segment();
EUpdate *le = new EUpdate(mds->mdlog, "subtree merge writebehind");
mds->mdlog->start_entry(le);
@ -6073,7 +6073,7 @@ void MDCache::queue_file_recover(CInode *in)
inode_t *pi = in->project_inode();
pi->version = in->pre_dirty();
MutationRef mut(new MutationImpl);
auto mut(std::make_shared<MutationImpl>());
mut->ls = mds->mdlog->get_current_segment();
EUpdate *le = new EUpdate(mds->mdlog, "queue_file_recover cow");
mds->mdlog->start_entry(le);
@ -6286,7 +6286,7 @@ void MDCache::truncate_inode_finish(CInode *in, LogSegment *ls)
pi->truncate_from = 0;
pi->truncate_pending--;
MutationRef mut(new MutationImpl);
auto mut(std::make_shared<MutationImpl>());
mut->ls = mds->mdlog->get_current_segment();
mut->add_projected_inode(in);
@ -9198,7 +9198,7 @@ void MDCache::snaprealm_create(MDRequestRef& mdr, CInode *in)
return;
}
MutationRef mut(new MutationImpl);
auto mut(std::make_shared<MutationImpl>());
mut->ls = mds->mdlog->get_current_segment();
EUpdate *le = new EUpdate(mds->mdlog, "snaprealm_create");
mds->mdlog->start_entry(le);

View File

@ -958,7 +958,7 @@ void Migrator::export_frozen(CDir *dir, uint64_t tid)
return;
}
it->second.mut = MutationRef(new MutationImpl);
it->second.mut = std::make_shared<MutationImpl>();
if (diri->is_auth())
it->second.mut->auth_pin(diri);
mds->locker->rdlock_take_set(rdlocks, it->second.mut);
@ -2166,7 +2166,7 @@ void Migrator::handle_export_prep(MExportDirPrep *m)
if (!mds->mdcache->is_readonly() &&
dir->get_inode()->filelock.can_wrlock(-1) &&
dir->get_inode()->nestlock.can_wrlock(-1)) {
it->second.mut = MutationRef(new MutationImpl);
it->second.mut = std::make_shared<MutationImpl>();
// force some locks. hacky.
mds->locker->wrlock_force(&dir->inode->filelock, it->second.mut);
mds->locker->wrlock_force(&dir->inode->nestlock, it->second.mut);

View File

@ -5334,7 +5334,7 @@ void Server::do_link_rollback(bufferlist &rbl, mds_rank_t master, MDRequestRef&
mdcache->add_rollback(rollback.reqid, master); // need to finish this update before resolve finishes
assert(mdr || mds->is_resolve());
MutationRef mut(new MutationImpl(rollback.reqid));
auto mut(std::make_shared<MutationImpl>(rollback.reqid));
mut->ls = mds->mdlog->get_current_segment();
CInode *in = mdcache->get_inode(rollback.ino);
@ -7586,7 +7586,7 @@ void Server::do_rename_rollback(bufferlist &rbl, mds_rank_t master, MDRequestRef
// need to finish this update before sending resolve to claim the subtree
mdcache->add_rollback(rollback.reqid, master);
MutationRef mut(new MutationImpl(rollback.reqid));
auto mut(std::make_shared<MutationImpl>(rollback.reqid));
mut->ls = mds->mdlog->get_current_segment();
CDentry *srcdn = NULL;

View File

@ -188,7 +188,7 @@ void AuthMonitor::update_from_paxos(bool *need_bootstrap)
mon->key_server.set_ver(keys_ver);
if (keys_ver == 1 && mon->is_keyring_required()) {
MonitorDBStore::TransactionRef t(new MonitorDBStore::Transaction);
auto t(std::make_shared<MonitorDBStore::Transaction>());
t->erase("mkfs", "keyring");
mon->store->apply_transaction(t);
}

View File

@ -51,7 +51,7 @@ void Elector::bump_epoch(epoch_t e)
dout(10) << "bump_epoch " << epoch << " to " << e << dendl;
assert(epoch <= e);
epoch = e;
MonitorDBStore::TransactionRef t(new MonitorDBStore::Transaction);
auto t(std::make_shared<MonitorDBStore::Transaction>());
t->put(Monitor::MONITOR_NAME, "election_epoch", epoch);
mon->store->apply_transaction(t);
@ -79,7 +79,7 @@ void Elector::start()
bump_epoch(epoch+1); // odd == election cycle
} else {
// do a trivial db write just to ensure it is writeable.
MonitorDBStore::TransactionRef t(new MonitorDBStore::Transaction);
auto t(std::make_shared<MonitorDBStore::Transaction>());
t->put(Monitor::MONITOR_NAME, "election_writeable_test", rand());
int r = mon->store->apply_transaction(t);
assert(r >= 0);
@ -491,7 +491,7 @@ void Elector::dispatch(MonOpRequestRef op)
<< ", taking it"
<< dendl;
mon->monmap->decode(em->monmap_bl);
MonitorDBStore::TransactionRef t(new MonitorDBStore::Transaction);
auto t(std::make_shared<MonitorDBStore::Transaction>());
t->put("monmap", mon->monmap->epoch, em->monmap_bl);
t->put("monmap", "last_committed", mon->monmap->epoch);
mon->store->apply_transaction(t);

View File

@ -730,7 +730,7 @@ ceph::logging::Graylog::Ref LogMonitor::log_channel_info::get_graylog(
<< channel << "'" << dendl;
if (graylogs.count(channel) == 0) {
ceph::logging::Graylog::Ref graylog = ceph::logging::Graylog::Ref(new ceph::logging::Graylog("mon"));
auto graylog(std::make_shared<ceph::logging::Graylog>("mon"));
graylog->set_fsid(g_conf->fsid);
graylog->set_hostname(g_conf->host);

View File

@ -533,7 +533,7 @@ void Monitor::read_features_off_disk(MonitorDBStore *store, CompatSet *features)
*features = get_legacy_features();
features->encode(featuresbl);
MonitorDBStore::TransactionRef t(new MonitorDBStore::Transaction);
auto t(std::make_shared<MonitorDBStore::Transaction>());
t->put(MONITOR_NAME, COMPAT_SET_LOC, featuresbl);
store->apply_transaction(t);
} else {
@ -1332,7 +1332,7 @@ void Monitor::sync_start(entity_inst_t &other, bool full)
if (sync_full) {
// stash key state, and mark that we are syncing
MonitorDBStore::TransactionRef t(new MonitorDBStore::Transaction);
auto t(std::make_shared<MonitorDBStore::Transaction>());
sync_stash_critical_state(t);
t->put("mon_sync", "in_sync", 1);
@ -1396,7 +1396,7 @@ void Monitor::sync_finish(version_t last_committed)
if (sync_full) {
// finalize the paxos commits
MonitorDBStore::TransactionRef tx(new MonitorDBStore::Transaction);
auto tx(std::make_shared<MonitorDBStore::Transaction>());
paxos->read_and_prepare_transactions(tx, sync_start_version,
last_committed);
tx->put(paxos->get_name(), "last_committed", last_committed);
@ -1412,7 +1412,7 @@ void Monitor::sync_finish(version_t last_committed)
assert(g_conf->mon_sync_requester_kill_at != 8);
MonitorDBStore::TransactionRef t(new MonitorDBStore::Transaction);
auto t(std::make_shared<MonitorDBStore::Transaction>());
t->erase("mon_sync", "in_sync");
t->erase("mon_sync", "force_sync");
t->erase("mon_sync", "last_committed_floor");
@ -1551,7 +1551,7 @@ void Monitor::handle_sync_get_chunk(MonOpRequestRef op)
}
MMonSync *reply = new MMonSync(MMonSync::OP_CHUNK, sp.cookie);
MonitorDBStore::TransactionRef tx(new MonitorDBStore::Transaction);
auto tx(std::make_shared<MonitorDBStore::Transaction>());
int left = g_conf->mon_sync_max_payload_size;
while (sp.last_committed < paxos->get_version() && left > 0) {
@ -1645,7 +1645,7 @@ void Monitor::handle_sync_chunk(MonOpRequestRef op)
assert(state == STATE_SYNCHRONIZING);
assert(g_conf->mon_sync_requester_kill_at != 5);
MonitorDBStore::TransactionRef tx(new MonitorDBStore::Transaction);
auto tx(std::make_shared<MonitorDBStore::Transaction>());
tx->append_from_encoded(m->chunk_bl);
dout(30) << __func__ << " tx dump:\n";
@ -1660,7 +1660,7 @@ void Monitor::handle_sync_chunk(MonOpRequestRef op)
if (!sync_full) {
dout(10) << __func__ << " applying recent paxos transactions as we go" << dendl;
MonitorDBStore::TransactionRef tx(new MonitorDBStore::Transaction);
auto tx(std::make_shared<MonitorDBStore::Transaction>());
paxos->read_and_prepare_transactions(tx, paxos->get_version() + 1,
m->last_committed);
tx->put(paxos->get_name(), "last_committed", m->last_committed);
@ -2226,7 +2226,7 @@ void Monitor::sync_force(Formatter *f, ostream& ss)
free_formatter = true;
}
MonitorDBStore::TransactionRef tx(new MonitorDBStore::Transaction);
auto tx(std::make_shared<MonitorDBStore::Transaction>());
sync_stash_critical_state(tx);
tx->put("mon_sync", "force_sync", 1);
store->apply_transaction(tx);
@ -5163,7 +5163,7 @@ int Monitor::check_fsid()
int Monitor::write_fsid()
{
MonitorDBStore::TransactionRef t(new MonitorDBStore::Transaction);
auto t(std::make_shared<MonitorDBStore::Transaction>());
write_fsid(t);
int r = store->apply_transaction(t);
return r;
@ -5188,7 +5188,7 @@ int Monitor::write_fsid(MonitorDBStore::TransactionRef t)
*/
int Monitor::mkfs(bufferlist& osdmapbl)
{
MonitorDBStore::TransactionRef t(new MonitorDBStore::Transaction);
auto t(std::make_shared<MonitorDBStore::Transaction>());
// verify cluster fsid
int r = check_fsid();

View File

@ -186,7 +186,7 @@ class MonitorDBStore
}
void append_from_encoded(bufferlist& bl) {
TransactionRef other(new Transaction);
auto other(std::make_shared<Transaction>());
bufferlist::iterator it = bl.begin();
other->decode(it);
append(other);
@ -376,7 +376,7 @@ class MonitorDBStore
string &key,
bufferlist &value,
uint64_t max) {
TransactionRef tmp(new Transaction);
auto tmp(std::make_shared<Transaction>());
bufferlist tmp_bl;
tmp->put(prefix, key, value);
tmp->encode(tmp_bl);

View File

@ -66,7 +66,7 @@ void MonmapMonitor::update_from_paxos(bool *need_bootstrap)
mon->monmap->decode(monmap_bl);
if (mon->store->exists("mkfs", "monmap")) {
MonitorDBStore::TransactionRef t(new MonitorDBStore::Transaction);
auto t(std::make_shared<MonitorDBStore::Transaction>());
t->erase("mkfs", "monmap");
mon->store->apply_transaction(t);
}
@ -161,7 +161,7 @@ void MonmapMonitor::on_active()
single-threaded process and, truth be told, no one else relies on this
thing besides us.
*/
MonitorDBStore::TransactionRef t(new MonitorDBStore::Transaction);
auto t(std::make_shared<MonitorDBStore::Transaction>());
t->put(Monitor::MONITOR_NAME, "joined", 1);
mon->store->apply_transaction(t);
mon->has_ever_joined = true;

View File

@ -191,7 +191,7 @@ void OSDMonitor::update_from_paxos(bool *need_bootstrap)
// state, and we shouldn't want to work around it without knowing what
// exactly happened.
assert(latest_full > 0);
MonitorDBStore::TransactionRef t(new MonitorDBStore::Transaction);
auto t(std::make_shared<MonitorDBStore::Transaction>());
put_version_latest_full(t, latest_full);
mon->store->apply_transaction(t);
dout(10) << __func__ << " updated the on-disk full map version to "

View File

@ -299,7 +299,7 @@ void Paxos::handle_collect(MonOpRequestRef op)
dout(10) << "accepting pn " << accepted_pn << " from "
<< accepted_pn_from << dendl;
MonitorDBStore::TransactionRef t(new MonitorDBStore::Transaction);
auto t(std::make_shared<MonitorDBStore::Transaction>());
t->put(get_name(), "accepted_pn", accepted_pn);
dout(30) << __func__ << " transaction dump:\n";
@ -413,7 +413,7 @@ void Paxos::share_state(MMonPaxos *m, version_t peer_first_committed,
*/
bool Paxos::store_state(MMonPaxos *m)
{
MonitorDBStore::TransactionRef t(new MonitorDBStore::Transaction);
auto t(std::make_shared<MonitorDBStore::Transaction>());
map<version_t,bufferlist>::iterator start = m->values.begin();
bool changed = false;
@ -670,7 +670,7 @@ void Paxos::begin(bufferlist& v)
new_value = v;
if (last_committed == 0) {
MonitorDBStore::TransactionRef t(new MonitorDBStore::Transaction);
auto t(std::make_shared<MonitorDBStore::Transaction>());
// initial base case; set first_committed too
t->put(get_name(), "first_committed", 1);
decode_append_transaction(t, new_value);
@ -683,7 +683,7 @@ void Paxos::begin(bufferlist& v)
// store the proposed value in the store. IF it is accepted, we will then
// have to decode it into a transaction and apply it.
MonitorDBStore::TransactionRef t(new MonitorDBStore::Transaction);
auto t(std::make_shared<MonitorDBStore::Transaction>());
t->put(get_name(), last_committed+1, new_value);
// note which pn this pending value is for.
@ -694,7 +694,7 @@ void Paxos::begin(bufferlist& v)
JSONFormatter f(true);
t->dump(&f);
f.flush(*_dout);
MonitorDBStore::TransactionRef debug_tx(new MonitorDBStore::Transaction);
auto debug_tx(std::make_shared<MonitorDBStore::Transaction>());
bufferlist::iterator new_value_it = new_value.begin();
debug_tx->decode(new_value_it);
debug_tx->dump(&f);
@ -772,7 +772,7 @@ void Paxos::handle_begin(MonOpRequestRef op)
dout(10) << "accepting value for " << v << " pn " << accepted_pn << dendl;
// store the accepted value onto our store. We will have to decode it and
// apply its transaction once we receive permission to commit.
MonitorDBStore::TransactionRef t(new MonitorDBStore::Transaction);
auto t(std::make_shared<MonitorDBStore::Transaction>());
t->put(get_name(), v, begin->values[v]);
// note which pn this pending value is for.
@ -873,7 +873,7 @@ void Paxos::commit_start()
assert(g_conf->paxos_kill_at != 7);
MonitorDBStore::TransactionRef t(new MonitorDBStore::Transaction);
auto t(std::make_shared<MonitorDBStore::Transaction>());
// commit locally
t->put(get_name(), "last_committed", last_committed + 1);
@ -1280,7 +1280,7 @@ version_t Paxos::get_new_proposal_number(version_t gt)
last_pn += (version_t)mon->rank;
// write
MonitorDBStore::TransactionRef t(new MonitorDBStore::Transaction);
auto t(std::make_shared<MonitorDBStore::Transaction>());
t->put(get_name(), "last_pn", last_pn);
dout(30) << __func__ << " transaction dump:\n";

View File

@ -1141,7 +1141,7 @@ public:
*/
static void decode_append_transaction(MonitorDBStore::TransactionRef t,
bufferlist& bl) {
MonitorDBStore::TransactionRef vt(new MonitorDBStore::Transaction);
auto vt(std::make_shared<MonitorDBStore::Transaction>());
bufferlist::iterator it = bl.begin();
vt->decode(it);
t->append(vt);
@ -1359,7 +1359,7 @@ inline ostream& operator<<(ostream& out, Paxos::C_Proposal& p)
out << " " << proposed
<< " queued " << (ceph_clock_now() - p.proposal_time)
<< " tx dump:\n";
MonitorDBStore::TransactionRef t(new MonitorDBStore::Transaction);
auto t(std::make_shared<MonitorDBStore::Transaction>());
bufferlist::iterator p_it = p.bl.begin();
t->decode(p_it);
JSONFormatter f(true);

View File

@ -326,7 +326,7 @@ int FileStore::lfn_open(const coll_t& cid,
TEMP_FAILURE_RETRY(::close(fd));
}
} else {
*outfd = FDRef(new FDCache::FD(fd));
*outfd = std::make_shared<FDCache::FD>(fd);
}
if (need_lock) {

View File

@ -54,12 +54,12 @@ int RGWCallStatRemoteObjCR::operate() {
void rgw_register_sync_modules(RGWSyncModulesManager *modules_manager)
{
RGWSyncModuleRef default_module(new RGWDefaultSyncModule());
RGWSyncModuleRef default_module(std::make_shared<RGWDefaultSyncModule>());
modules_manager->register_module("rgw", default_module, true);
RGWSyncModuleRef log_module(new RGWLogSyncModule());
RGWSyncModuleRef log_module(std::make_shared<RGWLogSyncModule>());
modules_manager->register_module("log", log_module);
RGWSyncModuleRef es_module(new RGWElasticSyncModule());
RGWSyncModuleRef es_module(std::make_shared<RGWElasticSyncModule>());
modules_manager->register_module("elasticsearch", es_module);
}

View File

@ -436,7 +436,7 @@ int rewrite_crush(const char* progname,
// store the transaction into store as a proposal
const string prefix("paxos");
version_t pending_v = store.get(prefix, "last_committed") + 1;
MonitorDBStore::TransactionRef t(new MonitorDBStore::Transaction);
auto t(std::make_shared<MonitorDBStore::Transaction>());
bufferlist bl;
rewrite_txn.encode(bl);
cout << "adding pending commit " << pending_v
@ -482,7 +482,7 @@ int inflate_pgmap(MonitorDBStore& st, unsigned n, bool can_be_trimmed) {
version_t first = st.get("pgmap", "first_committed");
version_t ver = last;
MonitorDBStore::TransactionRef txn(new MonitorDBStore::Transaction);
auto txn(std::make_shared<MonitorDBStore::Transaction>());
for (unsigned i = 0; i < n; i++) {
bufferlist trans_bl;
bufferlist dirty_pgs;
@ -1012,7 +1012,7 @@ int main(int argc, char **argv) {
if (bl.length() == 0)
break;
cout << "\n--- " << v << " ---" << std::endl;
MonitorDBStore::TransactionRef tx(new MonitorDBStore::Transaction);
auto tx(std::make_shared<MonitorDBStore::Transaction>());
Paxos::decode_append_transaction(tx, bl);
JSONFormatter f(true);
tx->dump(&f);
@ -1192,7 +1192,7 @@ int main(int argc, char **argv) {
unsigned num = 0;
for (unsigned i = 0; i < ntrans; ++i) {
std::cerr << "Applying trans " << i << std::endl;
MonitorDBStore::TransactionRef t(new MonitorDBStore::Transaction);
auto t(std::make_shared<MonitorDBStore::Transaction>());
string prefix;
prefix.push_back((i%26)+'a');
for (unsigned j = 0; j < tsize; ++j) {
@ -1234,7 +1234,7 @@ int main(int argc, char **argv) {
do {
uint64_t num_keys = 0;
MonitorDBStore::TransactionRef tx(new MonitorDBStore::Transaction);
auto tx(std::make_shared<MonitorDBStore::Transaction>());
while (it->valid() && num_keys < 128) {
pair<string,string> k = it->raw_key();