diff options
Diffstat (limited to 'src/mongo/db/storage/mmap_v1/durop.h')
-rw-r--r-- | src/mongo/db/storage/mmap_v1/durop.h | 165 |
1 files changed, 86 insertions, 79 deletions
diff --git a/src/mongo/db/storage/mmap_v1/durop.h b/src/mongo/db/storage/mmap_v1/durop.h index 9ebddb3dfc0..a798f210616 100644 --- a/src/mongo/db/storage/mmap_v1/durop.h +++ b/src/mongo/db/storage/mmap_v1/durop.h @@ -37,86 +37,93 @@ namespace mongo { - class AlignedBuilder; - - namespace dur { - - /** DurOp - Operations we journal that aren't just basic writes. - * - * Basic writes are logged as JEntry's, and indicated in ram temporarily as struct dur::WriteIntent. - * We don't make WriteIntent inherit from DurOp to keep it as lean as possible as there will be millions of - * them (we don't want a vtable for example there). - * - * For each op we want to journal, we define a subclass. - */ - class DurOp { /* copyable */ - public: - // @param opcode a sentinel value near max unsigned which uniquely identifies the operation. - // @see dur::JEntry - DurOp(unsigned opcode) : _opcode(opcode) { } - - virtual ~DurOp() { } - - /** serialize the op out to a builder which will then be written (presumably) to the journal */ - void serialize(AlignedBuilder& ab); - - /** read a durop from journal file referenced by br. - @param opcode the opcode which has already been written from the bufreader - */ - static std::shared_ptr<DurOp> read(unsigned opcode, BufReader& br); - - /** replay the operation (during recovery) - throws - - For now, these are not replayed during the normal WRITETODATAFILES phase, since these - operations are handled in other parts of the code. At some point this may change. - */ - virtual void replay() = 0; - - virtual std::string toString() = 0; - - /** if the op requires all file to be closed before doing its work, returns true. */ - virtual bool needFilesClosed() { return false; } - - protected: - /** DurOp will have already written the opcode for you */ - virtual void _serialize(AlignedBuilder& ab) = 0; - - private: - const unsigned _opcode; - }; - - /** indicates creation of a new file */ - class FileCreatedOp : public DurOp { - public: - FileCreatedOp(BufReader& log); - /** param f filename to create with path */ - FileCreatedOp(const std::string& f, unsigned long long l); - virtual void replay(); - virtual std::string toString(); - virtual bool needFilesClosed(); - protected: - virtual void _serialize(AlignedBuilder& ab); - private: - RelativePath _p; - unsigned long long _len; // size of file, not length of name - }; - - /** record drop of a database */ - class DropDbOp : public DurOp { - public: - DropDbOp(BufReader& log); - DropDbOp(const std::string& db) : - DurOp(JEntry::OpCode_DropDb), _db(db) { } - virtual void replay(); - virtual std::string toString() { return std::string("DropDbOp ") + _db; } - virtual bool needFilesClosed() { return true; } - protected: - virtual void _serialize(AlignedBuilder& ab); - private: - std::string _db; - }; +class AlignedBuilder; + +namespace dur { + +/** DurOp - Operations we journal that aren't just basic writes. + * + * Basic writes are logged as JEntry's, and indicated in ram temporarily as struct dur::WriteIntent. + * We don't make WriteIntent inherit from DurOp to keep it as lean as possible as there will be millions of + * them (we don't want a vtable for example there). + * + * For each op we want to journal, we define a subclass. + */ +class DurOp {/* copyable */ +public: + // @param opcode a sentinel value near max unsigned which uniquely identifies the operation. + // @see dur::JEntry + DurOp(unsigned opcode) : _opcode(opcode) {} + + virtual ~DurOp() {} + + /** serialize the op out to a builder which will then be written (presumably) to the journal */ + void serialize(AlignedBuilder& ab); + + /** read a durop from journal file referenced by br. + @param opcode the opcode which has already been written from the bufreader + */ + static std::shared_ptr<DurOp> read(unsigned opcode, BufReader& br); + + /** replay the operation (during recovery) + throws + + For now, these are not replayed during the normal WRITETODATAFILES phase, since these + operations are handled in other parts of the code. At some point this may change. + */ + virtual void replay() = 0; + + virtual std::string toString() = 0; + + /** if the op requires all file to be closed before doing its work, returns true. */ + virtual bool needFilesClosed() { + return false; + } +protected: + /** DurOp will have already written the opcode for you */ + virtual void _serialize(AlignedBuilder& ab) = 0; + +private: + const unsigned _opcode; +}; + +/** indicates creation of a new file */ +class FileCreatedOp : public DurOp { +public: + FileCreatedOp(BufReader& log); + /** param f filename to create with path */ + FileCreatedOp(const std::string& f, unsigned long long l); + virtual void replay(); + virtual std::string toString(); + virtual bool needFilesClosed(); + +protected: + virtual void _serialize(AlignedBuilder& ab); + +private: + RelativePath _p; + unsigned long long _len; // size of file, not length of name +}; + +/** record drop of a database */ +class DropDbOp : public DurOp { +public: + DropDbOp(BufReader& log); + DropDbOp(const std::string& db) : DurOp(JEntry::OpCode_DropDb), _db(db) {} + virtual void replay(); + virtual std::string toString() { + return std::string("DropDbOp ") + _db; + } + virtual bool needFilesClosed() { + return true; } +protected: + virtual void _serialize(AlignedBuilder& ab); + +private: + std::string _db; +}; +} } |