summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEliot Horowitz <eliot@10gen.com>2011-08-17 11:22:04 -0400
committerEliot Horowitz <eliot@10gen.com>2011-08-17 11:22:04 -0400
commitd4435681b510407cf2ba83f338a3a925efaeb1ec (patch)
tree907656334b165778107215c458e9d2692ac1f4fe
parentb9619c4bde7460b6c3a3be9927854925bda60521 (diff)
downloadmongo-d4435681b510407cf2ba83f338a3a925efaeb1ec.tar.gz
better handling of new index versions SERVER-3589
-rw-r--r--db/btree.cpp1
-rw-r--r--db/btreecursor.cpp1
-rw-r--r--db/dbcommands.cpp11
-rw-r--r--db/index.h5
-rw-r--r--jstests/index_fornew.js13
5 files changed, 31 insertions, 0 deletions
diff --git a/db/btree.cpp b/db/btree.cpp
index 242c53438aa..299c212bf64 100644
--- a/db/btree.cpp
+++ b/db/btree.cpp
@@ -1642,6 +1642,7 @@ namespace mongo {
}
DiskLoc BtreeBucket::findSingle( const IndexDetails& indexdetails , const DiskLoc& thisLoc, const BSONObj& key ) const {
+ indexdetails.checkVersion();
int pos;
bool found;
// TODO: is it really ok here that the order is a default?
diff --git a/db/btreecursor.cpp b/db/btreecursor.cpp
index 9cab95f83c6..ce841ce3dbb 100644
--- a/db/btreecursor.cpp
+++ b/db/btreecursor.cpp
@@ -73,6 +73,7 @@ namespace mongo {
}
void BtreeCursor::audit() {
+ indexDetails.checkVersion();
dassert( d->idxNo((IndexDetails&) indexDetails) == idxNo );
if ( otherTraceLevel >= 12 ) {
diff --git a/db/dbcommands.cpp b/db/dbcommands.cpp
index 0cd80fd528f..59dd78c25ce 100644
--- a/db/dbcommands.cpp
+++ b/db/dbcommands.cpp
@@ -851,6 +851,17 @@ namespace mongo {
for ( list<BSONObj>::iterator i=all.begin(); i!=all.end(); i++ ) {
BSONObj o = *i;
+ if ( o.getIntField("v") > 0 ) {
+ BSONObjBuilder b;
+ BSONObjIterator i( o );
+ while ( i.more() ) {
+ BSONElement e = i.next();
+ if ( str::equals( e.fieldName() , "v" ) )
+ continue;
+ b.append( e );
+ }
+ o = b.obj();
+ }
theDataFileMgr.insertWithObjMod( Namespace( toDeleteNs.c_str() ).getSisterNS( "system.indexes" ).c_str() , o , true );
}
diff --git a/db/index.h b/db/index.h
index 8578ed381c9..8bb1a30f821 100644
--- a/db/index.h
+++ b/db/index.h
@@ -145,6 +145,11 @@ namespace mongo {
const IndexSpec& getSpec() const;
+ void checkVersion() const {
+ // TODO: cache?
+ massert( 13658 , str::stream() << "using a newer index version: " << info.obj() , info.obj().getIntField("v") == 0 );
+ }
+
string toString() const {
return info.obj().toString();
}
diff --git a/jstests/index_fornew.js b/jstests/index_fornew.js
new file mode 100644
index 00000000000..6c3c158ecff
--- /dev/null
+++ b/jstests/index_fornew.js
@@ -0,0 +1,13 @@
+
+t = db.index_fornew;
+t.drop();
+
+t.insert( { x : 1 } )
+t.ensureIndex( { x : 1 } , { v : 1 } )
+assert.eq( 1 , t.getIndexes()[1].v , tojson( t.getIndexes() ) );
+
+assert.throws( function(){ t.findOne( { x : 1 } ); } )
+
+t.reIndex();
+assert.eq( 0 , t.getIndexes()[1].v , tojson( t.getIndexes() ) );
+assert( t.findOne( { x : 1 } ) );