Storage Engine API
dur_journalimpl.h
Go to the documentation of this file.
1 // @file dur_journal.h
2 
31 #pragma once
32 
33 #include <boost/filesystem/path.hpp>
34 
38 #include "mongo/platform/atomic_word.h"
39 #include "mongo/stdx/mutex.h"
40 #include "mongo/util/concurrency/mutex.h"
41 
42 namespace mongo {
43 
44 class ClockSource;
45 
46 namespace dur {
47 
49 class Journal {
50 public:
51  std::string dir; // set by journalMakeDir() during initialization
52 
53  Journal();
54 
56  void init(ClockSource* cs, int64_t serverStartMs);
57 
63  void rotate();
64 
67  void journal(const JSectHeader& h, const AlignedBuilder& b);
68 
69  boost::filesystem::path getFilePathFor(int filenumber) const;
70 
71  void cleanup(bool log); // closes and removes journal files
72 
73  unsigned long long curFileId() const {
74  return _curFileId;
75  }
76 
78  stdx::lock_guard<SimpleMutex> lk(_curLogFileMutex);
79  if (_curLogFile == 0)
80  _open();
81  }
82 
84  void open();
85 
86 private:
90  void _rotate(unsigned long long lsnOfCurrentJournalEntry);
91 
92  void _open();
95 
96  unsigned long long _written = 0; // bytes written so far to the current journal (log) file
97  unsigned _nextFileNumber = 0;
98 
99  SimpleMutex _curLogFileMutex;
100 
101  LogFile* _curLogFile; // use _curLogFileMutex
102  unsigned long long _curFileId; // current file id see JHeader::fileId
103 
104  struct JFile {
105  std::string filename;
106  unsigned long long lastEventTimeMs;
107  };
108 
109  // files which have been closed but not unlinked (rotated out) yet
110  // ordered oldest to newest
111  std::list<JFile> _oldJournalFiles; // use _curLogFileMutex
112 
113  // lsn related
114  friend void setLastSeqNumberWrittenToSharedView(uint64_t seqNumber);
115  friend void notifyPreDataFileFlush();
116  friend void notifyPostDataFileFlush();
117  void updateLSNFile(unsigned long long lsnOfCurrentJournalEntry);
118  // data <= this time is in the shared view
120  // data <= this time was in the shared view when the last flush to start started
121  AtomicUInt64 _preFlushTime;
122  // data <= this time is fsynced in the datafiles (unless hard drive controller is caching)
123  AtomicUInt64 _lastFlushTime;
124  AtomicWord<bool> _writeToLSNNeeded;
125 
126  ClockSource* _clock;
127  int64_t _serverStartMs;
128 };
129 }
130 }
unsigned long long curFileId() const
Definition: dur_journalimpl.h:73
void open()
open a journal file to journal operations to.
Definition: dur_journal.cpp:558
friend void notifyPreDataFileFlush()
Call these before (pre) and after (post) the datafiles are flushed to disk by the DataFileSync thread...
Definition: dur_journal.cpp:680
void assureLogFileOpen()
Definition: dur_journalimpl.h:77
Definition: logfile.h:38
the writeahead journal for durability
Definition: dur_journalimpl.h:49
std::list< JFile > _oldJournalFiles
Definition: dur_journalimpl.h:111
Copyright (C) 2014 MongoDB Inc.
Definition: bson_collection_catalog_entry.cpp:38
AtomicUInt64 _preFlushTime
Definition: dur_journalimpl.h:121
AtomicUInt64 _lastSeqNumberWrittenToSharedView
Definition: dur_journalimpl.h:119
int64_t _serverStartMs
Definition: dur_journalimpl.h:127
void updateLSNFile(unsigned long long lsnOfCurrentJournalEntry)
remember "last sequence number" to speed recoveries concurrency: called by durThread only...
Definition: dur_journal.cpp:618
void init(ClockSource *cs, int64_t serverStartMs)
call during startup by journalMakeDir()
Definition: dur_journal.cpp:552
"Section" header.
Definition: dur_journalformat.h:91
friend void setLastSeqNumberWrittenToSharedView(uint64_t seqNumber)
Informs the journaling system that all writes on or before the passed in sequence number have been wr...
Definition: dur_journal.cpp:676
ClockSource * _clock
Definition: dur_journalimpl.h:126
void journal(const JSectHeader &h, const AlignedBuilder &b)
append to the journal file
Definition: dur_journal.cpp:766
void rotate()
check if time to rotate files.
unsigned long long _curFileId
Definition: dur_journalimpl.h:102
a page-aligned BufBuilder.
Definition: aligned_builder.h:37
friend void notifyPostDataFileFlush()
Definition: dur_journal.cpp:684
Journal()
Definition: dur_journal.cpp:197
void closeCurrentJournalFile()
Definition: dur_journal.cpp:690
std::string dir
Definition: dur_journalimpl.h:51
void cleanup(bool log)
Definition: dur_journal.cpp:273
std::string filename
Definition: dur_journalimpl.h:105
AtomicWord< bool > _writeToLSNNeeded
Definition: dur_journalimpl.h:124
LogFile * _curLogFile
Definition: dur_journalimpl.h:101
boost::filesystem::path getFilePathFor(int filenumber) const
Definition: dur_journal.cpp:204
void removeUnneededJournalFiles()
remove older journal files.
Definition: dur_journal.cpp:707
void _open()
Definition: dur_journal.cpp:514
SimpleMutex _curLogFileMutex
Definition: dur_journalimpl.h:99
AtomicUInt64 _lastFlushTime
Definition: dur_journalimpl.h:123
void _rotate(unsigned long long lsnOfCurrentJournalEntry)
check if time to rotate files.
Definition: dur_journal.cpp:727
unsigned _nextFileNumber
Definition: dur_journalimpl.h:97
Definition: dur_journalimpl.h:104
unsigned long long _written
Definition: dur_journalimpl.h:96
unsigned long long lastEventTimeMs
Definition: dur_journalimpl.h:106