Permalink
Browse files

Merge branch 'master' of git@github.com:mongodb/mongo

  • Loading branch information...
2 parents e8ea876 + 7ebae06 commit a1d3ebb0c44e4551d97c082f3ba3a644cb6d3e37 @astaple astaple committed May 6, 2009
Showing with 134 additions and 111 deletions.
  1. +2 −2 db/db.h
  2. +2 −2 db/repl.h
  3. +25 −4 dbtests/jstests.cpp
  4. +0 −71 s/shardkey.cpp
  5. +0 −6 s/shardkey.h
  6. +100 −18 scripting/engine_spidermonkey.cpp
  7. +2 −1 scripting/engine_spidermonkey.h
  8. +3 −7 scripting/sm_db.cpp
View
@@ -202,14 +202,14 @@ namespace mongo {
#if BOOST_VERSION >= 103500
dbMutex.unlock();
#else
- boost::detail::thread::lock_ops<boost::mutex>::unlock(dbMutex);
+ boost::detail::thread::lock_ops<boost::recursive_mutex>::unlock(dbMutex);
#endif
}
~dbtemprelease() {
#if BOOST_VERSION >= 103500
dbMutex.lock();
#else
- boost::detail::thread::lock_ops<boost::mutex>::lock(dbMutex);
+ boost::detail::thread::lock_ops<boost::recursive_mutex>::lock(dbMutex);
#endif
dbMutexInfo.entered();
if ( clientname.empty() )
View
@@ -19,7 +19,7 @@
/* replication data overview
at the slave:
- local.sources { host: ..., source: ..., syncedTo: ..., dbs: { ... } }
+ local.sources { host: ..., source: ..., only: ..., syncedTo: ..., localLogTs: ..., dbsNextPass: { ... }, incompleteCloneDbs: { ... } }
at the master:
local.oplog.$<source>
@@ -59,7 +59,7 @@ namespace mongo {
Can be a group of things to replicate for several databases.
- { host: ..., source: ..., syncedTo: ..., dbs: { ... } }
+ { host: ..., source: ..., only: ..., syncedTo: ..., localLogTs: ..., dbsNextPass: { ... }, incompleteCloneDbs: { ... } }
'source' defaults to 'main'; support for multiple source names is
not done (always use main for now).
View
@@ -137,10 +137,30 @@ namespace JSTests {
delete s;
}
};
-
- // TODO:
- // setThis
- // init
+
+ class ObjectDecoding {
+ public:
+ void run(){
+ Scope * s = globalScriptEngine->createScope();
+
+ s->invoke( "z = { num : 1 };" , BSONObj() );
+ BSONObj out = s->getObject( "z" );
+ ASSERT_EQUALS( 1 , out["num"].number() );
+ ASSERT_EQUALS( 1 , out.nFields() );
+
+ s->invoke( "z = { x : 'eliot' };" , BSONObj() );
+ out = s->getObject( "z" );
+ ASSERT_EQUALS( (string)"eliot" , out["x"].valuestr() );
+ ASSERT_EQUALS( 1 , out.nFields() );
+
+ BSONObj o = BSON( "x" << 17 );
+ s->setObject( "blah" , o );
+ out = s->getObject( "blah" );
+ ASSERT_EQUALS( 17 , out["x"].number() );
+
+ delete s;
+ }
+ };
class All : public UnitTest::Suite {
public:
@@ -150,6 +170,7 @@ namespace JSTests {
add< FalseTests >();
add< SimpleFunctions >();
add< ObjectMapping >();
+ add< ObjectDecoding >();
}
};
View
@@ -282,38 +282,6 @@ namespace mongo {
averageValues(b, lt, l, r);
}
- BSONObj ShardKeyPattern::middle( const BSONObj &lo , const BSONObj &ro ) {
- BSONObj L = extractKey(lo);
- BSONObj R = extractKey(ro);
- BSONElement l = L.firstElement();
- BSONElement r = R.firstElement();
- if( l == r || l.eoo() || r.eoo() )
- return L;
-
- BSONObjBuilder b;
-
- massert("not done for compound patterns", patternfields.size() == 1);
-
- middleVal(b, l, r);
- BSONObj res = b.obj();
-
- if( res.woEqual(ro) ) {
- // range is minimal, i.e., two adjacent values. as RHS is open,
- // return LHS
- return lo;
- }
-
- /* compound:
- BSONObjIterator li(L);
- BSONObjIterator ri(R);
- while( 1 ) {
-
- }
- */
-
- return res;
- }
-
bool ShardKeyPattern::hasShardKey( const BSONObj& obj ) {
/* this is written s.t. if obj has lots of fields, if the shard key fields are early,
it is fast. so a bit more work to try to be semi-fast.
@@ -538,39 +506,6 @@ namespace mongo {
BSONObj x = fromjson("{ key: { $gte: 30.0, $lt: 90.0 } }");
assert( x.woEqual(b.obj()) );
}
- void mid(const char *a, const char *b) {
- ShardKeyPattern k( BSON( "key" << 1 ) );
- BSONObj A = fromjson(a);
- BSONObj B = fromjson(b);
- BSONObj x = k.middle(A, B);
- assert( A.woCompare(x) < 0 );
- assert( x.woCompare(B) < 0 );
- }
- void testMiddle() {
- mid( "{key:10}", "{key:30}" );
- mid( "{key:10}", "{key:null}" );
- mid( "{key:\"Jane\"}", "{key:\"Tom\"}" );
-
- BSONObjBuilder b;
- b.appendMinKey("k");
- BSONObj min = b.obj();
- BSONObjBuilder b2;
- b2.appendMaxKey("k");
- BSONObj max = b2.obj();
- ShardKeyPattern k( BSON( "k" << 1 ) );
-// cout << min.toString() << endl;
- BSONObj m = k.middle(min, max);
-// cout << m << endl;
- BSONObj n = k.middle(m, max);
-// cout << n << endl;
- BSONObj p = k.middle(min, m);
-// cout << "\n" << min.toString() << " " << m.toString() << endl;
-// cout << p << endl;
- }
- void testGlobal(){
- ShardKeyPattern k( fromjson( "{num:1}" ) );
- DEV cout << "global middle:" << k.middle( k.globalMin() , k.globalMax() ) << endl;
- }
void div(const char *a, const char *res) {
OID A,RES;
A.init(a);
@@ -651,17 +586,11 @@ namespace mongo {
assert( k.compare(a,b) < 0 );
- assert( k.compare(a,k.middle(a,a)) == 0 );
- assert( k.compare(a,k.middle(a,b)) <= 0 );
- assert( k.compare(k.middle(a,b),b) <= 0 );
-
assert( k.canOrder( fromjson("{key:1}") ) == 1 );
assert( k.canOrder( fromjson("{zz:1}") ) == 0 );
assert( k.canOrder( fromjson("{key:-1}") ) == -1 );
testCanOrder();
- testMiddle();
- testGlobal();
getfilt();
rfq();
// add middle multitype tests
View
@@ -56,12 +56,6 @@ namespace mongo {
return isGlobalMin( k ) || isGlobalMax( k );
}
- /**
- @return the key central between min and max
- note: min and max could cross type boundaries
- */
- BSONObj middle( const BSONObj & min , const BSONObj & max );
-
/** compare shard keys from the objects specified
l < r negative
l == r 0
@@ -7,22 +7,6 @@
namespace mongo {
boost::thread_specific_ptr<SMScope> currentScope( dontDeleteScope );
-
- void bson_finalize( JSContext * cx , JSObject * obj ){
- BSONObj * o = (BSONObj*)JS_GetPrivate( cx , obj );
- if ( o ){
- delete o;
- JS_SetPrivate( cx , obj , 0 );
- }
- }
-
- static JSClass bson_ro_class = {
- "bson_object" , JSCLASS_HAS_PRIVATE | JSCLASS_NEW_RESOLVE ,
- JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_PropertyStub,
- JS_EnumerateStub, (JSResolveOp)(&resolveBSONField) , JS_ConvertStub, bson_finalize ,
- JSCLASS_NO_OPTIONAL_MEMBERS
- };
-
class Convertor {
public:
@@ -58,6 +42,48 @@ namespace mongo {
assert( JS_ValueToBoolean( _context, v , &b ) );
return b;
}
+
+ BSONObj toObject( JSObject * o ){
+ if ( ! o )
+ return BSONObj();
+
+ BSONObjBuilder b;
+
+ JSIdArray * properties = JS_Enumerate( _context , o );
+ assert( properties );
+
+ for ( jsint i=0; i<properties->length; i++ ){
+ jsid id = properties->vector[i];
+ jsval nameval;
+ assert( JS_IdToValue( _context ,id , &nameval ) );
+ string name = toString( nameval );
+ append( b , name , getProperty( o , name.c_str() ) );
+ }
+
+ return b.obj();
+ }
+
+ BSONObj toObject( jsval v ){
+ if ( JSVAL_IS_NULL( v ) ||
+ JSVAL_IS_VOID( v ) )
+ return BSONObj();
+
+ uassert( "not an object" , JSVAL_IS_OBJECT( v ) );
+ return toObject( JSVAL_TO_OBJECT( v ) );
+ }
+
+ void append( BSONObjBuilder& b , string name , jsval val ){
+ switch ( JS_TypeOfValue( _context , val ) ){
+
+ case JSTYPE_VOID: b.appendUndefined( name.c_str() ); break;
+ case JSTYPE_NULL: b.appendNull( name.c_str() ); break;
+
+ case JSTYPE_NUMBER: b.append( name.c_str() , toNumber( val ) ); break;
+ case JSTYPE_STRING: b.append( name.c_str() , toString( val ) ); break;
+
+ default: uassert( (string)"can't append type: " + typeString( val ) , 0 );
+ }
+ }
// ---------- to spider monkey ---------
@@ -97,7 +123,7 @@ namespace mongo {
case String:
return toval( e.valuestr() );
default:
- log() << "resolveBSONField can't handle type: " << (int)(e.type()) << endl;
+ log() << "toval can't handle type: " << (int)(e.type()) << endl;
}
uassert( "not done: toval" , 0 );
@@ -150,6 +176,62 @@ namespace mongo {
JSContext * _context;
};
+
+ void bson_finalize( JSContext * cx , JSObject * obj ){
+ BSONObj * o = (BSONObj*)JS_GetPrivate( cx , obj );
+ if ( o ){
+ delete o;
+ JS_SetPrivate( cx , obj , 0 );
+ }
+ }
+
+ JSBool bson_enumerate( JSContext *cx, JSObject *obj, JSIterateOp enum_op, jsval *statep, jsid *idp ){
+
+ if ( enum_op == JSENUMERATE_INIT ){
+ BSONObjIterator * it = new BSONObjIterator( ((BSONObj*)JS_GetPrivate( cx , obj ))->getOwned() );
+ *statep = PRIVATE_TO_JSVAL( it );
+ if ( idp )
+ *idp = JSVAL_ZERO;
+ return JS_TRUE;
+ }
+
+ BSONObjIterator * it = (BSONObjIterator*)JSVAL_TO_PRIVATE( *statep );
+
+ if ( enum_op == JSENUMERATE_NEXT ){
+ if ( it->more() ){
+ BSONElement e = it->next();
+ if ( e.eoo() ){
+ *statep = 0;
+ }
+ else {
+ Convertor c(cx);
+ assert( JS_ValueToId( cx , c.toval( e.fieldName() ) , idp ) );
+ }
+ }
+ else {
+ *statep = 0;
+ }
+ return JS_TRUE;
+ }
+
+ if ( enum_op == JSENUMERATE_DESTROY ){
+ delete it;
+ }
+
+ uassert( "don't know what to do with this op" , 0 );
+ return JS_FALSE;
+ }
+
+
+ JSClass bson_ro_class = {
+ "bson_object" , JSCLASS_HAS_PRIVATE | JSCLASS_NEW_RESOLVE | JSCLASS_NEW_ENUMERATE ,
+ JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_PropertyStub,
+ (JSEnumerateOp)bson_enumerate, (JSResolveOp)(&resolveBSONField) , JS_ConvertStub, bson_finalize ,
+ JSCLASS_NO_OPTIONAL_MEMBERS
+ };
+
+
+
static JSClass global_class = {
"global", JSCLASS_GLOBAL_FLAGS,
JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_PropertyStub,
@@ -304,7 +386,7 @@ namespace mongo {
}
BSONObj getObject( const char *field ){
- massert( "not implemented yet: getObject()" , 0 ); throw -1;
+ return _convertor->toObject( _convertor->getProperty( _global , field ) );
}
JSObject * getJSObject( const char * field ){
@@ -20,7 +20,8 @@
namespace mongo {
class SMScope;
-
+ extern JSClass bson_ro_class;
+
// internal things
void dontDeleteScope( SMScope * s ){}
void errorReporter( JSContext *cx, const char *message, JSErrorReport *report );
View
@@ -2,8 +2,6 @@
// hacked in right now from engine_spidermonkey.cpp
-#include "../db/db.h"
-
namespace mongo {
// ------------ some defs needed ---------------
@@ -128,18 +126,16 @@ namespace mongo {
string ns = c.toString( argv[0] );
+ BSONObj q = c.toObject( argv[1] );
+ //uassert( "field selector not supported yet in mongo_find" , argv[2] == JSVAL_NULL );
-
- uassert( "field selector not supported yet in mongo_find" , argv[2] == JSVAL_NULL );
int nToReturn = c.toNumber( argv[3] );
int nToSkip = c.toNumber( argv[4] );
bool slaveOk = c.getBoolean( obj , "slaveOk" );
try {
- dbtemprelease r; // TODO: remove
- auto_ptr<DBClientCursor> cursor = conn->query( ns , BSONObj() , nToReturn , nToSkip , 0 , slaveOk ? Option_SlaveOk : 0 );
-
+ auto_ptr<DBClientCursor> cursor = conn->query( ns , q , nToReturn , nToSkip , 0 , slaveOk ? Option_SlaveOk : 0 );
JSObject * mycursor = JS_NewObject( cx , &internal_cursor_class , 0 , 0 );
JS_SetPrivate( cx , mycursor , cursor.release() );

0 comments on commit a1d3ebb

Please sign in to comment.