]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
osd: properly encode ondisklog attr
authorSage Weil <sage@newdream.net>
Fri, 19 Dec 2008 00:01:41 +0000 (16:01 -0800)
committerSage Weil <sage@newdream.net>
Fri, 19 Dec 2008 00:01:41 +0000 (16:01 -0800)
Also combine into a single attr.

src/osd/PG.cc
src/osd/PG.h
src/osd/osd_types.h

index 95d506ffd4ba64aed55fad025f9f153be3f62cfb..6bf137965af42ffe98b189bf2ec20d2f4275453d 100644 (file)
@@ -1614,8 +1614,10 @@ void PG::write_log(ObjectStore::Transaction& t)
   // write it
   t.remove(0, info.pgid.to_log_pobject() );
   t.write(0, info.pgid.to_log_pobject() , 0, bl.length(), bl);
-  t.collection_setattr(info.pgid.to_coll(), "ondisklog_bottom", &ondisklog.bottom, sizeof(ondisklog.bottom));
-  t.collection_setattr(info.pgid.to_coll(), "ondisklog_top", &ondisklog.top, sizeof(ondisklog.top));
+
+  bufferlist blb(sizeof(ondisklog));
+  ::encode(ondisklog, blb);
+  t.collection_setattr(info.pgid.to_coll(), "ondisklog", blb);
   
   dout(10) << "write_log to " << ondisklog.bottom << "~" << ondisklog.length() << dendl;
   dirty_log = false;
@@ -1625,7 +1627,7 @@ void PG::trim_ondisklog_to(ObjectStore::Transaction& t, eversion_t v)
 {
   dout(15) << "trim_ondisk_log_to v " << v << dendl;
 
-  map<loff_t,eversion_t>::iterator p = ondisklog.block_map.begin();
+  map<__u64,eversion_t>::iterator p = ondisklog.block_map.begin();
   while (p != ondisklog.block_map.end()) {
     dout(15) << "    " << p->first << " -> " << p->second << dendl;
     p++;
@@ -1640,7 +1642,7 @@ void PG::trim_ondisklog_to(ObjectStore::Transaction& t, eversion_t v)
     return;  // can't trim anything!
   
   // we can trim!
-  loff_t trim = p->first;
+  __u64 trim = p->first;
   dout(10) << "  trimming ondisklog to " << ondisklog.bottom << "~" << ondisklog.length() << dendl;
 
   assert(trim >= ondisklog.bottom);
@@ -1650,8 +1652,9 @@ void PG::trim_ondisklog_to(ObjectStore::Transaction& t, eversion_t v)
   while (p != ondisklog.block_map.begin()) 
     ondisklog.block_map.erase(ondisklog.block_map.begin());
   
-  t.collection_setattr(info.pgid.to_coll(), "ondisklog_bottom", &ondisklog.bottom, sizeof(ondisklog.bottom));
-  t.collection_setattr(info.pgid.to_coll(), "ondisklog_top", &ondisklog.top, sizeof(ondisklog.top));
+  bufferlist blb(sizeof(ondisklog));
+  ::encode(ondisklog, blb);
+  t.collection_setattr(info.pgid.to_coll(), "ondisklog", blb);
 
   if (!g_conf.osd_preserve_trimmed_log)
     t.zero(0, info.pgid.to_log_pobject(), 0, ondisklog.bottom);
@@ -1688,8 +1691,11 @@ void PG::append_log(ObjectStore::Transaction &t, bufferlist& bl,
   t.write(0, info.pgid.to_log_pobject(), ondisklog.top, bl.length(), bl );
   
   ondisklog.top += bl.length();
-  t.collection_setattr(info.pgid.to_coll(), "ondisklog_top",
-                      &ondisklog.top, sizeof(ondisklog.top));
+
+  bufferlist blb(sizeof(ondisklog));
+  ::encode(ondisklog, blb);
+  t.collection_setattr(info.pgid.to_coll(), "ondisklog", blb);
+
   
   // trim?
   if (trim_to > log.bottom &&
@@ -1705,13 +1711,13 @@ void PG::append_log(ObjectStore::Transaction &t, bufferlist& bl,
 
 void PG::read_log(ObjectStore *store)
 {
-  int r;
   // load bounds
   ondisklog.bottom = ondisklog.top = 0;
-  r = store->collection_getattr(info.pgid.to_coll(), "ondisklog_bottom", &ondisklog.bottom, sizeof(ondisklog.bottom));
-  assert(r == sizeof(ondisklog.bottom));
-  r = store->collection_getattr(info.pgid.to_coll(), "ondisklog_top", &ondisklog.top, sizeof(ondisklog.top));
-  assert(r == sizeof(ondisklog.top));
+
+  bufferlist blb;
+  store->collection_getattr(info.pgid.to_coll(), "ondisklog", blb);
+  bufferlist::iterator p = blb.begin();
+  ::decode(ondisklog, p);
 
   dout(10) << "read_log " << ondisklog.bottom << "~" << ondisklog.length() << dendl;
 
index 3820a96da1c0ff82c8e7dac495263995ed60ae25..edc94ca325b09015916fd33893b17cbbbd8d7fef 100644 (file)
@@ -380,15 +380,25 @@ public:
   class OndiskLog {
   public:
     // ok
-    loff_t bottom;                     // first byte of log. 
-    loff_t top;                        // byte following end of log.
-    map<loff_t,eversion_t> block_map;  // block -> first stamp logged there
+    __u64 bottom;                     // first byte of log. 
+    __u64 top;                        // byte following end of log.
+    map<__u64,eversion_t> block_map;  // block -> first stamp logged there
 
     OndiskLog() : bottom(0), top(0) {}
 
-    loff_t length() { return top - bottom; }
+    __u64 length() { return top - bottom; }
     bool trim_to(eversion_t v, ObjectStore::Transaction& t);
+
+    void encode(bufferlist& bl) const {
+      ::encode(bottom, bl);
+      ::encode(top, bl);
+    }
+    void decode(bufferlist::iterator& bl) {
+      ::decode(bottom, bl);
+      ::decode(top, bl);
+    }
   };
+  WRITE_CLASS_ENCODER(OndiskLog)
 
 
   /*
@@ -841,7 +851,7 @@ WRITE_CLASS_ENCODER(PG::Missing)
 WRITE_CLASS_ENCODER(PG::Log::Entry)
 WRITE_CLASS_ENCODER(PG::Log)
 WRITE_CLASS_ENCODER(PG::Interval)
-
+WRITE_CLASS_ENCODER(PG::OndiskLog)
 
 inline ostream& operator<<(ostream& out, const PG::Info::History& h) 
 {
index 2af3a4b9a6a93015e90898cce49cd63d37ea8c71..54d2e0fba2c8c0325ffb1f876efd4c7c2e67b62b 100644 (file)
@@ -25,7 +25,7 @@
 
 
 
-#define CEPH_OSD_ONDISK_MAGIC "ceph osd volume v007"
+#define CEPH_OSD_ONDISK_MAGIC "ceph osd volume v008"