Files
mongo/db/dur_journalimpl.h

104 lines
3.3 KiB
C
Raw Normal View History

2010-12-19 14:15:32 -05:00
// @file dur_journal.h
/**
* Copyright (C) 2010 10gen Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
2011-07-25 12:45:03 -04:00
#include "dur_journalformat.h"
#include "../util/logfile.h"
2010-12-19 14:15:32 -05:00
namespace mongo {
namespace dur {
/** the writeahead journal for durability */
2010-12-19 14:15:32 -05:00
class Journal {
public:
string dir; // set by journalMakeDir() during initialization
Journal();
/** call during startup by journalMakeDir() */
void init();
2011-07-25 12:45:03 -04:00
/** check if time to rotate files. assure a file is open.
done separately from the journal() call as we can do this part
outside of lock.
thread: durThread()
*/
void rotate();
/** append to the journal file
*/
2011-07-25 12:45:03 -04:00
void journal(const JSectHeader& h, const AlignedBuilder& b);
2010-12-19 14:15:32 -05:00
boost::filesystem::path getFilePathFor(int filenumber) const;
2010-12-19 14:15:32 -05:00
unsigned long long lastFlushTime() const { return _lastFlushTime; }
void cleanup(bool log); // closes and removes journal files
unsigned long long curFileId() const { return _curFileId; }
2011-02-07 13:48:32 -05:00
void assureLogFileOpen() {
SimpleMutex::scoped_lock lk(_curLogFileMutex);
2011-02-07 13:48:32 -05:00
if( _curLogFile == 0 )
_open();
}
/** open a journal file to journal operations to. */
void open();
2011-03-09 17:20:02 -05:00
private:
/** check if time to rotate files. assure a file is open.
* internally called with every commit
*/
void _rotate();
2010-12-19 14:15:32 -05:00
void _open();
void closeCurrentJournalFile();
void removeUnneededJournalFiles();
2010-12-19 14:15:32 -05:00
unsigned long long _written; // bytes written so far to the current journal (log) file
unsigned _nextFileNumber;
public:
SimpleMutex _curLogFileMutex;
bool _ageOut;
private:
LogFile *_curLogFile; // use _curLogFileMutex
unsigned long long _curFileId; // current file id see JHeader::fileId
2011-01-04 00:40:41 -05:00
struct JFile {
string filename;
2010-12-21 01:59:33 -05:00
unsigned long long lastEventTimeMs;
};
// files which have been closed but not unlinked (rotated out) yet
// ordered oldest to newest
list<JFile> _oldJournalFiles; // use _curLogFileMutex
2010-12-27 16:56:43 -05:00
// lsn related
static void preFlush();
static void postFlush();
2010-12-21 01:59:33 -05:00
unsigned long long _preFlushTime;
unsigned long long _lastFlushTime; // data < this time is fsynced in the datafiles (unless hard drive controller is caching)
2010-12-27 16:56:43 -05:00
bool _writeToLSNNeeded;
void updateLSNFile();
2010-12-19 14:15:32 -05:00
};
}
}