]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
osd: read_log: clear the pagelog if it is corrupt
authorColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Tue, 5 Oct 2010 18:01:33 +0000 (11:01 -0700)
committerColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Tue, 5 Oct 2010 18:08:27 +0000 (11:08 -0700)
Signed-off-by: Colin McCabe <colinm@hq.newdream.net>
src/osd/PG.cc
src/osd/PG.h

index bb91accc16b6679bdaae1b134c8b4fa0421cd578..4d0f0ae681634e5e09ad5f10731602ad8dc89b51 100644 (file)
@@ -39,7 +39,6 @@ static ostream& _prefix(PG *pg, int whoami, OSDMap *osdmap) {
   return *_dout << dbeginl << "osd" << whoami << " " << (osdmap ? osdmap->get_epoch():0) << " " << *pg << " ";
 }
 
-
 /******* PGLog ********/
 
 void PG::Log::copy_after(const Log &other, eversion_t v) 
@@ -2173,11 +2172,11 @@ void PG::read_log(ObjectStore *store)
     bufferlist bl;
     store->read(coll_t::META_COLL, log_oid, ondisklog.tail, ondisklog.length(), bl);
     if (bl.length() < ondisklog.length()) {
-      dout(0) << "read_log got " << bl.length() << " bytes, expected " 
-             << ondisklog.head << "-" << ondisklog.tail << "="
-             << ondisklog.length()
-             << dendl;
-      assert(0);
+      std::ostringstream oss;
+      oss << "read_log got " << bl.length() << " bytes, expected "
+         << ondisklog.head << "-" << ondisklog.tail << "="
+         << ondisklog.length();
+      throw read_log_error(oss.str().c_str());
     }
     
     PG::Log::Entry e;
@@ -2198,10 +2197,9 @@ void PG::read_log(ObjectStore *store)
          bufferlist::iterator q = ebl.begin();
          ::decode(e, q);
        } else {
-         dout(0) << "read_log " << pos << " bad crc got " << got << " expected" << crc << dendl;
-
-         // ....
-         assert("do something smart here..." == 0);
+         std::ostringstream oss;
+         oss << "read_log " << pos << " bad crc got " << got << " expected" << crc;
+         throw read_log_error(oss.str().c_str());
        }
       } else {
        ::decode(e, p);
@@ -2403,7 +2401,18 @@ void PG::read_state(ObjectStore *store)
   ::decode(struct_v, p);
   ::decode(snap_collections, p);
 
-  read_log(store);
+  try {
+    read_log(store);
+  }
+  catch (const buffer::error &e) {
+    // Pretend that there is no ondisklog
+    dout(0) << "Got exception '" << e.what() << "' while reading log. "
+            << "Zeroing log." << dendl;
+    ondisklog.zero();
+    log.head = log.tail = info.last_update;
+    info.log_tail = info.last_update;
+    info.log_backlog = false;
+  }
 }
 
 coll_t PG::make_snap_collection(ObjectStore::Transaction& t, snapid_t s)
index 9247a0bc0a5b8bdb04e02cd3a3a19a01bc5762b8..a1b9ae946a09592e90c7a029e0ee76c0d2d87c05 100644 (file)
@@ -79,7 +79,19 @@ struct PGPool {
 
 class PG {
 public:
-  
+  /* Exceptions */
+  class read_log_error : public buffer::error {
+  public:
+    explicit read_log_error(const char *what) {
+      snprintf(buf, sizeof(buf), "read_log_error: %s", what);
+    }
+    const char *what() const throw () {
+      return buf;
+    }
+  private:
+    char buf[512];
+  };
+
   /*
    * PG::Info - summary of PG statistics.
    *