Skip to content

Commit

Permalink
SERVER-6808 RecoveryJob shouldn't find MMF for each journal entry
Browse files Browse the repository at this point in the history
  • Loading branch information
RedBeard0531 committed Aug 20, 2012
1 parent a781bbc commit 0ff6321
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 31 deletions.
73 changes: 44 additions & 29 deletions src/mongo/db/dur_recover.cpp
Expand Up @@ -214,34 +214,9 @@ namespace mongo {
_mmfs.clear();
}

void RecoveryJob::write(const ParsedJournalEntry& entry) {
void RecoveryJob::write(const ParsedJournalEntry& entry, MongoMMF* mmf) {
//TODO(mathias): look into making some of these dasserts
verify(entry.e);
verify(entry.dbName);
verify(strnlen(entry.dbName, MaxDatabaseNameLen) < MaxDatabaseNameLen);

const string fn = fileName(entry.dbName, entry.e->getFileNo());
MongoFile* file;
{
MongoFileFinder finder; // must release lock before creating new MongoMMF
file = finder.findByPath(fn);
}

MongoMMF* mmf;
if (file) {
verify(file->isMongoMMF());
mmf = (MongoMMF*)file;
}
else {
if( !_recovering ) {
log() << "journal error applying writes, file " << fn << " is not open" << endl;
verify(false);
}
boost::shared_ptr<MongoMMF> sp (new MongoMMF);
verify(sp->open(fn, false));
_mmfs.push_back(sp);
mmf = sp.get();
}

if ((entry.e->ofs + entry.e->len) <= mmf->length()) {
verify(mmf->view_write());
Expand All @@ -256,7 +231,7 @@ namespace mongo {
}
}

void RecoveryJob::applyEntry(const ParsedJournalEntry& entry, bool apply, bool dump) {
void RecoveryJob::applyEntry(const ParsedJournalEntry& entry, bool apply, bool dump, MongoMMF* mmf) {
if( entry.e ) {
if( dump ) {
stringstream ss;
Expand All @@ -270,7 +245,7 @@ namespace mongo {
log() << ss.str() << endl;
}
if( apply ) {
write(entry);
write(entry, mmf);
}
}
else if(entry.op) {
Expand All @@ -287,14 +262,54 @@ namespace mongo {
}
}

MongoMMF* RecoveryJob::getMongoMMF(const ParsedJournalEntry& entry) {
verify(entry.dbName);
verify(strnlen(entry.dbName, MaxDatabaseNameLen) < MaxDatabaseNameLen);

const string fn = fileName(entry.dbName, entry.e->getFileNo());
MongoFile* file;
{
MongoFileFinder finder; // must release lock before creating new MongoMMF
file = finder.findByPath(fn);
}

MongoMMF* mmf;
if (file) {
verify(file->isMongoMMF());
mmf = (MongoMMF*)file;
}
else {
if( !_recovering ) {
log() << "journal error applying writes, file " << fn << " is not open" << endl;
verify(false);
}
boost::shared_ptr<MongoMMF> sp (new MongoMMF);
verify(sp->open(fn, false));
_mmfs.push_back(sp);
mmf = sp.get();
}

return mmf;
}

void RecoveryJob::applyEntries(const vector<ParsedJournalEntry> &entries) {
bool apply = (cmdLine.durOptions & CmdLine::DurScanOnly) == 0;
bool dump = cmdLine.durOptions & CmdLine::DurDumpJournal;
if( dump )
log() << "BEGIN section" << endl;

const char* lastDbName = NULL;
int lastFileNo = 0;
MongoMMF* mmf = NULL;
for( vector<ParsedJournalEntry>::const_iterator i = entries.begin(); i != entries.end(); ++i ) {
applyEntry(*i, apply, dump);
if (i->e && (i->dbName != lastDbName || i->e->getFileNo() != lastFileNo)) {
mmf = getMongoMMF(*i);
lastDbName = i->dbName;
lastFileNo = i->e->getFileNo();
}
fassert(16429, !i->e || mmf);

applyEntry(*i, apply, dump, mmf);
}

if( dump )
Expand Down
5 changes: 3 additions & 2 deletions src/mongo/db/dur_recover.h
Expand Up @@ -28,12 +28,13 @@ namespace mongo {

static RecoveryJob & get() { return _instance; }
private:
void write(const ParsedJournalEntry& entry); // actually writes to the file
void applyEntry(const ParsedJournalEntry& entry, bool apply, bool dump);
void write(const ParsedJournalEntry& entry, MongoMMF* mmf); // actually writes to the file
void applyEntry(const ParsedJournalEntry& entry, bool apply, bool dump, MongoMMF* mmf);
void applyEntries(const vector<ParsedJournalEntry> &entries);
bool processFileBuffer(const void *, unsigned len);
bool processFile(boost::filesystem::path journalfile);
void _close(); // doesn't lock
MongoMMF* getMongoMMF(const ParsedJournalEntry& entry);

list<boost::shared_ptr<MongoMMF> > _mmfs;

Expand Down

0 comments on commit 0ff6321

Please sign in to comment.