summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordwight <dwight@Dwights-MacBook-2.local>2009-09-27 14:46:51 -0400
committerdwight <dwight@Dwights-MacBook-2.local>2009-09-27 14:46:51 -0400
commit29ec5bf837b2e8796112744c1ccdc7c76182bdda (patch)
tree162288eae876ed29c288f8e95052e4be3da0906a
parent5de6107490d00e7737dc78b8e15b515d0bb9df5d (diff)
downloadmongo-29ec5bf837b2e8796112744c1ccdc7c76182bdda.tar.gz
tuning index performance
log less too
-rw-r--r--db/btree.cpp37
-rw-r--r--db/dbcommands.cpp2
-rw-r--r--db/instance.cpp2
-rw-r--r--db/pdfile.cpp25
4 files changed, 37 insertions, 29 deletions
diff --git a/db/btree.cpp b/db/btree.cpp
index 7db4ce1633c..dd21ec535e1 100644
--- a/db/btree.cpp
+++ b/db/btree.cpp
@@ -601,9 +601,8 @@ found:
int mid = n / 2;
- BtreeBucket *r = allocTemp();
- DiskLoc rLoc;
-
+ DiskLoc rLoc = addBucket(idx);
+ BtreeBucket *r = rLoc.btreemod();allocTemp();
if ( split_debug )
out() << " mid:" << mid << ' ' << keyNode(mid).key.toString() << " n:" << n << endl;
for ( int i = mid+1; i < n; i++ ) {
@@ -613,10 +612,8 @@ found:
r->nextChild = nextChild;
r->assertValid( order );
- rLoc = btreeStore->insert(idx.indexNamespace().c_str(), r, r->Size(), true);
if ( split_debug )
out() << " new rLoc:" << rLoc.toString() << endl;
- free(r);
r = 0;
rLoc.btree()->fixParentPtrs(rLoc);
@@ -630,14 +627,14 @@ found:
// promote middle to a parent node
if ( parent.isNull() ) {
// make a new parent if we were the root
- BtreeBucket *p = allocTemp();
+ DiskLoc L = addBucket(idx);
+ BtreeBucket *p = L.btreemod();
p->pushBack(middle.recordLoc, middle.key, order, thisLoc);
p->nextChild = rLoc;
p->assertValid( order );
- parent = idx.head = btreeStore->insert(idx.indexNamespace().c_str(), p, p->Size(), true);
+ parent = idx.head = L;
if ( split_debug )
out() << " we were root, making new root:" << hex << parent.getOfs() << dec << endl;
- free(p);
rLoc.btreemod()->parent = parent;
}
else {
@@ -672,9 +669,9 @@ found:
/* start a new index off, empty */
DiskLoc BtreeBucket::addBucket(IndexDetails& id) {
- BtreeBucket *p = allocTemp();
- DiskLoc loc = btreeStore->insert(id.indexNamespace().c_str(), p, p->Size(), true);
- free(p);
+ DiskLoc loc = btreeStore->insert(id.indexNamespace().c_str(), 0, BucketSize, true);
+ BtreeBucket *b = loc.btreemod();
+ b->init();
return loc;
}
@@ -919,15 +916,17 @@ namespace mongo {
}
void BtreeBuilder::addKey(BSONObj& key, DiskLoc loc) {
- if( n > 0 ) {
- int cmp = keyLast.woCompare(key, order);
- massert( "bad key order in BtreeBuilder - server internal error", cmp <= 0 );
- if( cmp == 0 ) {
- if( !dupsAllowed )
- uasserted( BtreeBucket::dupKeyError( idx , keyLast ) );
- }
+ if( !dupsAllowed ) {
+ if( n > 0 ) {
+ int cmp = keyLast.woCompare(key, order);
+ massert( "bad key order in BtreeBuilder - server internal error", cmp <= 0 );
+ if( cmp == 0 ) {
+ //if( !dupsAllowed )
+ uasserted( BtreeBucket::dupKeyError( idx , keyLast ) );
+ }
+ }
+ keyLast = key;
}
- keyLast = key;
if ( ! b->_pushBack(loc, key, order, DiskLoc()) ){
// no room
diff --git a/db/dbcommands.cpp b/db/dbcommands.cpp
index 9d39b1351f5..38da128404f 100644
--- a/db/dbcommands.cpp
+++ b/db/dbcommands.cpp
@@ -573,7 +573,7 @@ namespace mongo {
// delete a specific index or all?
if ( *name == '*' && name[1] == 0 ) {
- log() << " d->nIndexes was " << d->nIndexes << '\n';
+ log(4) << " d->nIndexes was " << d->nIndexes << '\n';
anObjBuilder.append("nIndexesWas", (double)d->nIndexes);
IndexDetails *idIndex = 0;
if( d->nIndexes ) {
diff --git a/db/instance.cpp b/db/instance.cpp
index 4b2234e7d82..150647bf17d 100644
--- a/db/instance.cpp
+++ b/db/instance.cpp
@@ -260,7 +260,7 @@ namespace mongo {
}
}
ms = t.millis();
- log = log || (++ctr % 512 == 0 && !quiet);
+ log = log || (logLevel >= 2 && ++ctr % 512 == 0);
DEV log = true;
if ( log || ms > 100 ) {
ss << ' ' << t.millis() << "ms";
diff --git a/db/pdfile.cpp b/db/pdfile.cpp
index 4ff9eaf7d2d..599bc5736dc 100644
--- a/db/pdfile.cpp
+++ b/db/pdfile.cpp
@@ -1182,13 +1182,18 @@ assert( !eloc.isNull() );
void buildIndex(string ns, NamespaceDetails *d, IndexDetails& idx, int idxNo) {
log() << "building new index on " << idx.keyPattern() << " for " << ns << "..." << endl;
Timer t;
-
- unsigned long long n = fastBuildIndex(ns.c_str(), d, idx, idxNo);
- assert( !idx.head.isNull() );
- //idx.head = BtreeBucket::addBucket(idx);
- //int n = addExistingToIndex(ns.c_str(), d, idx, idxNo);
-
- log() << "\t done for " << n << " records " << t.millis() / 1000.0 << "secs" << endl;
+ unsigned long long n;
+ if( 1 ) {
+ //cout << "fastBuild\n";
+ n = fastBuildIndex(ns.c_str(), d, idx, idxNo);
+ assert( !idx.head.isNull() );
+ }
+ else {
+ cout << "oldBuild\n";
+ idx.head = BtreeBucket::addBucket(idx);
+ n = addExistingToIndex(ns.c_str(), d, idx, idxNo);
+ }
+ log() << "done for " << n << " records " << t.millis() / 1000.0 << "secs" << endl;
}
/* add keys to indexes for a new record */
@@ -1284,6 +1289,9 @@ assert( !eloc.isNull() );
return loc;
}
+ /* note: if god==true, you may pass in obuf of NULL and then popular the returned DiskLoc
+ after the call -- that will prevent a double buffer copy in some cases (btree.cpp).
+ */
DiskLoc DataFileMgr::insert(const char *ns, const void *obuf, int len, bool god, const BSONElement &writeId, bool mayAddIndex) {
bool wouldAddIndex = false;
uassert("cannot insert into reserved $ collection", god || strchr(ns, '$') == 0 );
@@ -1443,7 +1451,8 @@ assert( !eloc.isNull() );
memcpy(r->data+4+newId->size(), ((char *)obuf)+4, addID-4);
}
else {
- memcpy(r->data, obuf, len);
+ if( obuf )
+ memcpy(r->data, obuf, len);
}
Extent *e = r->myExtent(loc);
if ( e->lastRecord.isNull() ) {