diff options
author | Aaron <aaron@10gen.com> | 2010-03-01 14:34:16 -0800 |
---|---|---|
committer | Aaron <aaron@10gen.com> | 2010-03-01 14:34:16 -0800 |
commit | 892d8b4a9587c24bbf15e496c687602644cdc5ba (patch) | |
tree | 58fae32b07af0a88659753181cf8b09d0b46f5f2 | |
parent | ee3e5923e55f419a8d0fc144cc6251d432421563 (diff) | |
parent | 59eb3a8b0c0699b24d52c98fe895abf659866334 (diff) | |
download | mongo-892d8b4a9587c24bbf15e496c687602644cdc5ba.tar.gz |
Merge branch 'master' of github.com:mongodb/mongo
-rw-r--r-- | db/dbcommands.cpp | 30 | ||||
-rw-r--r-- | db/index_geo2d.cpp | 13 | ||||
-rw-r--r-- | db/jsobj.h | 24 | ||||
-rw-r--r-- | db/stats/counters.cpp | 6 | ||||
-rw-r--r-- | db/stats/top.cpp | 4 | ||||
-rw-r--r-- | dbtests/jsobjtests.cpp | 21 | ||||
-rw-r--r-- | s/commands_public.cpp | 6 |
7 files changed, 73 insertions, 31 deletions
diff --git a/db/dbcommands.cpp b/db/dbcommands.cpp index 78d50cbe71b..621d6ed1444 100644 --- a/db/dbcommands.cpp +++ b/db/dbcommands.cpp @@ -341,8 +341,8 @@ namespace mongo { ProcessInfo p; if ( p.supported() ){ - t.appendIntOrLL( "resident" , p.getResidentSize() ); - t.appendIntOrLL( "virtual" , p.getVirtualMemorySize() ); + t.appendNumber( "resident" , p.getResidentSize() ); + t.appendNumber( "virtual" , p.getVirtualMemorySize() ); t.appendBool( "supported" , true ); } else { @@ -350,7 +350,7 @@ namespace mongo { t.appendBool( "supported" , false ); } - t.appendIntOrLL( "mapped" , MemoryMappedFile::totalMappedLength() / ( 1024 * 1024 ) ); + t.appendNumber( "mapped" , MemoryMappedFile::totalMappedLength() / ( 1024 * 1024 ) ); t.done(); @@ -1025,7 +1025,7 @@ namespace mongo { continue; // nothing to do here totalSize += nsd->datasize; if (details) - details->appendIntOrLL(index["name"].valuestrsafe(), nsd->datasize / scale ); + details->appendNumber(index["name"].valuestrsafe(), nsd->datasize / scale ); } return totalSize; } @@ -1058,10 +1058,10 @@ namespace mongo { if ( jsobj["scale"].isNumber() ) scale = jsobj["scale"].numberInt(); - result.appendIntOrLL( "count" , nsd->nrecords ); - result.appendIntOrLL( "size" , nsd->datasize / scale ); + result.appendNumber( "count" , nsd->nrecords ); + result.appendNumber( "size" , nsd->datasize / scale ); int numExtents; - result.appendIntOrLL( "storageSize" , nsd->storageSize( &numExtents ) / scale ); + result.appendNumber( "storageSize" , nsd->storageSize( &numExtents ) / scale ); result.append( "numExtents" , numExtents ); result.append( "nindexes" , nsd->nIndexes ); result.append( "lastExtentSize" , nsd->lastExtentSize / scale ); @@ -1069,7 +1069,7 @@ namespace mongo { result.append( "flags" , nsd->flags ); BSONObjBuilder indexSizes; - result.appendIntOrLL( "totalIndexSize" , getIndexSizeForCollection(dbname, ns, &indexSizes, scale) / scale ); + result.appendNumber( "totalIndexSize" , getIndexSizeForCollection(dbname, ns, &indexSizes, scale) / scale ); result.append("indexSizes", indexSizes.obj()); if ( nsd->capped ){ @@ -1127,13 +1127,13 @@ namespace mongo { indexSize += getIndexSizeForCollection(dbname, ns); } - result.appendIntOrLL( "collections" , ncollections ); - result.appendIntOrLL( "objects" , objects ); - result.appendIntOrLL( "dataSize" , size ); - result.appendIntOrLL( "storageSize" , storageSize); - result.appendIntOrLL( "numExtents" , numExtents ); - result.appendIntOrLL( "indexes" , indexes ); - result.appendIntOrLL( "indexSize" , indexSize ); + result.appendNumber( "collections" , ncollections ); + result.appendNumber( "objects" , objects ); + result.appendNumber( "dataSize" , size ); + result.appendNumber( "storageSize" , storageSize); + result.appendNumber( "numExtents" , numExtents ); + result.appendNumber( "indexes" , indexes ); + result.appendNumber( "indexSize" , indexSize ); return true; } diff --git a/db/index_geo2d.cpp b/db/index_geo2d.cpp index d865368170c..e6415d7aa9b 100644 --- a/db/index_geo2d.cpp +++ b/db/index_geo2d.cpp @@ -149,10 +149,6 @@ namespace mongo { setBit( pos , 1 ); } - unsigned operator[]( const unsigned pos ) const { - return _hash & geoBitSets.masks64[pos]; - } - void setBit( unsigned pos , bool one ){ if ( one ) _hash |= geoBitSets.masks64[pos]; @@ -1056,7 +1052,8 @@ namespace mongo { int numWanted = 100; if ( cmdObj["num"].isNumber() ) numWanted = cmdObj["num"].numberInt(); - + + uassert(13046, "'near' param missing/invalid", cmdObj["near"].type() == String); const GeoHash n = g->_tohash( cmdObj["near"] ); result.append( "near" , n.toString() ); @@ -1097,9 +1094,9 @@ namespace mongo { BSONObjBuilder stats( result.subobjStart( "stats" ) ); stats.append( "time" , cc().curop()->elapsedMillis() ); - stats.appendIntOrLL( "btreelocs" , gs._nscanned ); - stats.appendIntOrLL( "nscanned" , gs._hopper._lookedAt ); - stats.appendIntOrLL( "objectsLoaded" , gs._hopper._objectsLoaded ); + stats.appendNumber( "btreelocs" , gs._nscanned ); + stats.appendNumber( "nscanned" , gs._hopper._lookedAt ); + stats.appendNumber( "objectsLoaded" , gs._hopper._objectsLoaded ); stats.append( "avgDistance" , totalDistance / x ); stats.done(); diff --git a/db/jsobj.h b/db/jsobj.h index 01f8472462c..c70a6d7cba1 100644 --- a/db/jsobj.h +++ b/db/jsobj.h @@ -1291,6 +1291,30 @@ namespace mongo { else append( fieldName.c_str() , n ); } + + + /** + * appendNumber is a series of method for appending the smallest sensible type + * mostly for JS + */ + void appendNumber( const string& fieldName , int n ){ + append( fieldName.c_str() , n ); + } + + void appendNumber( const string& fieldName , double d ){ + append( fieldName.c_str() , d ); + } + + void appendNumber( const string& fieldName , long long l ){ + static long long maxInt = (int)pow( 2.0 , 30.0 ); + static long long maxDouble = (long long)pow( 2.0 , 40.0 ); + + if ( l < maxInt ) + append( fieldName.c_str() , (int)l ); + else if ( l < maxDouble ) + append( fieldName.c_str() , (double)l ); + append( fieldName.c_str() , l ); + } /** Append a double element */ BSONObjBuilder& append(const char *fieldName, double n) { diff --git a/db/stats/counters.cpp b/db/stats/counters.cpp index 3ff7925a079..1c037d73e4b 100644 --- a/db/stats/counters.cpp +++ b/db/stats/counters.cpp @@ -85,9 +85,9 @@ namespace mongo { } BSONObjBuilder bb( b.subobjStart( "btree" ) ); - bb.appendIntOrLL( "accesses" , _btreeAccesses ); - bb.appendIntOrLL( "hits" , _btreeMemHits ); - bb.appendIntOrLL( "misses" , _btreeMemMisses ); + bb.appendNumber( "accesses" , _btreeAccesses ); + bb.appendNumber( "hits" , _btreeMemHits ); + bb.appendNumber( "misses" , _btreeMemMisses ); bb.append( "resets" , _resets ); diff --git a/db/stats/top.cpp b/db/stats/top.cpp index 89b7e19825e..50ec7a4a5b8 100644 --- a/db/stats/top.cpp +++ b/db/stats/top.cpp @@ -107,8 +107,8 @@ namespace mongo { void Top::append( BSONObjBuilder& b , const char * name , const UsageData& map ){ BSONObjBuilder bb( b.subobjStart( name ) ); - bb.appendIntOrLL( "time" , map.time ); - bb.appendIntOrLL( "count" , map.count ); + bb.appendNumber( "time" , map.time ); + bb.appendNumber( "count" , map.count ); bb.done(); } diff --git a/dbtests/jsobjtests.cpp b/dbtests/jsobjtests.cpp index d48a7a6632c..fd136eea14e 100644 --- a/dbtests/jsobjtests.cpp +++ b/dbtests/jsobjtests.cpp @@ -358,6 +358,26 @@ namespace JsobjTests { } }; + struct AppendNumber { + void run(){ + BSONObjBuilder b; + b.appendNumber( "a" , 5 ); + b.appendNumber( "b" , 5.5 ); + b.appendNumber( "c" , (1024LL*1024*1024)-1 ); + b.appendNumber( "d" , (1024LL*1024*1024*1024)-1 ); + b.appendNumber( "e" , 1024LL*1024*1024*1024*1024*1024 ); + + BSONObj o = b.obj(); + + ASSERT( o["a"].type() == NumberInt ); + ASSERT( o["b"].type() == NumberDouble ); + ASSERT( o["c"].type() == NumberInt ); + ASSERT( o["d"].type() == NumberDouble ); + ASSERT( o["e"].type() == NumberLong ); + + } + }; + namespace Validation { class Base { @@ -1444,6 +1464,7 @@ namespace JsobjTests { add< BSONObjTests::Nan >(); add< BSONObjTests::AsTempObj >(); add< BSONObjTests::AppendIntOrLL >(); + add< BSONObjTests::AppendNumber >(); add< BSONObjTests::Validation::BadType >(); add< BSONObjTests::Validation::EooBeforeEnd >(); add< BSONObjTests::Validation::Undefined >(); diff --git a/s/commands_public.cpp b/s/commands_public.cpp index ce0e4e9fe7d..649d7d1ac7e 100644 --- a/s/commands_public.cpp +++ b/s/commands_public.cpp @@ -226,9 +226,9 @@ namespace mongo { } result.append("ns", fullns); - result.appendIntOrLL("count", count); - result.appendIntOrLL("size", size); - result.appendIntOrLL("storageSize", storageSize); + result.appendNumber("count", count); + result.appendNumber("size", size); + result.appendNumber("storageSize", storageSize); result.append("nindexes", nindexes); result.append("nchunks", cm->numChunks()); |