Skip to content

Commit

Permalink
compact faster
Browse files Browse the repository at this point in the history
  • Loading branch information
dwight committed Apr 5, 2011
1 parent b40989e commit d8f79a5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
14 changes: 8 additions & 6 deletions db/compact.cpp
Expand Up @@ -98,11 +98,13 @@ namespace mongo {
break; break;
} }


// remove the old record (orphan it) // remove the old records (orphan them) periodically so our commit block doesn't get too large
e->firstRecord.writing() = L; if( getDur().aCommitIsNeeded() ) {
Record *r = L.rec(); e->firstRecord.writing() = L;
getDur().writingInt(r->prevOfs) = DiskLoc::NullOfs; Record *r = L.rec();
getDur().commitIfNeeded(); getDur().writingInt(r->prevOfs) = DiskLoc::NullOfs;
getDur().commitIfNeeded();
}
} }


assert( d->firstExtent == ext ); assert( d->firstExtent == ext );
Expand All @@ -112,7 +114,7 @@ namespace mongo {
newFirst.ext()->xprev.writing().Null(); newFirst.ext()->xprev.writing().Null();
getDur().writing(e)->markEmpty(); getDur().writing(e)->markEmpty();
freeExtents(ext,ext); freeExtents(ext,ext);
getDur().commitNow(); getDur().commitIfNeeded();


log() << "compact " << nrecs << " documents " << totalSize/1000000.0 << "MB" << endl; log() << "compact " << nrecs << " documents " << totalSize/1000000.0 << "MB" << endl;
} }
Expand Down
4 changes: 4 additions & 0 deletions db/dur.cpp
Expand Up @@ -240,6 +240,10 @@ namespace mongo {
return p; return p;
} }


bool DurableImpl::aCommitIsNeeded() const {
return commitJob.bytes() > UncommittedBytesLimit;
}

bool DurableImpl::commitIfNeeded() { bool DurableImpl::commitIfNeeded() {
DEV commitJob._nSinceCommitIfNeededCall = 0; DEV commitJob._nSinceCommitIfNeededCall = 0;
if (commitJob.bytes() > UncommittedBytesLimit) { // should this also fire if CmdLine::DurAlwaysCommit? if (commitJob.bytes() > UncommittedBytesLimit) { // should this also fire if CmdLine::DurAlwaysCommit?
Expand Down
5 changes: 5 additions & 0 deletions db/dur.h
Expand Up @@ -100,6 +100,9 @@ namespace mongo {
*/ */
virtual bool commitIfNeeded() = 0; 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() */ /** Declare write intent for a DiskLoc. @see DiskLoc::writing() */
inline DiskLoc& writingDiskLoc(DiskLoc& d) { return *((DiskLoc*) writingPtr(&d, sizeof(d))); } inline DiskLoc& writingDiskLoc(DiskLoc& d) { return *((DiskLoc*) writingPtr(&d, sizeof(d))); }


Expand Down Expand Up @@ -174,6 +177,7 @@ namespace mongo {
bool awaitCommit() { return false; } bool awaitCommit() { return false; }
bool commitNow() { return false; } bool commitNow() { return false; }
bool commitIfNeeded() { return false; } bool commitIfNeeded() { return false; }
bool aCommitIsNeeded() const { return false; }
void setNoJournal(void *dst, void *src, unsigned len); void setNoJournal(void *dst, void *src, unsigned len);
void syncDataAndTruncateJournal() {} void syncDataAndTruncateJournal() {}
}; };
Expand All @@ -186,6 +190,7 @@ namespace mongo {
void createdFile(string filename, unsigned long long len); void createdFile(string filename, unsigned long long len);
bool awaitCommit(); bool awaitCommit();
bool commitNow(); bool commitNow();
bool aCommitIsNeeded() const;
bool commitIfNeeded(); bool commitIfNeeded();
void setNoJournal(void *dst, void *src, unsigned len); void setNoJournal(void *dst, void *src, unsigned len);
void syncDataAndTruncateJournal(); void syncDataAndTruncateJournal();
Expand Down

0 comments on commit d8f79a5

Please sign in to comment.