]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
osd: implement --dump-journal
authorSage Weil <sage.weil@dreamhost.com>
Sun, 15 Jan 2012 05:15:02 +0000 (21:15 -0800)
committerSage Weil <sage@newdream.net>
Fri, 20 Jan 2012 18:55:20 +0000 (10:55 -0800)
Dump the contents of the journal to stdout in text form.  Useful for
debugging.

Signed-off-by: Sage Weil <sage.weil@dreamhost.com>
src/ceph_osd.cc
src/os/FileJournal.cc
src/os/FileJournal.h
src/os/FileStore.cc
src/os/FileStore.h
src/os/Journal.h
src/os/ObjectStore.h
src/osd/OSD.cc
src/osd/OSD.h

index a272ac2b0412e6ba4702856522f3a221290bcf57..0c6945148812b2ac19a3e2b5ab018356d8189781 100644 (file)
@@ -64,6 +64,7 @@ int main(int argc, const char **argv)
   bool mkjournal = false;
   bool mkkey = false;
   bool flushjournal = false;
+  bool dump_journal = false;
   bool convertfilestore = false;
   bool get_journal_fsid = false;
   bool get_osd_fsid = false;
@@ -89,6 +90,8 @@ int main(int argc, const char **argv)
       convertfilestore = true;
     } else if (ceph_argparse_witharg(args, i, &val, "--dump-pg-log", (char*)NULL)) {
       dump_pg_log = val;
+    } else if (ceph_argparse_flag(args, i, "--dump-journal", (char*)NULL)) {
+      dump_journal = true;
     } else if (ceph_argparse_flag(args, i, "--get-cluster-fsid", (char*)NULL)) {
       get_cluster_fsid = true;
     } else if (ceph_argparse_flag(args, i, "--get-osd-fsid", (char*)NULL)) {
@@ -211,6 +214,22 @@ int main(int argc, const char **argv)
         << dendl;
     exit(0);
   }
+  if (dump_journal) {
+    common_init_finish(g_ceph_context);
+    int err = OSD::dump_journal(g_conf->osd_data, g_conf->osd_journal, cout);
+    if (err < 0) {
+      derr << TEXT_RED << " ** ERROR: error dumping journal " << g_conf->osd_journal
+          << " for object store " << g_conf->osd_data
+          << ": " << cpp_strerror(-err) << TEXT_NORMAL << dendl;
+      exit(1);
+    }
+    derr << "dumped journal " << g_conf->osd_journal
+        << " for object store " << g_conf->osd_data
+        << dendl;
+    exit(0);
+
+  }
+
 
   if (convertfilestore) {
     int err = OSD::convertfs(g_conf->osd_data, g_conf->osd_journal);
index 63449723d675ec87292ddd3ef96346a1fab02fdd..ebc641fee5e0b63bf6ff5b28f69814cc057ab41b 100644 (file)
@@ -504,6 +504,42 @@ void FileJournal::close()
   fd = -1;
 }
 
+
+int FileJournal::dump(ostream& out)
+{
+  dout(10) << "dump" << dendl;
+  _open(false, false);
+
+  int err = read_header();
+  if (err < 0)
+    return err;
+
+  read_pos = header.start;
+
+  while (1) {
+    bufferlist bl;
+    uint64_t seq = 0;
+    uint64_t pos = read_pos;
+    if (!read_entry(bl, seq)) {
+      dout(3) << "journal_replay: end of journal, done." << dendl;
+      break;
+    }
+
+    out << "offset " << pos << " seq " << seq << "\n";
+   
+    bufferlist::iterator p = bl.begin();
+    while (!p.end()) {
+      ObjectStore::Transaction *t = new ObjectStore::Transaction(p);
+      t->dump(out);
+      delete t;
+    }
+  }
+  out << std::endl;
+  dout(10) << "dump finish" << dendl;
+  return 0;
+}
+
+
 void FileJournal::start_writer()
 {
   write_stop = false;
index 88955b2474b61d1ebe5351b71ec53e97c02eedde..1488d65164ccf306a5c269aa4aeb84f86ef96e9a 100644 (file)
@@ -238,6 +238,8 @@ private:
   void close();
   int peek_fsid(uuid_d& fsid);
 
+  int dump(ostream& out);
+
   void flush();
 
   void throttle();
index 47223678b23288f7de458eba5d65f97e1e2c0bfa..c1ab28552a6310008938563300041dc0803978bc 100644 (file)
@@ -759,6 +759,19 @@ int FileStore::open_journal()
   return 0;
 }
 
