00001 // @file dur_journal.h 00002 00019 #pragma once 00020 00021 #include "../util/logfile.h" 00022 00023 namespace mongo { 00024 namespace dur { 00025 00027 class Journal { 00028 public: 00029 string dir; // set by journalMakeDir() during initialization 00030 00031 Journal(); 00032 00034 void init(); 00035 00041 void rotate(); 00042 00045 void journal(const AlignedBuilder& b); 00046 00047 boost::filesystem::path getFilePathFor(int filenumber) const; 00048 00049 unsigned long long lastFlushTime() const { return _lastFlushTime; } 00050 void cleanup(); 00051 00052 // Rotate after reaching this data size in a journal (j._<n>) file 00053 // We use a smaller size for 32 bit as the journal is mmapped during recovery (only) 00054 // Note if you take a set of datafiles, including journal files, from 32->64 or vice-versa, it must 00055 // work. (and should as-is) 00056 static const unsigned long long DataLimit = (sizeof(void*)==4) ? 256 * 1024 * 1024 : 1 * 1024 * 1024 * 1024; 00057 00058 unsigned long long curFileId() const { return _curFileId; } 00059 00060 void assureLogFileOpen() { 00061 mutex::scoped_lock lk(_curLogFileMutex); 00062 if( _curLogFile == 0 ) 00063 _open(); 00064 } 00065 00067 void open(); 00068 00069 private: 00070 void _open(); 00071 void closeCurrentJournalFile(); 00072 void removeUnneededJournalFiles(); 00073 00074 unsigned long long _written; // bytes written so far to the current journal (log) file 00075 unsigned _nextFileNumber; 00076 00077 mutex _curLogFileMutex; 00078 00079 LogFile *_curLogFile; // use _curLogFileMutex 00080 unsigned long long _curFileId; // current file id see JHeader::fileId 00081 00082 struct JFile { 00083 string filename; 00084 unsigned long long lastEventTimeMs; 00085 }; 00086 00087 // files which have been closed but not unlinked (rotated out) yet 00088 // ordered oldest to newest 00089 list<JFile> _oldJournalFiles; // use _curLogFileMutex 00090 00091 // lsn related 00092 static void preFlush(); 00093 static void postFlush(); 00094 unsigned long long _preFlushTime; 00095 unsigned long long _lastFlushTime; // data < this time is fsynced in the datafiles (unless hard drive controller is caching) 00096 bool _writeToLSNNeeded; 00097 void updateLSNFile(); 00098 }; 00099 00100 } 00101 }