mon: use std::make_shared to replace new

Signed-off-by: Yunchuan Wen <yunchuan.wen@kylin-cloud.com>
This commit is contained in:
Yunchuan Wen 2016-12-09 13:08:49 +08:00
parent d2f8fb4a6b
commit 1f155619c1
11 changed files with 36 additions and 36 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

@ -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);
@ -81,7 +81,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);
@ -512,7 +512,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

@ -540,7 +540,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 {
@ -1341,7 +1341,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);
@ -1405,7 +1405,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);
@ -1421,7 +1421,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");
@ -1560,7 +1560,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) {
@ -1654,7 +1654,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";
@ -1669,7 +1669,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);
@ -2238,7 +2238,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);
@ -5181,7 +5181,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;
@ -5206,7 +5206,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

@ -184,7 +184,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);
@ -374,7 +374,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

@ -202,7 +202,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

@ -1142,7 +1142,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);
@ -1360,7 +1360,7 @@ inline ostream& operator<<(ostream& out, Paxos::C_Proposal& p)
out << " " << proposed
<< " queued " << (ceph_clock_now(NULL) - 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

@ -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();