diff options
author | Dwight <dmerriman@gmail.com> | 2008-06-26 19:11:19 -0400 |
---|---|---|
committer | Dwight <dmerriman@gmail.com> | 2008-06-26 19:11:19 -0400 |
commit | 0c4751cb7856a849963841e59784d5058557e9a0 (patch) | |
tree | 53bb2346e09467590a797fb14af5c4c4628229de | |
parent | 58d84f51f2ecf26d3926bb648b88b4e97d410244 (diff) | |
download | mongo-0c4751cb7856a849963841e59784d5058557e9a0.tar.gz |
pad objects when allocated, when appropriate, to make updates faster.
-rw-r--r-- | db/namespace.h | 21 | ||||
-rw-r--r-- | db/pdfile.cpp | 24 | ||||
-rw-r--r-- | db/query.cpp | 2 |
3 files changed, 41 insertions, 6 deletions
diff --git a/db/namespace.h b/db/namespace.h index 6caefc633f3..e8e056ed958 100644 --- a/db/namespace.h +++ b/db/namespace.h @@ -76,11 +76,14 @@ extern int bucketSizes[]; class NamespaceDetails { public: NamespaceDetails() { + /* be sure to initialize new fields here, otherwise they will contain garbage by default. + */ datasize = nrecords = 0; lastExtentSize = 0; nIndexes = 0; capped = 0; max = 0x7fffffff; + paddingFactor = 1.0; memset(reserved, 0, sizeof(reserved)); } DiskLoc firstExtent; @@ -93,7 +96,19 @@ public: IndexDetails indexes[MaxIndexes]; int capped; int max; // max # of objects for a capped table. - char reserved[256-16-4-4-8*MaxIndexes-8-8]; + double paddingFactor; // 1.0 = no padding. + char reserved[256-16-4-4-8*MaxIndexes-8-8-8]; + + void paddingFits() { + double x = paddingFactor - 0.01; + if( x >= 1.0 ) + paddingFactor = x; + } + void paddingTooSmall() { + double x = paddingFactor + 0.6; + if( x <= 2.0 ) + paddingFactor = x; + } //returns offset in indexes[] int findIndexByName(const char *name) { @@ -112,8 +127,12 @@ public: return Buckets-1; } + /* allocate a new record. lenToAlloc includes headers. */ DiskLoc alloc(const char *ns, int lenToAlloc, DiskLoc& extentLoc); + + /* add a given record to the deleted chains for this NS */ void addDeletedRec(DeletedRecord *d, DiskLoc dloc); + void dumpDeleted(set<DiskLoc> *extents = 0); private: DiskLoc __stdAlloc(int len); diff --git a/db/pdfile.cpp b/db/pdfile.cpp index 2bc7c529bdf..c39191d42a7 100644 --- a/db/pdfile.cpp +++ b/db/pdfile.cpp @@ -79,7 +79,8 @@ void NamespaceDetails::addDeletedRec(DeletedRecord *d, DiskLoc dloc) { d->nextDeleted = oldHead; } -/* lenToAlloc is WITH header +/* + lenToAlloc is WITH header */ DiskLoc NamespaceDetails::alloc(const char *ns, int lenToAlloc, DiskLoc& extentLoc) { lenToAlloc = (lenToAlloc + 3) & 0xfffffffc; @@ -259,10 +260,13 @@ void NamespaceDetails::compact() { } } +/* alloc with capped table handling. */ DiskLoc NamespaceDetails::_alloc(const char *ns, int len) { if( !capped ) return __stdAlloc(len); + // capped. + assert( len < 400000000 ); int passes = 0; DiskLoc loc; @@ -749,13 +753,15 @@ void DataFileMgr::update( { NamespaceDetails *d = nsdetails(ns); - if( toupdate->netLength() < len ) { + if( toupdate->netLength() < len ) { + // doesn't fit. must reallocate. + if( d && d->capped ) { ss << " failing a growing update on a capped ns " << ns << endl; return; } - // doesn't fit. + d->paddingTooSmall(); if( client->profile ) ss << " moved "; deleteRecord(ns, toupdate, dl); @@ -763,6 +769,8 @@ void DataFileMgr::update( return; } + d->paddingFits(); + /* has any index keys changed? */ { NamespaceDetails *d = nsdetails(ns); @@ -893,6 +901,7 @@ DiskLoc DataFileMgr::insert(const char *ns, const void *buf, int len, bool god) client->newestFile()->newExtent(ns, initialExtentSize(len)); d = nsdetails(ns); } + d->paddingFits(); NamespaceDetails *tableToIndex = 0; @@ -927,11 +936,18 @@ DiskLoc DataFileMgr::insert(const char *ns, const void *buf, int len, bool god) DiskLoc extentLoc; int lenWHdr = len + Record::HeaderSize; + lenWHdr = (int) (lenWHdr * d->paddingFactor); + if( lenWHdr == 0 ) { + // old datafiles, backward compatible here. + assert( d->paddingFactor == 0 ); + d->paddingFactor = 1.0; + lenWHdr = len + Record::HeaderSize; + } DiskLoc loc = d->alloc(ns, lenWHdr, extentLoc); if( loc.isNull() ) { // out of space if( d->capped == 0 ) { // size capped doesn't grow - cout << "allocating new extent for " << ns << endl; + cout << "allocating new extent for " << ns << " padding:" << d->paddingFactor << endl; client->newestFile()->newExtent(ns, followupExtentSize(len, d->lastExtentSize)); loc = d->alloc(ns, lenWHdr, extentLoc); } diff --git a/db/query.cpp b/db/query.cpp index cef5dbf50a9..3f76624dfb3 100644 --- a/db/query.cpp +++ b/db/query.cpp @@ -342,7 +342,7 @@ string validateNS(const char *ns, NamespaceDetails *d) { ss << " firstExtent:" << d->firstExtent.toString() << " lastExtent:" << d->lastExtent.toString() << '\n'; ss << " datasize?:" << d->datasize << " nrecords?:" << d->nrecords << " lastExtentSize:" << d->lastExtentSize << '\n'; - + ss << " padding:" << d->paddingFactor << '\n'; try { { |