From e44c2d2763c3f79fa0ab199bda7f028439eecc15 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Mon, 3 Nov 2008 16:52:45 -0800 Subject: [PATCH] journal: ensure we see a clean sequence of entries on read/replay Only lightly tested, but so far so good. --- src/os/FileJournal.cc | 8 +++++++- src/os/JournalingObjectStore.cc | 3 ++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/os/FileJournal.cc b/src/os/FileJournal.cc index f680997d69042..a4af966c8b036 100644 --- a/src/os/FileJournal.cc +++ b/src/os/FileJournal.cc @@ -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); diff --git a/src/os/JournalingObjectStore.cc b/src/os/JournalingObjectStore.cc index 4bb6e17c56ff6..9f66b3d16996e 100644 --- a/src/os/JournalingObjectStore.cc +++ b/src/os/JournalingObjectStore.cc @@ -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. -- 2.39.5