]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
journal: ensure we see a clean sequence of entries on read/replay
authorSage Weil <sage@newdream.net>
Tue, 4 Nov 2008 00:52:45 +0000 (16:52 -0800)
committerSage Weil <sage@newdream.net>
Tue, 4 Nov 2008 00:54:32 +0000 (16:54 -0800)
Only lightly tested, but so far so good.

src/os/FileJournal.cc
src/os/JournalingObjectStore.cc

index f680997d690424363a315d4e30a3d63396f51a95..a4af966c8b036107aaafebf66a0a118190276c77 100644 (file)
@@ -136,9 +136,9 @@ int FileJournal::open(__u64 next_seq)
 
   // find next entry
   read_pos = header.start;
+  __u64 seq = 0;
   while (1) {
     bufferlist bl;
-    __u64 seq;
     off64_t old_pos = read_pos;
     if (!read_entry(bl, seq)) {
       dout(10) << "open reached end of journal." << dendl;
@@ -154,6 +154,7 @@ int FileJournal::open(__u64 next_seq)
       read_pos = old_pos;
       break;
     }
+    seq++;  // next event should follow.
   }
 
   return 0;
@@ -666,6 +667,11 @@ bool FileJournal::read_entry(bufferlist& bl, __u64& seq)
          << " " << h.len << " bytes"
          << dendl;
 
+  if (seq && h.seq != seq) {
+    dout(2) << "read_entry " << read_pos << " : got seq " << h.seq << ", expected " << seq << ", stopping" << dendl;
+    return false;
+  }
+
   if (h.seq < last_committed_seq) {
     dout(0) << "read_entry seq " << seq << " < last_committed_seq " << last_committed_seq << dendl;
     assert(h.seq >= last_committed_seq);
index 4bb6e17c56ff6181e95c739b4e7624e05db9df10..9f66b3d16996e6a0be82dc43b5b3fbd8b553ab91 100644 (file)
@@ -23,7 +23,7 @@ int JournalingObjectStore::journal_replay()
   int count = 0;
   while (1) {
     bufferlist bl;
-    __u64 seq;
+    __u64 seq = op_seq + 1;
     if (!journal->read_entry(bl, seq)) {
       dout(3) << "journal_replay: end of journal, done." << dendl;
       break;
@@ -41,6 +41,7 @@ int JournalingObjectStore::journal_replay()
 
     dout(3) << "journal_replay: r = " << r << ", op now seq " << op_seq << dendl;
     assert(op_seq == seq);
+    seq++;  // we expect the next op
   }
 
   // done reading, make writeable.