From ed4bc51a083470fce140783aeaf44b7f77427846 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Wed, 2 Jul 2008 10:48:25 -0700 Subject: [PATCH] mds: introduce snaptable --- src/Makefile.am | 1 + src/mds/MDS.cc | 16 +++++++++- src/mds/MDS.h | 3 ++ src/mds/SnapTable.cc | 60 +++++++++++++++++++++++++++++++++++++ src/mds/SnapTable.h | 71 ++++++++++++++++++++++++++++++++++++++++++++ src/mds/mdstypes.h | 1 + 6 files changed, 151 insertions(+), 1 deletion(-) create mode 100644 src/mds/SnapTable.cc create mode 100644 src/mds/SnapTable.h diff --git a/src/Makefile.am b/src/Makefile.am index d39c44fa65239..d616484463be9 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -205,6 +205,7 @@ libmds_a_SOURCES = \ mds/LogEvent.cc \ mds/MDSTable.cc \ mds/IdAllocator.cc \ + mds/SnapTable.cc \ mds/SessionMap.cc \ mds/MDLog.cc diff --git a/src/mds/MDS.cc b/src/mds/MDS.cc index 6ae7e70389e7c..c94ebb54ee7f3 100644 --- a/src/mds/MDS.cc +++ b/src/mds/MDS.cc @@ -31,12 +31,14 @@ #include "MDCache.h" #include "MDLog.h" #include "MDBalancer.h" -#include "IdAllocator.h" #include "Migrator.h" #include "AnchorTable.h" #include "AnchorClient.h" +#include "IdAllocator.h" +#include "SnapTable.h" + #include "common/Logger.h" #include "common/LogType.h" @@ -92,6 +94,7 @@ MDS::MDS(int whoami, Messenger *m, MonMap *mm) : idalloc = new IdAllocator(this); anchortable = new AnchorTable(this); + snaptable = new SnapTable(this); server = new Server(this); locker = new Locker(this, mdcache); @@ -125,6 +128,7 @@ MDS::~MDS() { if (balancer) { delete balancer; balancer = NULL; } if (idalloc) { delete idalloc; idalloc = NULL; } if (anchortable) { delete anchortable; anchortable = NULL; } + if (snaptable) { delete snaptable; snaptable = NULL; } if (anchorclient) { delete anchorclient; anchorclient = NULL; } if (osdmap) { delete osdmap; osdmap = 0; } if (mdsmap) { delete mdsmap; mdsmap = 0; } @@ -735,6 +739,12 @@ void MDS::boot_create() anchortable->create_fresh(); anchortable->save(fin->new_sub()); } + + if (whoami == 0) { + dout(10) << "boot_create creating fresh snaptable" << dendl; + snaptable->reset(); + snaptable->save(fin->new_sub()); + } } void MDS::creating_done() @@ -777,6 +787,10 @@ void MDS::boot_start(int step, int r) dout(2) << "boot_start " << step << ": opening anchor table" << dendl; anchortable->load(gather->new_sub()); } + if (whoami == 0) { + dout(2) << "boot_start " << step << ": opening snap table" << dendl; + snaptable->load(gather->new_sub()); + } dout(2) << "boot_start " << step << ": opening mds log" << dendl; mdlog->open(gather->new_sub()); diff --git a/src/mds/MDS.h b/src/mds/MDS.h index 1afe25dfb2b10..b41bf73138cd4 100644 --- a/src/mds/MDS.h +++ b/src/mds/MDS.h @@ -60,6 +60,7 @@ class MDCache; class MDLog; class MDBalancer; class IdAllocator; +class SnapTable; class CInode; class CDir; @@ -105,6 +106,8 @@ class MDS : public Dispatcher { AnchorTable *anchortable; AnchorClient *anchorclient; + SnapTable *snaptable; + Logger *logger, *logger2; diff --git a/src/mds/SnapTable.cc b/src/mds/SnapTable.cc new file mode 100644 index 0000000000000..fdb840956d429 --- /dev/null +++ b/src/mds/SnapTable.cc @@ -0,0 +1,60 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab +/* + * Ceph - scalable distributed file system + * + * Copyright (C) 2004-2006 Sage Weil + * + * This is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software + * Foundation. See file COPYING. + * + */ + +#include "SnapTable.h" +#include "MDS.h" + +#include "include/types.h" + +#include "config.h" + +#define dout(x) if (x <= g_conf.debug_mds) *_dout << dbeginl << g_clock.now() << " mds" << mds->get_nodeid() << ".snap: " + +void SnapTable::init_inode() +{ + ino = MDS_INO_SNAPTABLE; + layout = g_default_file_layout; +} + +void SnapTable::reset_state() +{ + last_snap = 0; + snaps.clear(); + pending_removal.clear(); +} + +snapid_t SnapTable::create(inodeno_t base, const string& name, utime_t stamp) +{ + assert(is_active()); + + snapid_t sn = ++last_snap; + snaps[sn].base = base; + snaps[sn].name = name; + snaps[sn].stamp = stamp; + version++; + + dout(10) << "create(" << base << "," << name << ") = " << sn << dendl; + + return sn; +} + +void SnapTable::remove(snapid_t sn) +{ + assert(is_active()); + + snaps.erase(sn); + pending_removal.insert(sn); + version++; +} + diff --git a/src/mds/SnapTable.h b/src/mds/SnapTable.h new file mode 100644 index 0000000000000..6cbbe0c7e7487 --- /dev/null +++ b/src/mds/SnapTable.h @@ -0,0 +1,71 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab +/* + * Ceph - scalable distributed file system + * + * Copyright (C) 2004-2006 Sage Weil + * + * This is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software + * Foundation. See file COPYING. + * + */ + + +#ifndef __SNAPTABLE_H +#define __SNAPTABLE_H + +#include "MDSTable.h" +#include "include/interval_set.h" + +class MDS; + +class SnapTable : public MDSTable { +public: + struct snapinfo { + inodeno_t base; + utime_t stamp; + string name; + + void encode(bufferlist& bl) const { + ::encode(base, bl); + ::encode(stamp, bl); + ::encode(name, bl); + } + void decode(bufferlist::iterator& bl) { + ::decode(base, bl); + ::decode(stamp, bl); + ::decode(name, bl); + } + }; + WRITE_CLASS_ENCODER(snapinfo) + +protected: + snapid_t last_snap; + map snaps; + set pending_removal; + +public: + SnapTable(MDS *m) : MDSTable(m, "snap") { } + + // alloc or reclaim ids + snapid_t create(inodeno_t base, const string& name, utime_t stamp); + void remove(snapid_t sn); + + void init_inode(); + void reset_state(); + void encode_state(bufferlist& bl) { + ::encode(last_snap, bl); + ::encode(snaps, bl); + ::encode(pending_removal, bl); + } + void decode_state(bufferlist::iterator& bl) { + ::decode(last_snap, bl); + ::decode(snaps, bl); + ::decode(pending_removal, bl); + } +}; +WRITE_CLASS_ENCODER(SnapTable::snapinfo) + +#endif diff --git a/src/mds/mdstypes.h b/src/mds/mdstypes.h index 788393e48525f..8cf9a34ef6bad 100644 --- a/src/mds/mdstypes.h +++ b/src/mds/mdstypes.h @@ -34,6 +34,7 @@ using namespace std; #define MDS_INO_ROOT 1 #define MDS_INO_PGTABLE 2 #define MDS_INO_ANCHORTABLE 3 +#define MDS_INO_SNAPTABLE 4 #define MDS_INO_LOG_OFFSET (1*MAX_MDS) #define MDS_INO_IDS_OFFSET (2*MAX_MDS) -- 2.39.5