0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-12-01 09:32:32 +01:00

get rid of TempDisableDurability and replace with syncDataAndTruncateJournal

This commit is contained in:
Mathias Stearn 2011-01-12 15:54:31 -05:00
parent 1bc1c3cc3a
commit b4094b20bb
3 changed files with 24 additions and 30 deletions

View File

@ -588,27 +588,14 @@ namespace mongo {
boost::thread t(durThread);
}
TempDisableDurability::TempDisableDurability() : _wasDur(cmdLine.dur), _lock(durThreadMutex) {
void DurableImpl::syncDataAndTruncateJournal() {
dbMutex.assertWriteLocked();
if (_wasDur) {
groupCommit();
DurableInterface::disableDurability();
cmdLine.dur = false;
groupCommit();
MongoFile::flushAll(true);
journalCleanup();
//SyncAndTruncate;
MongoFile::flushAll(true);
journalCleanup();
}
}
TempDisableDurability::~TempDisableDurability() {
dbMutex.assertWriteLocked();
if (_wasDur) {
assert(!haveJournalFiles());
cmdLine.dur = true;
DurableInterface::enableDurability();
}
assert(!haveJournalFiles()); // Double check post-conditions
}
} // namespace dur

View File

@ -24,15 +24,6 @@ namespace mongo {
*/
void startup();
class TempDisableDurability : boost::noncopyable {
public:
TempDisableDurability(); // disables durability and SyncAndTruncate iff it is enabled
~TempDisableDurability(); // enables durability iff constructor disabled it
private:
const bool _wasDur;
scoped_lock _lock;
};
class DurableInterface : boost::noncopyable {
public:
virtual ~DurableInterface() { log() << "ERROR warning ~DurableInterface not intended to be called" << endl; }
@ -140,6 +131,15 @@ namespace mongo {
*/
virtual void setNoJournal(void *dst, void *src, unsigned len) = 0;
/** Commits pending changes, flushes all changes to main data
files, then removes the journal.
This is useful as a "barrier" to ensure that writes before this
call will never go through recovery and be applied to files
that have had changes made after this call applied.
*/
virtual void syncDataAndTruncateJournal() = 0;
static DurableInterface& getDur() { return *_impl; }
private:
@ -172,6 +172,7 @@ namespace mongo {
bool commitNow() { return false; }
void commitIfNeeded() { }
void setNoJournal(void *dst, void *src, unsigned len);
void syncDataAndTruncateJournal() {}
};
class DurableImpl : public DurableInterface {
@ -184,6 +185,7 @@ namespace mongo {
bool commitNow();
void commitIfNeeded();
void setNoJournal(void *dst, void *src, unsigned len);
void syncDataAndTruncateJournal();
};
} // namespace dur

View File

@ -1756,11 +1756,11 @@ namespace mongo {
BackgroundOperation::assertNoBgOpInProgForDb(d->name.c_str());
getDur().syncDataAndTruncateJournal();
Database::closeDatabase( d->name.c_str(), d->path );
d = 0; // d is now deleted
dur::TempDisableDurability holder; //does SyncAndTruncate
_deleteDataFiles( db.c_str() );
}
@ -1894,7 +1894,7 @@ namespace mongo {
BackgroundOperation::assertNoBgOpInProgForDb(dbName);
dur::TempDisableDurability holder; // SyncAndTruncate before computing freeSpace
getDur().syncDataAndTruncateJournal(); // Must be done before and after repair
boost::intmax_t totalSize = dbSize( dbName );
boost::intmax_t freeSize = freeSpace( repairpath );
@ -1928,6 +1928,9 @@ namespace mongo {
problem() << "clone failed for " << dbName << " with error: " << errmsg << endl;
if ( !preserveClonedFilesOnFailure )
BOOST_CHECK_EXCEPTION( boost::filesystem::remove_all( reservedPath ) );
getDur().syncDataAndTruncateJournal(); // Must be done before and after repair
return false;
}
@ -1949,6 +1952,8 @@ namespace mongo {
if ( !backupOriginalFiles )
BOOST_CHECK_EXCEPTION( boost::filesystem::remove_all( reservedPath ) );
getDur().syncDataAndTruncateJournal(); // Must be done before and after repair
return true;
}