00001 // @file durop.h class DurOp and descendants 00002 00019 #pragma once 00020 00021 #include "dur_journalformat.h" 00022 #include "../util/bufreader.h" 00023 #include "../util/paths.h" 00024 00025 namespace mongo { 00026 00027 class AlignedBuilder; 00028 00029 namespace dur { 00030 00031 const unsigned Alignment = 8192; 00032 00041 class DurOp { /* copyable */ 00042 public: 00043 // @param opcode a sentinel value near max unsigned which uniquely identifies the operation. 00044 // @see dur::JEntry 00045 DurOp(unsigned opcode) : _opcode(opcode) { } 00046 00047 virtual ~DurOp() { } 00048 00050 void serialize(AlignedBuilder& ab); 00051 00055 static shared_ptr<DurOp> read(unsigned opcode, BufReader& br); 00056 00063 virtual void replay() = 0; 00064 00065 virtual string toString() = 0; 00066 00068 virtual bool needFilesClosed() { return false; } 00069 00070 protected: 00072 virtual void _serialize(AlignedBuilder& ab) = 0; 00073 00074 private: 00075 const unsigned _opcode; 00076 }; 00077 00079 class FileCreatedOp : public DurOp { 00080 public: 00081 FileCreatedOp(BufReader& log); 00083 FileCreatedOp(string f, unsigned long long l); 00084 virtual void replay(); 00085 virtual string toString(); 00086 virtual bool needFilesClosed(); 00087 protected: 00088 virtual void _serialize(AlignedBuilder& ab); 00089 private: 00090 RelativePath _p; 00091 unsigned long long _len; // size of file, not length of name 00092 }; 00093 00095 class DropDbOp : public DurOp { 00096 public: 00097 DropDbOp(BufReader& log); 00098 DropDbOp(string db) : 00099 DurOp(JEntry::OpCode_DropDb), _db(db) { } 00100 virtual void replay(); 00101 virtual string toString() { return string("DropDbOp ") + _db; } 00102 virtual bool needFilesClosed() { return true; } 00103 protected: 00104 virtual void _serialize(AlignedBuilder& ab); 00105 private: 00106 string _db; 00107 }; 00108 00109 } 00110 00111 }