summaryrefslogtreecommitdiff
path: root/src/mongo/db/structure/catalog/namespace_details.cpp
diff options
context:
space:
mode:
authorEliot Horowitz <eliot@10gen.com>2014-03-24 12:28:35 -0400
committerEliot Horowitz <eliot@10gen.com>2014-04-03 13:31:49 -0400
commit5234c5739a3dfbba1a831b6b818b29a1e9ec4f0d (patch)
treed0b6584d5f0f60fc29ab4ee718ea6cc3e3767c40 /src/mongo/db/structure/catalog/namespace_details.cpp
parentb62e61ff7ba1a3d36167d55abde95e26bae5dcc4 (diff)
downloadmongo-5234c5739a3dfbba1a831b6b818b29a1e9ec4f0d.tar.gz
SERVER-13084: move non-capped alloc into its own class
Diffstat (limited to 'src/mongo/db/structure/catalog/namespace_details.cpp')
-rw-r--r--src/mongo/db/structure/catalog/namespace_details.cpp139
1 files changed, 3 insertions, 136 deletions
diff --git a/src/mongo/db/structure/catalog/namespace_details.cpp b/src/mongo/db/structure/catalog/namespace_details.cpp
index 26051d41585..2c317407540 100644
--- a/src/mongo/db/structure/catalog/namespace_details.cpp
+++ b/src/mongo/db/structure/catalog/namespace_details.cpp
@@ -52,18 +52,6 @@
namespace mongo {
- static Counter64 freelistAllocs;
- static Counter64 freelistBucketExhausted;
- static Counter64 freelistIterations;
-
- static ServerStatusMetricField<Counter64> dFreelist1( "storage.freelist.search.requests",
- &freelistAllocs );
-
- static ServerStatusMetricField<Counter64> dFreelist2( "storage.freelist.search.bucketExhausted",
- &freelistBucketExhausted );
-
- static ServerStatusMetricField<Counter64> dFreelist3( "storage.freelist.search.scanned",
- &freelistIterations );
BSONObj idKeyPattern = fromjson("{\"_id\":1}");
@@ -179,14 +167,15 @@ namespace mongo {
*/
DiskLoc NamespaceDetails::alloc(Collection* collection, const StringData& ns, int lenToAlloc) {
// if we are capped, collection must be non-NULL
- invariant( !isCapped() || collection );
+ invariant( isCapped() );
+ invariant( collection );
{
// align very slightly.
lenToAlloc = (lenToAlloc + 3) & 0xfffffffc;
}
- DiskLoc loc = _alloc(collection, ns, lenToAlloc);
+ DiskLoc loc = cappedAlloc(collection, ns, lenToAlloc);
if ( loc.isNull() )
return loc;
@@ -201,28 +190,6 @@ namespace mongo {
DEBUGGING out() << "TEMP: alloc() returns " << loc.toString() << ' ' << ns << " lentoalloc:" << lenToAlloc << endl;
int left = regionlen - lenToAlloc;
- if ( ! isCapped() ) {
- if ( left < 24 || left < (lenToAlloc >> 3) ) {
- // you get the whole thing.
- return loc;
- }
- }
-
- // don't quantize:
- // - capped collections: just wastes space
- // - $ collections (indexes) as we already have those aligned the way we want SERVER-8425
- if ( !isCapped() && NamespaceString::normal( ns ) ) {
- // we quantize here so that it only impacts newly sized records
- // this prevents oddities with older records and space re-use SERVER-8435
- lenToAlloc = std::min( r->lengthWithHeaders(),
- NamespaceDetails::quantizeAllocationSpace( lenToAlloc ) );
- left = regionlen - lenToAlloc;
-
- if ( left < 24 ) {
- // you get the whole thing.
- return loc;
- }
- }
/* split off some for further use. */
getDur().writingInt(r->lengthWithHeaders()) = lenToAlloc;
@@ -239,98 +206,6 @@ namespace mongo {
return loc;
}
- /* for non-capped collections.
- @param peekOnly just look up where and don't reserve
- returned item is out of the deleted list upon return
- */
- DiskLoc NamespaceDetails::__stdAlloc(int len, bool peekOnly) {
- freelistAllocs.increment();
- DiskLoc *prev;
- DiskLoc *bestprev = 0;
- DiskLoc bestmatch;
- int bestmatchlen = 0x7fffffff;
- int b = bucket(len);
- DiskLoc cur = _deletedList[b];
- prev = &_deletedList[b];
- int extra = 5; // look for a better fit, a little.
- int chain = 0;
- while ( 1 ) {
- { // defensive check
- int fileNumber = cur.a();
- int fileOffset = cur.getOfs();
- if (fileNumber < -1 || fileNumber >= 100000 || fileOffset < 0) {
- StringBuilder sb;
- sb << "Deleted record list corrupted in bucket " << b
- << ", link number " << chain
- << ", invalid link is " << cur.toString()
- << ", throwing Fatal Assertion";
- problem() << sb.str() << endl;
- fassertFailed(16469);
- }
- }
- if ( cur.isNull() ) {
- // move to next bucket. if we were doing "extra", just break
- if ( bestmatchlen < 0x7fffffff )
- break;
-
- if ( chain > 0 ) {
- // if we looked at things in the right bucket, but they were not suitable
- freelistBucketExhausted.increment();
- }
-
- b++;
- if ( b > MaxBucket ) {
- // out of space. alloc a new extent.
- freelistIterations.increment( 1 + chain );
- return DiskLoc();
- }
- cur = _deletedList[b];
- prev = &_deletedList[b];
- continue;
- }
- DeletedRecord *r = cur.drec();
- if ( r->lengthWithHeaders() >= len &&
- r->lengthWithHeaders() < bestmatchlen ) {
- bestmatchlen = r->lengthWithHeaders();
- bestmatch = cur;
- bestprev = prev;
- if (r->lengthWithHeaders() == len)
- // exact match, stop searching
- break;
- }
- if ( bestmatchlen < 0x7fffffff && --extra <= 0 )
- break;
- if ( ++chain > 30 && b < MaxBucket ) {
- // too slow, force move to next bucket to grab a big chunk
- //b++;
- freelistIterations.increment( chain );
- chain = 0;
- cur.Null();
- }
- else {
- /*this defensive check only made sense for the mmap storage engine:
- if ( r->nextDeleted.getOfs() == 0 ) {
- problem() << "~~ Assertion - bad nextDeleted " << r->nextDeleted.toString() <<
- " b:" << b << " chain:" << chain << ", fixing.\n";
- r->nextDeleted.Null();
- }*/
- cur = r->nextDeleted();
- prev = &r->nextDeleted();
- }
- }
-
- /* unlink ourself from the deleted list */
- if( !peekOnly ) {
- DeletedRecord *bmr = bestmatch.drec();
- *getDur().writing(bestprev) = bmr->nextDeleted();
- bmr->nextDeleted().writing().setInvalid(); // defensive.
- verify(bmr->extentOfs() < bestmatch.getOfs());
- }
-
- freelistIterations.increment( 1 + chain );
- return bestmatch;
- }
-
DiskLoc NamespaceDetails::firstRecord( const DiskLoc &startExtent ) const {
for (DiskLoc i = startExtent.isNull() ? _firstExtent : startExtent;
!i.isNull(); i = i.ext()->xnext ) {
@@ -367,14 +242,6 @@ namespace mongo {
}
}
- /* alloc with capped table handling. */
- DiskLoc NamespaceDetails::_alloc(Collection* collection, const StringData& ns, int len) {
- if ( ! isCapped() )
- return __stdAlloc(len, false);
-
- return cappedAlloc(collection, ns,len);
- }
-
NamespaceDetails::Extra* NamespaceDetails::allocExtra( const StringData& ns,
NamespaceIndex& ni,
int nindexessofar) {