+int FileStore::dump_journal(ostream& out)
+{
+  int r;
+
+  if (!journalpath.length())
+    return -EINVAL;
+
+  FileJournal *journal = new FileJournal(fsid, &finisher, &sync_cond, journalpath.c_str(), m_journal_dio);
+  r = journal->dump(out);
+  delete journal;
+  return r;
+}
+
 int FileStore::wipe_subvol(const char *s)
 {
 #if defined(__linux__)
index 299d81fe32749edaf260cbaebb697805c3b0f9db..e6fb17f4ec1a4b427df37e1bad9cf616cb4e55fe 100644 (file)
@@ -323,6 +323,8 @@ public:
   void flush();
   void sync_and_flush();
 
+  int dump_journal(ostream& out);
+
   uuid_d get_fsid() { return fsid; }
 
   int snapshot(const string& name);
index 5d9f46f3f7dc93957cc748f9133a18785beec86f..c87e54858915f78a373e3e7e5b467da6f63ec7ca 100644 (file)
@@ -16,6 +16,8 @@
 #ifndef CEPH_JOURNAL_H
 #define CEPH_JOURNAL_H
 
+#include <errno.h>
+
 #include "include/buffer.h"
 #include "include/Context.h"
 #include "common/Finisher.h"
@@ -46,6 +48,8 @@ public:
   virtual void flush() = 0;
   virtual void throttle() = 0;
 
+  virtual int dump(ostream& out) { return -EOPNOTSUPP; }
+
   void set_wait_on_full(bool b) { wait_on_full = b; }
 
   // writes
index eae3c31052490e8a1904c803b33f82e782cd8cbc..fa43ceed145772b33b8af09e4c3919cfc76a1d10 100644 (file)
@@ -674,6 +674,8 @@ public:
   virtual void flush() {}
   virtual void sync_and_flush() {}
 
+  virtual int dump_journal(ostream& out) { return -EOPNOTSUPP; }
+
   virtual int snapshot(const string& name) { return -EOPNOTSUPP; }
     
   virtual void _fake_writes(bool b) {};
index 2ab453ec4b179f6401a5fa8407a8d68ce77841c6..4c7efcda9620732240fcaa0bf332f0dbcbcab0f2 100644 (file)
@@ -391,6 +391,16 @@ int OSD::flushjournal(const std::string &dev, const std::string &jdev)
   return err;
 }
 
+int OSD::dump_journal(const std::string &dev, const std::string &jdev, ostream& out)
+{
+  ObjectStore *store = create_object_store(dev, jdev);
+  if (!store)
+    return -ENOENT;
+  int err = store->dump_journal(out);
+  delete store;
+  return err;
+}
+
 int OSD::write_meta(const std::string &base, const std::string &file,
                    const char *val, size_t vallen)
 {
index e64f05c3e5c8d12b9e35309c3129d5856ff46035..55521e40cfe87ff9473a3fa3366de61dea50ec89 100644 (file)
@@ -1011,6 +1011,7 @@ protected:
                  uuid_d fsid, int whoami);
   static int mkjournal(const std::string &dev, const std::string &jdev);
   static int flushjournal(const std::string &dev, const std::string &jdev);
+  static int dump_journal(const std::string &dev, const std::string &jdev, ostream& out);
   /* remove any non-user xattrs from a map of them */
   void filter_xattrs(map<string, bufferptr>& attrs) {
     for (map<string, bufferptr>::iterator iter = attrs.begin();