From 47c2cecc21e0546a53e327e4adfb9f0f38f3cae9 Mon Sep 17 00:00:00 2001 From: "Yan, Zheng" Date: Wed, 8 Apr 2015 10:55:58 +0800 Subject: [PATCH] mds: update snaptable when renaming snapshot Signed-off-by: Yan, Zheng --- src/mds/Server.cc | 17 ++++++++++++ src/mds/SnapClient.h | 12 +++++++++ src/mds/SnapServer.cc | 61 ++++++++++++++++++++++++++++++++++--------- src/mds/SnapServer.h | 6 ++--- 4 files changed, 80 insertions(+), 16 deletions(-) diff --git a/src/mds/Server.cc b/src/mds/Server.cc index 14a80f5805984..6a92790342d86 100644 --- a/src/mds/Server.cc +++ b/src/mds/Server.cc @@ -7997,6 +7997,20 @@ void Server::handle_client_renamesnap(MDRequestRef& mdr) if (!mds->locker->acquire_locks(mdr, rdlocks, wrlocks, xlocks)) return; + // prepare + if (!mdr->more()->stid) { + mds->snapclient->prepare_update(diri->ino(), snapid, dstname, utime_t(), + &mdr->more()->stid, &mdr->more()->snapidbl, + new C_MDS_RetryRequest(mds->mdcache, mdr)); + return; + } + + version_t stid = mdr->more()->stid; + bufferlist::iterator p = mdr->more()->snapidbl.begin(); + snapid_t seq; + ::decode(seq, p); + dout(10) << " stid is " << stid << ", seq is " << seq << dendl; + // journal inode_t *pi = diri->project_inode(); pi->ctime = mdr->get_op_stamp(); @@ -8013,6 +8027,7 @@ void Server::handle_client_renamesnap(MDRequestRef& mdr) mdlog->start_entry(le); le->metablob.add_client_req(req->get_reqid(), req->get_oldest_client_tid()); + le->metablob.add_table_transaction(TABLE_SNAP, stid); mdcache->predirty_journal_parents(mdr, &le->metablob, diri, 0, PREDIRTY_PRIMARY, false); mdcache->journal_dirty_inode(mdr.get(), &le->metablob, diri); @@ -8029,6 +8044,8 @@ void Server::_renamesnap_finish(MDRequestRef& mdr, CInode *diri, snapid_t snapid diri->pop_and_dirty_projected_inode(mdr->ls); mdr->apply(); + mds->snapclient->commit(mdr->more()->stid, mdr->ls); + dout(10) << "snaprealm now " << *diri->snaprealm << dendl; mdcache->do_realm_invalidate_and_update_notify(diri, CEPH_SNAP_OP_CREATE, true); diff --git a/src/mds/SnapClient.h b/src/mds/SnapClient.h index 3e8d6a282786d..ea1b3acdcd5cc 100644 --- a/src/mds/SnapClient.h +++ b/src/mds/SnapClient.h @@ -56,6 +56,18 @@ public: ::encode(snapid, bl); _prepare(bl, pstid, pbl, onfinish); } + + void prepare_update(inodeno_t ino, snapid_t snapid, const string& name, utime_t stamp, + version_t *pstid, bufferlist *pbl, MDSInternalContextBase *onfinish) { + bufferlist bl; + __u32 op = TABLE_OP_UPDATE; + ::encode(op, bl); + ::encode(ino, bl); + ::encode(snapid, bl); + ::encode(name, bl); + ::encode(stamp, bl); + _prepare(bl, pstid, pbl, onfinish); + } }; #endif diff --git a/src/mds/SnapServer.cc b/src/mds/SnapServer.cc index 29812e4c49c40..5599b19437fd6 100644 --- a/src/mds/SnapServer.cc +++ b/src/mds/SnapServer.cc @@ -76,7 +76,8 @@ void SnapServer::_prepare(bufferlist &bl, uint64_t reqid, mds_rank_t bymds) ::decode(info.name, p); ::decode(info.stamp, p); info.snapid = ++last_snap; - pending_create[version] = info; + info.long_name = "create"; + pending_update[version] = info; dout(10) << "prepare v" << version << " create " << info << dendl; } else { pending_noop.insert(version); @@ -106,6 +107,26 @@ void SnapServer::_prepare(bufferlist &bl, uint64_t reqid, mds_rank_t bymds) } break; + case TABLE_OP_UPDATE: + { + SnapInfo info; + ::decode(info.ino, p); + ::decode(info.snapid, p); + ::decode(info.name, p); + ::decode(info.stamp, p); + info.long_name = "update"; + + version++; + // bump last_snap... we use it as a version value on the snaprealm. + ++last_snap; + pending_update[version] = info; + dout(10) << "prepare v" << version << " update " << info << dendl; + + bl.clear(); + ::encode(last_snap, bl); + } + break; + default: assert(0); } @@ -115,17 +136,25 @@ void SnapServer::_prepare(bufferlist &bl, uint64_t reqid, mds_rank_t bymds) bool SnapServer::_is_prepared(version_t tid) { return - pending_create.count(tid) || + pending_update.count(tid) || pending_destroy.count(tid); } bool SnapServer::_commit(version_t tid, MMDSTableRequest *req) { - if (pending_create.count(tid)) { - dout(7) << "commit " << tid << " create " << pending_create[tid] << dendl; - snaps[pending_create[tid].snapid] = pending_create[tid]; - pending_create.erase(tid); - } + if (pending_update.count(tid)) { + SnapInfo &info = pending_update[tid]; + string opname; + if (info.long_name.empty()) + opname = "create"; + else + opname.swap(info.long_name); + if (info.stamp == utime_t() && snaps.count(info.snapid)) + info.stamp = snaps[info.snapid].stamp; + dout(7) << "commit " << tid << " " << opname << " " << info << dendl; + snaps[info.snapid] = info; + pending_update.erase(tid); + } else if (pending_destroy.count(tid)) { snapid_t sn = pending_destroy[tid].first; @@ -157,9 +186,15 @@ bool SnapServer::_commit(version_t tid, MMDSTableRequest *req) void SnapServer::_rollback(version_t tid) { - if (pending_create.count(tid)) { - dout(7) << "rollback " << tid << " create " << pending_create[tid] << dendl; - pending_create.erase(tid); + if (pending_update.count(tid)) { + SnapInfo &info = pending_update[tid]; + string opname; + if (info.long_name.empty()) + opname = "create"; + else + opname.swap(info.long_name); + dout(7) << "rollback " << tid << " " << opname << " " << info << dendl; + pending_update.erase(tid); } else if (pending_destroy.count(tid)) { @@ -287,8 +322,8 @@ void SnapServer::dump(Formatter *f) const } f->close_section(); - f->open_array_section("pending_create"); - for(map::const_iterator i = pending_create.begin(); i != pending_create.end(); ++i) { + f->open_array_section("pending_update"); + for(map::const_iterator i = pending_update.begin(); i != pending_update.end(); ++i) { f->open_object_section("snap"); f->dump_unsigned("version", i->first); f->open_object_section("snapinfo"); @@ -326,7 +361,7 @@ void SnapServer::generate_test_instances(list& ls) populated->last_snap = 123; populated->snaps[456] = populated_snapinfo; populated->need_to_purge[2].insert(012); - populated->pending_create[234] = populated_snapinfo; + populated->pending_update[234] = populated_snapinfo; populated->pending_destroy[345].first = 567; populated->pending_destroy[345].second = 768; populated->pending_noop.insert(890); diff --git a/src/mds/SnapServer.h b/src/mds/SnapServer.h index 13669fccd3a21..80ced2b457ade 100644 --- a/src/mds/SnapServer.h +++ b/src/mds/SnapServer.h @@ -28,7 +28,7 @@ protected: map snaps; map > need_to_purge; - map pending_create; + map pending_update; map > pending_destroy; // (removed_snap, seq) set pending_noop; @@ -44,7 +44,7 @@ public: ::encode(last_snap, bl); ::encode(snaps, bl); ::encode(need_to_purge, bl); - ::encode(pending_create, bl); + ::encode(pending_update, bl); ::encode(pending_destroy, bl); ::encode(pending_noop, bl); ENCODE_FINISH(bl); @@ -54,7 +54,7 @@ public: ::decode(last_snap, bl); ::decode(snaps, bl); ::decode(need_to_purge, bl); - ::decode(pending_create, bl); + ::decode(pending_update, bl); if (struct_v >= 2) ::decode(pending_destroy, bl); else { -- 2.39.5