From a099270cf1bf15da9e94a2e2db01c2285fdc9bcd Mon Sep 17 00:00:00 2001 From: yangruifeng Date: Fri, 16 Oct 2015 22:00:56 -0400 Subject: [PATCH] osd/tools: new and delete ObjectStore::Transaction in a function is not necessary Signed-off-by: Ruifeng Yang --- src/os/FileJournal.cc | 5 ++-- src/osd/OSD.cc | 14 ++++----- src/tools/ceph_objectstore_tool.cc | 46 +++++++++++++----------------- 3 files changed, 28 insertions(+), 37 deletions(-) diff --git a/src/os/FileJournal.cc b/src/os/FileJournal.cc index fb05152e8a4..4fa419ccbf8 100644 --- a/src/os/FileJournal.cc +++ b/src/os/FileJournal.cc @@ -665,12 +665,11 @@ int FileJournal::_fdump(Formatter &f, bool simple) bufferlist::iterator p = bl.begin(); int trans_num = 0; while (!p.end()) { - ObjectStore::Transaction *t = new ObjectStore::Transaction(p); + ObjectStore::Transaction t(p); f.open_object_section("transaction"); f.dump_unsigned("trans_num", trans_num); - t->dump(&f); + t.dump(&f); f.close_section(); - delete t; trans_num++; } f.close_section(); diff --git a/src/osd/OSD.cc b/src/osd/OSD.cc index a4af9981999..59cb5aade17 100644 --- a/src/osd/OSD.cc +++ b/src/osd/OSD.cc @@ -4223,7 +4223,7 @@ bool remove_dir( { vector olist; int64_t num = 0; - ObjectStore::Transaction *t = new ObjectStore::Transaction; + ObjectStore::Transaction t; ghobject_t next; handle.reset_tp_timeout(); store->collection_list( @@ -4239,38 +4239,36 @@ bool remove_dir( ++i, ++num) { if (i->is_pgmeta()) continue; - OSDriver::OSTransaction _t(osdriver->get_transaction(t)); + OSDriver::OSTransaction _t(osdriver->get_transaction(&t)); int r = mapper->remove_oid(i->hobj, &_t); if (r != 0 && r != -ENOENT) { assert(0); } - t->remove(coll, *i); + t.remove(coll, *i); if (num >= cct->_conf->osd_target_transaction_size) { C_SaferCond waiter; - store->queue_transaction(osr, t, &waiter); + store->queue_transaction(osr, &t, &waiter); bool cont = dstate->pause_clearing(); handle.suspend_tp_timeout(); waiter.wait(); handle.reset_tp_timeout(); if (cont) cont = dstate->resume_clearing(); - delete t; if (!cont) return false; - t = new ObjectStore::Transaction; + t = ObjectStore::Transaction(); num = 0; } } C_SaferCond waiter; - store->queue_transaction(osr, t, &waiter); + store->queue_transaction(osr, &t, &waiter); bool cont = dstate->pause_clearing(); handle.suspend_tp_timeout(); waiter.wait(); handle.reset_tp_timeout(); if (cont) cont = dstate->resume_clearing(); - delete t; // whether there are more objects to remove in the collection *finished = next.is_max(); return cont; diff --git a/src/tools/ceph_objectstore_tool.cc b/src/tools/ceph_objectstore_tool.cc index 11de3bc32b4..d734fcd968e 100644 --- a/src/tools/ceph_objectstore_tool.cc +++ b/src/tools/ceph_objectstore_tool.cc @@ -407,38 +407,35 @@ void remove_coll(ObjectStore *store, const coll_t &coll, ghobject_t next; int r = 0; int64_t num = 0; - ObjectStore::Transaction *t = new ObjectStore::Transaction; + ObjectStore::Transaction t; cout << "remove_coll " << coll << std::endl; while (!next.is_max()) { vector objects; r = store->collection_list(coll, next, ghobject_t::get_max(), true, 300, &objects, &next); if (r < 0) - goto out; + return; for (vector::iterator i = objects.begin(); i != objects.end(); ++i, ++num) { - OSDriver::OSTransaction _t(driver.get_transaction(t)); + OSDriver::OSTransaction _t(driver.get_transaction(&t)); cout << "remove " << *i << std::endl; int r = mapper.remove_oid(i->hobj, &_t); if (r != 0 && r != -ENOENT) { assert(0); } - t->remove(coll, *i); + t.remove(coll, *i); if (num >= 30) { - store->apply_transaction(&osr, *t); - delete t; - t = new ObjectStore::Transaction; + store->apply_transaction(&osr, t); + t = ObjectStore::Transaction(); num = 0; } } } - t->remove_collection(coll); - store->apply_transaction(&osr, *t); -out: - delete t; + t.remove_collection(coll); + store->apply_transaction(&osr, t); } //Based on part of OSD::load_pgs() @@ -507,13 +504,12 @@ int initiate_new_remove_pg(ObjectStore *store, spg_t r_pgid, cout << " marking collection for removal" << std::endl; if (dry_run) return 0; - ObjectStore::Transaction *rmt = new ObjectStore::Transaction; - int r = mark_pg_for_removal(store, r_pgid, rmt); + ObjectStore::Transaction rmt; + int r = mark_pg_for_removal(store, r_pgid, &rmt); if (r < 0) { - delete rmt; return r; } - store->apply_transaction(&osr, *rmt); + store->apply_transaction(&osr, rmt); finish_remove_pgs(store); return r; } @@ -1331,18 +1327,17 @@ int ObjectStoreTool::do_import(ObjectStore *store, OSDSuperblock& sb, } if (!dry_run) { - ObjectStore::Transaction *t = new ObjectStore::Transaction; - PG::_create(*t, pgid, + ObjectStore::Transaction t; + PG::_create(t, pgid, pgid.get_split_bits(curmap.get_pg_pool(pgid.pool())->get_pg_num())); - PG::_init(*t, pgid, NULL); + PG::_init(t, pgid, NULL); // mark this coll for removal until we're done map values; ::encode((char)1, values["_remove"]); - t->omap_setkeys(coll, pgid.make_pgmeta_oid(), values); + t.omap_setkeys(coll, pgid.make_pgmeta_oid(), values); - store->apply_transaction(&osr, *t); - delete t; + store->apply_transaction(&osr, t); } cout << "Importing pgid " << pgid; @@ -1494,18 +1489,17 @@ int do_remove_object(ObjectStore *store, coll_t coll, cout << "remove " << ghobj << std::endl; if (dry_run) return 0; - ObjectStore::Transaction *t = new ObjectStore::Transaction; - OSDriver::OSTransaction _t(driver.get_transaction(t)); + ObjectStore::Transaction t; + OSDriver::OSTransaction _t(driver.get_transaction(&t)); r = mapper.remove_oid(ghobj.hobj, &_t); if (r < 0 && r != -ENOENT) { cerr << "remove_oid returned " << cpp_strerror(r) << std::endl; return r; } - t->remove(coll, ghobj); + t.remove(coll, ghobj); - store->apply_transaction(&osr, *t); - delete t; + store->apply_transaction(&osr, t); return 0; } -- 2.47.3