From d8f79a52f2461d15849b5f363fd2079870a8e7d2 Mon Sep 17 00:00:00 2001 From: Dwight Date: Tue, 5 Apr 2011 15:59:28 -0400 Subject: [PATCH] compact faster --- db/compact.cpp | 14 ++++++++------ db/dur.cpp | 4 ++++ db/dur.h | 5 +++++ 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/db/compact.cpp b/db/compact.cpp index b701c3ec99d05..39d40dae308c9 100644 --- a/db/compact.cpp +++ b/db/compact.cpp @@ -98,11 +98,13 @@ namespace mongo { break; } - // remove the old record (orphan it) - e->firstRecord.writing() = L; - Record *r = L.rec(); - getDur().writingInt(r->prevOfs) = DiskLoc::NullOfs; - getDur().commitIfNeeded(); + // remove the old records (orphan them) periodically so our commit block doesn't get too large + if( getDur().aCommitIsNeeded() ) { + e->firstRecord.writing() = L; + Record *r = L.rec(); + getDur().writingInt(r->prevOfs) = DiskLoc::NullOfs; + getDur().commitIfNeeded(); + } } assert( d->firstExtent == ext ); @@ -112,7 +114,7 @@ namespace mongo { newFirst.ext()->xprev.writing().Null(); getDur().writing(e)->markEmpty(); freeExtents(ext,ext); - getDur().commitNow(); + getDur().commitIfNeeded(); log() << "compact " << nrecs << " documents " << totalSize/1000000.0 << "MB" << endl; } diff --git a/db/dur.cpp b/db/dur.cpp index 17d2b036a66bc..9edd32ed2ff22 100644 --- a/db/dur.cpp +++ b/db/dur.cpp @@ -240,6 +240,10 @@ namespace mongo { return p; } + bool DurableImpl::aCommitIsNeeded() const { + return commitJob.bytes() > UncommittedBytesLimit; + } + bool DurableImpl::commitIfNeeded() { DEV commitJob._nSinceCommitIfNeededCall = 0; if (commitJob.bytes() > UncommittedBytesLimit) { // should this also fire if CmdLine::DurAlwaysCommit? diff --git a/db/dur.h b/db/dur.h index a8035e4e7bcec..5917e8e8e7edb 100644 --- a/db/dur.h +++ b/db/dur.h @@ -100,6 +100,9 @@ namespace mongo { */ virtual bool commitIfNeeded() = 0; + /** @return true if time to commit but does NOT do a commit */ + virtual bool aCommitIsNeeded() const = 0; + /** Declare write intent for a DiskLoc. @see DiskLoc::writing() */ inline DiskLoc& writingDiskLoc(DiskLoc& d) { return *((DiskLoc*) writingPtr(&d, sizeof(d))); } @@ -174,6 +177,7 @@ namespace mongo { bool awaitCommit() { return false; } bool commitNow() { return false; } bool commitIfNeeded() { return false; } + bool aCommitIsNeeded() const { return false; } void setNoJournal(void *dst, void *src, unsigned len); void syncDataAndTruncateJournal() {} }; @@ -186,6 +190,7 @@ namespace mongo { void createdFile(string filename, unsigned long long len); bool awaitCommit(); bool commitNow(); + bool aCommitIsNeeded() const; bool commitIfNeeded(); void setNoJournal(void *dst, void *src, unsigned len); void syncDataAndTruncateJournal();