From 580c28ae97065cc478bef8c71b2f3abf89eeae7d Mon Sep 17 00:00:00 2001 From: sageweil Date: Wed, 25 Oct 2006 18:17:24 +0000 Subject: [PATCH] event fun git-svn-id: https://ceph.svn.sf.net/svnroot/ceph@947 29311d96-e01e-0410-9327-a35deaab8ce9 --- ceph/mds/LogEvent.h | 2 - ceph/mds/events/EAlloc.h | 111 ++++++++++++++++++--------------- ceph/mds/events/EDirUpdate.h | 73 +++++++++++++--------- ceph/mds/events/EInodeUpdate.h | 103 +++++++++++++++++------------- ceph/mds/events/EString.h | 30 +++++++-- ceph/mds/events/ETraced.h | 84 +++++++++++++++++++++++++ ceph/mds/events/EUnlink.h | 73 +++++++++++++--------- 7 files changed, 314 insertions(+), 162 deletions(-) create mode 100644 ceph/mds/events/ETraced.h diff --git a/ceph/mds/LogEvent.h b/ceph/mds/LogEvent.h index b2f29735d8d6f..410f2953a44a0 100644 --- a/ceph/mds/LogEvent.h +++ b/ceph/mds/LogEvent.h @@ -11,8 +11,6 @@ * */ - - #ifndef __LOGEVENT_H #define __LOGEVENT_H diff --git a/ceph/mds/events/EAlloc.h b/ceph/mds/events/EAlloc.h index 9959e5704bfbe..049a20e13ab12 100644 --- a/ceph/mds/events/EAlloc.h +++ b/ceph/mds/events/EAlloc.h @@ -1,5 +1,18 @@ -#ifndef __EALLOC_H -#define __EALLOC_H +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +/* + * Ceph - scalable distributed file system + * + * Copyright (C) 2004-2006 Sage Weil + * + * This is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software + * Foundation. See file COPYING. + * + */ + +#ifndef __MDS_EALLOC_H +#define __MDS_EALLOC_H #include #include "config.h" @@ -21,75 +34,75 @@ class EAlloc : public LogEvent { public: EAlloc() : LogEvent(EVENT_ALLOC) { } EAlloc(int idtype, idno_t id, int what, version_t v) : - LogEvent(EVENT_ALLOC) { - this->idtype = idtype; - this->id = id; - this->what = what; - this->table_version = v; + LogEvent(EVENT_ALLOC) { + this->idtype = idtype; + this->id = id; + this->what = what; + this->table_version = v; } void encode_payload(bufferlist& bl) { - bl.append((char*)&idtype, sizeof(idtype)); - bl.append((char*)&id, sizeof(id)); - bl.append((char*)&what, sizeof(what)); - bl.append((char*)&table_version, sizeof(table_version)); + bl.append((char*)&idtype, sizeof(idtype)); + bl.append((char*)&id, sizeof(id)); + bl.append((char*)&what, sizeof(what)); + bl.append((char*)&table_version, sizeof(table_version)); } void decode_payload(bufferlist& bl, int& off) { - bl.copy(off, sizeof(idtype), (char*)&idtype); - off += sizeof(idtype); - bl.copy(off, sizeof(id), (char*)&id); - off += sizeof(id); - bl.copy(off, sizeof(what), (char*)&what); - off += sizeof(what); - bl.copy(off, sizeof(table_version), (char*)&table_version); - off += sizeof(table_version); + bl.copy(off, sizeof(idtype), (char*)&idtype); + off += sizeof(idtype); + bl.copy(off, sizeof(id), (char*)&id); + off += sizeof(id); + bl.copy(off, sizeof(what), (char*)&what); + off += sizeof(what); + bl.copy(off, sizeof(table_version), (char*)&table_version); + off += sizeof(table_version); } void print(ostream& out) { - if (what == EALLOC_EV_ALLOC) - out << "alloc " << hex << id << dec << " tablev " << table_version; - else - out << "dealloc " << hex << id << dec << " tablev " << table_version; + if (what == EALLOC_EV_ALLOC) + out << "alloc " << hex << id << dec << " tablev " << table_version; + else + out << "dealloc " << hex << id << dec << " tablev " << table_version; } // live journal bool can_expire(MDS *mds) { - if (mds->idalloc->get_committed_version() <= table_version) - return false; // still dirty - else - return true; // already flushed + if (mds->idalloc->get_committed_version() <= table_version) + return false; // still dirty + else + return true; // already flushed } - + void retire(MDS *mds, Context *c) { - mds->idalloc->save(c, table_version); + mds->idalloc->save(c, table_version); } - - + + // recovery bool has_happened(MDS *mds) { - if (mds->idalloc->get_version() >= table_version) { - cout << " event " << table_version << " <= table " << mds->idalloc->get_version() << endl; - return true; - } else - return false; + if (mds->idalloc->get_version() >= table_version) { + cout << " event " << table_version << " <= table " << mds->idalloc->get_version() << endl; + return true; + } else + return false; } void replay(MDS *mds) { - assert(table_version-1 == mds->idalloc->get_version()); - - if (what == EALLOC_EV_ALLOC) { - idno_t nid = mds->idalloc->alloc_id(true); - assert(nid == id); // this should match. - } - else if (what == EALLOC_EV_FREE) { - mds->idalloc->reclaim_id(id, true); - } - else - assert(0); - - assert(table_version == mds->idalloc->get_version()); + assert(table_version-1 == mds->idalloc->get_version()); + + if (what == EALLOC_EV_ALLOC) { + idno_t nid = mds->idalloc->alloc_id(true); + assert(nid == id); // this should match. + } + else if (what == EALLOC_EV_FREE) { + mds->idalloc->reclaim_id(id, true); + } + else + assert(0); + + assert(table_version == mds->idalloc->get_version()); } }; diff --git a/ceph/mds/events/EDirUpdate.h b/ceph/mds/events/EDirUpdate.h index 9c90a518b4204..6411a0d37d8fe 100644 --- a/ceph/mds/events/EDirUpdate.h +++ b/ceph/mds/events/EDirUpdate.h @@ -1,3 +1,16 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +/* + * Ceph - scalable distributed file system + * + * Copyright (C) 2004-2006 Sage Weil + * + * This is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software + * Foundation. See file COPYING. + * + */ + #ifndef __EDIRUPDATE_H #define __EDIRUPDATE_H @@ -18,55 +31,55 @@ class EDirUpdate : public LogEvent { public: EDirUpdate(CDir *dir) : - LogEvent(EVENT_DIRUPDATE) { - this->dirino = dir->ino(); - version = dir->get_version(); + LogEvent(EVENT_DIRUPDATE) { + this->dirino = dir->ino(); + version = dir->get_version(); } EDirUpdate() : - LogEvent(EVENT_DIRUPDATE) { + LogEvent(EVENT_DIRUPDATE) { } virtual void encode_payload(bufferlist& bl) { - bl.append((char*)&version, sizeof(version)); - bl.append((char*)&dirino, sizeof(dirino)); + bl.append((char*)&version, sizeof(version)); + bl.append((char*)&dirino, sizeof(dirino)); } void decode_payload(bufferlist& bl, int& off) { - bl.copy(off, sizeof(version), (char*)&version); - off += sizeof(version); - bl.copy(off, sizeof(dirino), (char*)&dirino); - off += sizeof(dirino); + bl.copy(off, sizeof(version), (char*)&version); + off += sizeof(version); + bl.copy(off, sizeof(dirino), (char*)&dirino); + off += sizeof(dirino); } virtual bool can_expire(MDS *mds) { - // am i obsolete? - CInode *in = mds->mdcache->get_inode(dirino); - if (!in) return true; - CDir *dir = in->dir; - if (!dir) return true; + // am i obsolete? + CInode *in = mds->mdcache->get_inode(dirino); + if (!in) return true; + CDir *dir = in->dir; + if (!dir) return true; - dout(10) << "EDirUpdate v " << version << " on dir " << *dir << endl; + dout(10) << "EDirUpdate v " << version << " on dir " << *dir << endl; - if (!dir->is_auth()) return true; // not mine! - if (dir->is_frozen()) return true; // frozen -> exporting -> obsolete? FIXME - - if (!dir->is_dirty()) return true; + if (!dir->is_auth()) return true; // not mine! + if (dir->is_frozen()) return true; // frozen -> exporting -> obsolete? FIXME + + if (!dir->is_dirty()) return true; - if (dir->get_committing_version() > version) - return true; + if (dir->get_committing_version() > version) + return true; - return false; + return false; } virtual void retire(MDS *mds, Context *c) { - // commit directory - CInode *in = mds->mdcache->get_inode(dirino); - assert(in); - CDir *dir = in->dir; - assert(dir); + // commit directory + CInode *in = mds->mdcache->get_inode(dirino); + assert(in); + CDir *dir = in->dir; + assert(dir); - dout(10) << "EDirUpdate committing dir " << *dir << endl; - mds->mdstore->commit_dir(dir, c); + dout(10) << "EDirUpdate committing dir " << *dir << endl; + mds->mdstore->commit_dir(dir, c); } }; diff --git a/ceph/mds/events/EInodeUpdate.h b/ceph/mds/events/EInodeUpdate.h index 3601c6960cd23..8220760ac11c5 100644 --- a/ceph/mds/events/EInodeUpdate.h +++ b/ceph/mds/events/EInodeUpdate.h @@ -1,3 +1,16 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +/* + * Ceph - scalable distributed file system + * + * Copyright (C) 2004-2006 Sage Weil + * + * This is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software + * Foundation. See file COPYING. + * + */ + #ifndef __EINODEUPDATE_H #define __EINODEUPDATE_H @@ -18,70 +31,70 @@ class EInodeUpdate : public LogEvent { public: EInodeUpdate(CInode *in) : - LogEvent(EVENT_INODEUPDATE) { - this->inode = in->inode; - version = in->get_version(); + LogEvent(EVENT_INODEUPDATE) { + this->inode = in->inode; + version = in->get_version(); } EInodeUpdate() : - LogEvent(EVENT_INODEUPDATE) { + LogEvent(EVENT_INODEUPDATE) { } virtual void encode_payload(bufferlist& bl) { - bl.append((char*)&version, sizeof(version)); - bl.append((char*)&inode, sizeof(inode)); + bl.append((char*)&version, sizeof(version)); + bl.append((char*)&inode, sizeof(inode)); } void decode_payload(bufferlist& bl, int& off) { - bl.copy(off, sizeof(version), (char*)&version); - off += sizeof(version); - bl.copy(off, sizeof(inode), (char*)&inode); - off += sizeof(inode); + bl.copy(off, sizeof(version), (char*)&version); + off += sizeof(version); + bl.copy(off, sizeof(inode), (char*)&inode); + off += sizeof(inode); } bool can_expire(MDS *mds) { - // am i obsolete? - CInode *in = mds->mdcache->get_inode(inode.ino); + // am i obsolete? + CInode *in = mds->mdcache->get_inode(inode.ino); - //assert(in); - if (!in) { - dout(7) << "inode " << inode.ino << " not in cache, must have exported" << endl; - return true; - } - dout(7) << "EInodeUpdate obsolete? on " << *in << endl; - if (!in->is_auth()) - return true; // not my inode anymore! - if (in->get_version() != version) - return true; // i'm obsolete! (another log entry follows) + //assert(in); + if (!in) { + dout(7) << "inode " << inode.ino << " not in cache, must have exported" << endl; + return true; + } + dout(7) << "EInodeUpdate obsolete? on " << *in << endl; + if (!in->is_auth()) + return true; // not my inode anymore! + if (in->get_version() != version) + return true; // i'm obsolete! (another log entry follows) - CDir *parent = in->get_parent_dir(); - if (!parent) return true; // root? - if (!parent->is_dirty()) return true; // dir is clean! + CDir *parent = in->get_parent_dir(); + if (!parent) return true; // root? + if (!parent->is_dirty()) return true; // dir is clean! - // frozen -> exporting -> obsolete (FOR NOW?) - if (in->is_frozen()) - return true; + // frozen -> exporting -> obsolete (FOR NOW?) + if (in->is_frozen()) + return true; - return false; + return false; } virtual void retire(MDS *mds, Context *c) { - // commit my containing directory - CInode *in = mds->mdcache->get_inode(inode.ino); - assert(in); - CDir *parent = in->get_parent_dir(); + // commit my containing directory + CInode *in = mds->mdcache->get_inode(inode.ino); + assert(in); + CDir *parent = in->get_parent_dir(); - if (parent) { - // okay! - dout(7) << "commiting containing dir for " << *in << ", which is " << *parent << endl; - mds->mdstore->commit_dir(parent, c); - } else { - // oh, i'm the root inode - dout(7) << "don't know how to commit the root inode" << endl; - if (c) { - c->finish(0); - delete c; - } - } + if (parent) { + // okay! + dout(7) << "commiting containing dir for " << *in << ", which is " << *parent << endl; + mds->mdstore->commit_dir(parent, c); + } else { + // oh, i'm the root inode + dout(7) << "don't know how to commit the root inode" << endl; + if (c) { + c->finish(0); + delete c; + } + } } diff --git a/ceph/mds/events/EString.h b/ceph/mds/events/EString.h index face114bfea27..6bd10030549ba 100644 --- a/ceph/mds/events/EString.h +++ b/ceph/mds/events/EString.h @@ -1,3 +1,16 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +/* + * Ceph - scalable distributed file system + * + * Copyright (C) 2004-2006 Sage Weil + * + * This is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software + * Foundation. See file COPYING. + * + */ + #ifndef __ESTRING_H #define __ESTRING_H @@ -15,21 +28,26 @@ class EString : public LogEvent { public: EString(string e) : - LogEvent(EVENT_STRING) { - event = e; + LogEvent(EVENT_STRING) { + event = e; } EString() : - LogEvent(EVENT_STRING) { + LogEvent(EVENT_STRING) { } void decode_payload(bufferlist& bl, int& off) { - event = bl.c_str() + off; - off += event.length() + 1; + event = bl.c_str() + off; + off += event.length() + 1; } void encode_payload(bufferlist& bl) { - bl.append(event.c_str(), event.length()+1); + bl.append(event.c_str(), event.length()+1); + } + + void print(ostream& out) { + out << '"' << event << '"'; } + }; #endif diff --git a/ceph/mds/events/ETraced.h b/ceph/mds/events/ETraced.h new file mode 100644 index 0000000000000..de1347dcdfd99 --- /dev/null +++ b/ceph/mds/events/ETraced.h @@ -0,0 +1,84 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +/* + * Ceph - scalable distributed file system + * + * Copyright (C) 2004-2006 Sage Weil + * + * This is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software + * Foundation. See file COPYING. + * + */ + + +#ifndef __MDS_ETRACED_H +#define __MDS_ETRACED_H + +#include +#include +using namespace std; + +#include "../LogEvent.h" + +// generic log event +class ETraced : public LogEvent { + struct bit { + inodeno_t dirino; + version_t dirv; + string dn; + inodeno_t ino; + version_t inov; + + bit() {} + bit(inodeno_t di, version_t dv, string& d, inodeno_t i, version_t iv) : + dirino(di), dirv(dv), dn(d), ino(i), inov(iv) {} + + void _encode(bufferlist& bl) { + bl.append((char*)&dirino, sizeof(dirino)); + bl.append((char*)&dirv, sizeof(dirv)); + ::_encode(dn,bl); + bl.append((char*)&ino, sizeof(ino)); + bl.append((char*)&inov, sizeof(inov)); + } + void _decode(bufferlist& bl, int& off) { + bl.copy(off, sizeof(dirino), (char*)&dirino); off += sizeof(dirino); + bl.copy(off, sizeof(dirv), (char*)&dirv); off += sizeof(dirv); + ::_decode(dn, bl, off); + bl.copy(off, sizeof(ino), (char*)&ino); off += sizeof(ino); + bl.copy(off, sizeof(inov), (char*)&inov); off += sizeof(inov); + } + }; + + protected: + list trace; + + public: + ETraced(int t) : LogEvent(t) { } + + void decode_trace(bufferlist& bl, int& off) { + int n; + bl.copy(off, sizeof(n), (char*)&n); + off += n; + for (int i=0; i::iterator i = trace.begin(); + i != trace.end(); + i++) + i->_encode(bl); + } + + void print(ostream& out) { + out << '"' << event << '"'; + } + +}; + +#endif diff --git a/ceph/mds/events/EUnlink.h b/ceph/mds/events/EUnlink.h index 874440280f1f4..ccea623bfebff 100644 --- a/ceph/mds/events/EUnlink.h +++ b/ceph/mds/events/EUnlink.h @@ -1,3 +1,16 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +/* + * Ceph - scalable distributed file system + * + * Copyright (C) 2004-2006 Sage Weil + * + * This is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software + * Foundation. See file COPYING. + * + */ + #ifndef __EUNLINK_H #define __EUNLINK_H @@ -19,53 +32,53 @@ class EUnlink : public LogEvent { public: EUnlink(CDir *dir, CDentry* dn) : - LogEvent(EVENT_UNLINK) { - this->dir_ino = dir->ino(); - this->dname = dn->get_name(); - this->version = dir->get_version(); + LogEvent(EVENT_UNLINK) { + this->dir_ino = dir->ino(); + this->dname = dn->get_name(); + this->version = dir->get_version(); } EUnlink() : - LogEvent(EVENT_UNLINK) { + LogEvent(EVENT_UNLINK) { } virtual void encode_payload(bufferlist& bl) { - bl.append((char*)&dir_ino, sizeof(dir_ino)); - bl.append((char*)&version, sizeof(version)); - bl.append((char*)dname.c_str(), dname.length() + 1); + bl.append((char*)&dir_ino, sizeof(dir_ino)); + bl.append((char*)&version, sizeof(version)); + bl.append((char*)dname.c_str(), dname.length() + 1); } void decode_payload(bufferlist& bl, int& off) { - bl.copy(off, sizeof(dir_ino), (char*)&dir_ino); - off += sizeof(dir_ino); - bl.copy(off, sizeof(version), (char*)&version); - off += sizeof(version); - dname = bl.c_str() + off; - off += dname.length() + 1; + bl.copy(off, sizeof(dir_ino), (char*)&dir_ino); + off += sizeof(dir_ino); + bl.copy(off, sizeof(version), (char*)&version); + off += sizeof(version); + dname = bl.c_str() + off; + off += dname.length() + 1; } virtual bool can_expire(MDS *mds) { - // am i obsolete? - CInode *idir = mds->mdcache->get_inode(dir_ino); - if (!idir) return true; + // am i obsolete? + CInode *idir = mds->mdcache->get_inode(dir_ino); + if (!idir) return true; - CDir *dir = idir->dir; + CDir *dir = idir->dir; - if (!dir) return true; + if (!dir) return true; - if (!idir->dir->is_auth()) return true; - if (idir->dir->is_clean()) return true; + if (!idir->dir->is_auth()) return true; + if (idir->dir->is_clean()) return true; - if (idir->dir->get_last_committed_version() >= version) return true; - return false; + if (idir->dir->get_last_committed_version() >= version) return true; + return false; } virtual void retire(MDS *mds, Context *c) { - // commit my containing directory - CDir *dir = mds->mdcache->get_inode(dir_ino)->dir; - assert(dir); - - // okay! - dout(7) << "commiting dirty (from unlink) dir " << *dir << endl; - mds->mdstore->commit_dir(dir, version, c); + // commit my containing directory + CDir *dir = mds->mdcache->get_inode(dir_ino)->dir; + assert(dir); + + // okay! + dout(7) << "commiting dirty (from unlink) dir " << *dir << endl; + mds->mdstore->commit_dir(dir, version, c); } }; -- 2.39.5