Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

an index v1 buf fix and a bunch of cleaning/safety

  • Loading branch information...
commit e39dfdf08badc59282c9a583a9b5e977b35708cc 1 parent b5993b3
@dwight dwight authored
View
6 db/btree.cpp
@@ -309,12 +309,12 @@ namespace mongo {
* does not bother returning that value.
*/
template< class V >
- void BucketBasics<V>::popBack(DiskLoc& recLoc, Key& key) {
+ void BucketBasics<V>::popBack(DiskLoc& recLoc, const Key *&key) {
massert( 10282 , "n==0 in btree popBack()", this->n > 0 );
assert( k(this->n-1).isUsed() ); // no unused skipping in this function at this point - btreebuilder doesn't require that
KeyNode kn = keyNode(this->n-1);
recLoc = kn.recordLoc;
- key = kn.key;
+ key = &kn.key;
int keysize = kn.key.dataSize();
massert( 10283 , "rchild not null in btree popBack()", this->nextChild.isNull());
@@ -1760,7 +1760,7 @@ namespace mongo {
}
}
- int x = _insert(thisLoc, recordLoc, Key(key), order, dupsAllowed, DiskLoc(), DiskLoc(), idx);
+ int x = _insert(thisLoc, recordLoc, key, order, dupsAllowed, DiskLoc(), DiskLoc(), idx);
this->assertValid( order );
return x;
View
8 db/btree.h
@@ -429,7 +429,7 @@ namespace mongo {
* - The last key of the bucket is removed, and its key and recLoc are
* returned. As mentioned above, the key points to unallocated memory.
*/
- void popBack(DiskLoc& recLoc, Key& key);
+ void popBack(DiskLoc& recLoc, const Key *&key);
/**
* Preconditions:
@@ -880,8 +880,10 @@ namespace mongo {
int indexInParent( const DiskLoc &thisLoc ) const;
public:
- Key keyAt(int keyOfs) const {
- return keyOfs >= this->n ? Key() : this->keyNode(keyOfs).key;
+ Key keyAt(int i) const {
+ if( i >= this->n )
+ return Key();
+ return Key(data + k(i).keyDataOfs());
}
protected:
View
22 db/btreebuilder.cpp
@@ -62,31 +62,31 @@ namespace mongo {
template<class V>
void BtreeBuilder<V>::addKey(BSONObj& _key, DiskLoc loc) {
- KeyOwned key(_key);
+ auto_ptr< KeyOwned > key( new KeyOwned(_key) );
- if ( key.dataSize() > KeyMax ) {
+ if ( key->dataSize() > KeyMax ) {
problem() << "Btree::insert: key too large to index, skipping " << idx.indexNamespace()
- << ' ' << key.dataSize() << ' ' << key.toString() << endl;
+ << ' ' << key->dataSize() << ' ' << key->toString() << endl;
return;
}
if( !dupsAllowed ) {
if( n > 0 ) {
- int cmp = keyLast.woCompare(key, ordering);
+ int cmp = keyLast->woCompare(*key, ordering);
massert( 10288 , "bad key order in BtreeBuilder - server internal error", cmp <= 0 );
if( cmp == 0 ) {
//if( !dupsAllowed )
- uasserted( ASSERT_ID_DUPKEY , BtreeBucket<V>::dupKeyError( idx , keyLast ) );
+ uasserted( ASSERT_ID_DUPKEY , BtreeBucket<V>::dupKeyError( idx , *keyLast ) );
}
}
- keyLast = key;
}
- if ( ! b->_pushBack(loc, key, ordering, DiskLoc()) ) {
+ if ( ! b->_pushBack(loc, *key, ordering, DiskLoc()) ) {
// bucket was full
newBucket();
- b->pushBack(loc, key, ordering, DiskLoc());
+ b->pushBack(loc, *key, ordering, DiskLoc());
}
+ keyLast = key;
n++;
mayCommitProgressDurably();
}
@@ -114,19 +114,19 @@ namespace mongo {
}
BtreeBucket<V> *x = xloc.btreemod<V>();
- Key k;
+ const Key *k;
DiskLoc r;
x->popBack(r,k);
bool keepX = ( x->n != 0 );
DiskLoc keepLoc = keepX ? xloc : x->nextChild;
- if ( ! up->_pushBack(r, k, ordering, keepLoc) ) {
+ if ( ! up->_pushBack(r, *k, ordering, keepLoc) ) {
// current bucket full
DiskLoc n = BtreeBucket<V>::addBucket(idx);
up->setTempNext(n);
upLoc = n;
up = upLoc.btreemod<V>();
- up->pushBack(r, k, ordering, keepLoc);
+ up->pushBack(r, *k, ordering, keepLoc);
}
DiskLoc nextLoc = x->tempNext(); // get next in chain at current level
View
2  db/btreebuilder.h
@@ -17,7 +17,7 @@ namespace mongo {
/** Number of keys added to btree. */
unsigned long long n;
/** Last key passed to addKey(). */
- typename V::Key keyLast;
+ auto_ptr< typename V::KeyOwned > keyLast;
BSONObj order;
Ordering ordering;
/** true iff commit() completed successfully. */
View
5 db/geo/2d.cpp
@@ -1129,7 +1129,10 @@ namespace mongo {
}
bool hasPrefix( const GeoHash& hash ) {
+ BSONObj k = key();
+ cout << k.toString() << endl;
BSONElement e = key().firstElement();
+ cout << e.toString() << endl;
if ( e.eoo() )
return false;
return GeoHash( e ).hasPrefix( hash );
@@ -1182,8 +1185,6 @@ namespace mongo {
GeoHash start ,
int & found , GeoAccumulator * hopper ) {
- assert( id.version() == 0 ); // see note at top of this file
-
Ordering ordering = Ordering::make(spec->_order);
IndexInterface *ii = &id.idxInterface();
View
2  db/geo/core.h
@@ -89,7 +89,7 @@ namespace mongo {
_bits = bits;
}
else {
- cout << "GeoHash cons e : " << e << endl;
+ cout << "GeoHash bad element: " << e << endl;
uassert(13047,"wrong type for geo index. if you're using a pre-release version, need to rebuild index",0);
}
_fix();
View
4 db/index.cpp
@@ -28,9 +28,9 @@
namespace mongo {
/** old (<= v1.8) : 0
- 1 is temp new version but might move it to 2 for the real release TBD
+ 1 is new version
*/
- const int DefaultIndexVersionNumber = 0;
+ const int DefaultIndexVersionNumber = 1;
template< class V >
class IndexInterfaceImpl : public IndexInterface {
View
2  db/key.cpp
@@ -88,7 +88,7 @@ namespace mongo {
case Symbol:
case String:
// nulls not allowed in the middle of strings in the old version
- return strcmp(l.valuestr(), r.valuestr());
+ return strcmp(l.valuestr(), r.valuestr());
case Object:
case Array:
return oldCompare(l.embeddedObject(), r.embeddedObject(), nullOrdering);
View
12 db/key.h
@@ -45,16 +45,25 @@ namespace mongo {
BSONObj _o;
};
+ class KeyV1Owned;
+
// corresponding to BtreeData_V1
class KeyV1 {
+ void operator=(const KeyV1&); // disallowed just to make people be careful as we don't own the buffer
+ KeyV1(const KeyV1Owned&); // disallowed as this is not a great idea as KeyV1Owned likely will go out of scope
public:
KeyV1() { _keyData = 0; }
~KeyV1() { DEV _keyData = (const unsigned char *) 1; }
+ KeyV1(const KeyV1& rhs) : _keyData(rhs._keyData) {
+ dassert( _keyData > (const unsigned char *) 1 );
+ }
+
/** @param keyData can be a buffer containing data in either BSON format, OR in KeyV1 format.
when BSON, we are just a wrapper
*/
explicit KeyV1(const char *keyData) : _keyData((unsigned char *) keyData) { }
+
int woCompare(const KeyV1& r, const Ordering &o) const;
bool woEqual(const KeyV1& r) const;
BSONObj toBson() const;
@@ -81,6 +90,8 @@ namespace mongo {
};
class KeyV1Owned : public KeyV1 {
+ KeyV1Owned(const KeyV1Owned&); // not copyable -- StackBufBuilder is not copyable and that owns our buffer
+ void operator=(const KeyV1Owned&);
public:
/** @obj a BSON object to be translated to KeyV1 format. If the object isn't
representable in KeyV1 format (which happens, intentionally, at times)
@@ -88,7 +99,6 @@ namespace mongo {
*/
KeyV1Owned(const BSONObj& obj);
private:
- KeyV1Owned(const KeyV1Owned&); //not copyable
StackBufBuilder b;
void traditional(const BSONObj& obj); // store as traditional bson not as compact format
};
Please sign in to comment.
Something went wrong with that request. Please try again.