]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mds: introduce snaptable
authorSage Weil <sage@newdream.net>
Wed, 2 Jul 2008 17:48:25 +0000 (10:48 -0700)
committerSage Weil <sage@newdream.net>
Wed, 2 Jul 2008 17:48:25 +0000 (10:48 -0700)
src/Makefile.am
src/mds/MDS.cc
src/mds/MDS.h
src/mds/SnapTable.cc [new file with mode: 0644]
src/mds/SnapTable.h [new file with mode: 0644]
src/mds/mdstypes.h

index d39c44fa65239ee3f889b147257f848f3effb67a..d616484463be9737a11bf05c0c1194dc3ead403c 100644 (file)
@@ -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
 
index 6ae7e70389e7cc84fa6e370b27b934fa8e557637..c94ebb54ee7f3c785130bed5f6cd76ae06ecbd06 100644 (file)
 #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());
index 1afe25dfb2b10610c9aac1f3bf19f80b956734dc..b41bf73138cd45ce2ad2980e6e16e3f45eae1487 100644 (file)
@@ -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 (file)
index 0000000..fdb8409
--- /dev/null
@@ -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 <sage@newdream.net>
+ *
+ * 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 (file)
index 0000000..6cbbe0c
--- /dev/null
@@ -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 <sage@newdream.net>
+ *
+ * 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<snapid_t, snapinfo> snaps;
+  set<snapid_t> 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
index 788393e48525fee4ae8d05b72cf4eaeaf80a8955..8cf9a34ef6badfc27e7d88dd8f618fdbd7a547b2 100644 (file)
@@ -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)