Skip to content

Commit

Permalink
Merge branch 'smshell'
Browse files Browse the repository at this point in the history
Conflicts:
	jstests/count.js
	scripting/engine_spidermonkey.cpp
  • Loading branch information
erh committed May 15, 2009
2 parents 6b8c0c1 + 0516fad commit 2db1e0c
Show file tree
Hide file tree
Showing 34 changed files with 1,161 additions and 266 deletions.
37 changes: 6 additions & 31 deletions SConstruct
Expand Up @@ -207,12 +207,13 @@ coreServerFiles = [ "util/message_server_port.cpp" , "util/message_server_asio.c
serverOnlyFiles = Split( "db/query.cpp db/introspect.cpp db/btree.cpp db/clientcursor.cpp db/tests.cpp db/repl.cpp db/btreecursor.cpp db/cloner.cpp db/namespace.cpp db/matcher.cpp db/dbcommands.cpp db/dbeval.cpp db/dbwebserver.cpp db/dbinfo.cpp db/dbhelpers.cpp db/instance.cpp db/pdfile.cpp db/cursor.cpp db/security_commands.cpp db/security.cpp util/miniwebserver.cpp db/storage.cpp db/reccache.cpp db/queryoptimizer.cpp" ) serverOnlyFiles = Split( "db/query.cpp db/introspect.cpp db/btree.cpp db/clientcursor.cpp db/tests.cpp db/repl.cpp db/btreecursor.cpp db/cloner.cpp db/namespace.cpp db/matcher.cpp db/dbcommands.cpp db/dbeval.cpp db/dbwebserver.cpp db/dbinfo.cpp db/dbhelpers.cpp db/instance.cpp db/pdfile.cpp db/cursor.cpp db/security_commands.cpp db/security.cpp util/miniwebserver.cpp db/storage.cpp db/reccache.cpp db/queryoptimizer.cpp" )


if usesm: if usesm:
serverOnlyFiles += [ "scripting/engine_spidermonkey.cpp" ] commonFiles += [ "scripting/engine_spidermonkey.cpp" ]
nojni = True nojni = True
elif not nojni: elif not nojni:
serverOnlyFiles += [ "scripting/engine_java.cpp" ] commonFiles += [ "scripting/engine_java.cpp" ]
else: else:
serverOnlyFiles += [ "scripting/engine_none.cpp" ] commonFiles += [ "scripting/engine_none.cpp" ]
nojni = True


coreShardFiles = [] coreShardFiles = []
shardServerFiles = coreShardFiles + Glob( "s/strategy*.cpp" ) + [ "s/commands_admin.cpp" , "s/commands_public.cpp" , "s/request.cpp" , "s/cursors.cpp" , "s/server.cpp" ] + [ "s/shard.cpp" , "s/shardkey.cpp" , "s/config.cpp" ] shardServerFiles = coreShardFiles + Glob( "s/strategy*.cpp" ) + [ "s/commands_admin.cpp" , "s/commands_public.cpp" , "s/request.cpp" , "s/cursors.cpp" , "s/server.cpp" ] + [ "s/shard.cpp" , "s/shardkey.cpp" , "s/config.cpp" ]
Expand Down Expand Up @@ -499,12 +500,6 @@ def doConfigure( myenv , needJava=True , needPcre=True , shell=False ):


return False return False


if shell:
if windows:
myenv.Append( LIBS=["v8"] )
else:
myCheckLib( "v8" , True )

if needPcre and not conf.CheckCXXHeader( 'pcrecpp.h' ): if needPcre and not conf.CheckCXXHeader( 'pcrecpp.h' ):
print( "can't find pcre" ) print( "can't find pcre" )
Exit(1) Exit(1)
Expand Down Expand Up @@ -582,15 +577,6 @@ def doConfigure( myenv , needJava=True , needPcre=True , shell=False ):
return conf.Finish() return conf.Finish()


env = doConfigure( env ) env = doConfigure( env )
# --- v8 ---

v8Home = GetOption( "v8home" )

if not os.path.exists( v8Home ):
for poss in [ "../v8" , "../../v8/" , "../open-source/v8" ]:
if os.path.exists( poss ):
v8Home = poss
break


# --- js concat --- # --- js concat ---


Expand Down Expand Up @@ -715,16 +701,12 @@ if darwin or clientEnv["_HAVEPCAP"]:
sniffEnv.Program( "mongosniff" , "tools/sniffer.cpp" ) sniffEnv.Program( "mongosniff" , "tools/sniffer.cpp" )


# --- shell --- # --- shell ---
# shell is complicated by the fact that v8 doesn't work 64-bit yet


env.JSConcat( "shell/mongo.jsall" , Glob( "shell/*.js" ) ) env.JSConcat( "shell/mongo.jsall" , Glob( "shell/*.js" ) )
env.JSHeader( "shell/mongo.jsall" ) env.JSHeader( "shell/mongo.jsall" )


shellEnv = env.Clone(); shellEnv = env.Clone();


shellEnv.Append( CPPPATH=[ "../" , v8Home + "/include/" ] )
shellEnv.Append( LIBPATH=[ v8Home] )

if release and ( ( darwin and force64 ) or linux64 ): if release and ( ( darwin and force64 ) or linux64 ):
shellEnv["LINKFLAGS"] = env["LINKFLAGS_CLEAN"] shellEnv["LINKFLAGS"] = env["LINKFLAGS_CLEAN"]
shellEnv["LIBS"] = env["LIBS_CLEAN"] shellEnv["LIBS"] = env["LIBS_CLEAN"]
Expand All @@ -733,14 +715,7 @@ if release and ( ( darwin and force64 ) or linux64 ):
if noshell: if noshell:
print( "not building shell" ) print( "not building shell" )
elif not onlyServer: elif not onlyServer:
weird = linux64 or force64 weird = force64

if linux64:
shellEnv.Append( CFLAGS="-m32" )
shellEnv.Append( CXXFLAGS="-m32" )
shellEnv.Append( LINKFLAGS="-m32" )
shellEnv.Append( LIBPATH=[ "/usr/lib32" , "/usr/lib" ] )
shellEnv["LIBPATH"].remove( "/usr/lib64" )


if force64: if force64:
shellEnv["CFLAGS"].remove("-m64") shellEnv["CFLAGS"].remove("-m64")
Expand All @@ -762,7 +737,7 @@ elif not onlyServer:
if windows: if windows:
shellEnv.Append( LIBS=["winmm.lib"] ) shellEnv.Append( LIBS=["winmm.lib"] )


coreShellFiles = [ "shell/MongoJS.cpp" , "shell/ShellUtils.cpp" , "shell/dbshell.cpp" , "scripting/engine_v8.cpp" ] coreShellFiles = [ "shell/dbshell.cpp" , "shell/utils.cpp" ]


if weird: if weird:
shell32BitFiles = coreShellFiles shell32BitFiles = coreShellFiles
Expand Down
6 changes: 6 additions & 0 deletions db/jsobj.h
Expand Up @@ -28,6 +28,7 @@


#include "../stdafx.h" #include "../stdafx.h"
#include "../util/builder.h" #include "../util/builder.h"
#include "../util/optime.h"
#include "boost/utility.hpp" #include "boost/utility.hpp"


#include <set> #include <set>
Expand Down Expand Up @@ -1007,6 +1008,11 @@ namespace mongo {
b.append( fieldName ); b.append( fieldName );
b.append( val ); b.append( val );
} }

void appendTimestamp( const char *fieldName , unsigned long long time , unsigned int inc ){
OpTime t( time / 1000 , inc );
appendTimestamp( fieldName , t.asDate() );
}


/* Deprecated (but supported) */ /* Deprecated (but supported) */
void appendDBRef( const char *fieldName, const char *ns, const OID &oid ) { void appendDBRef( const char *fieldName, const char *ns, const OID &oid ) {
Expand Down
2 changes: 1 addition & 1 deletion db/matcher.cpp
Expand Up @@ -143,7 +143,7 @@ namespace mongo {
if ( e.eoo() ) if ( e.eoo() )
break; break;


if ( ( e.type() == CodeWScope || e.type() == Code ) && strcmp(e.fieldName(), "$where")==0 ) { if ( ( e.type() == CodeWScope || e.type() == Code || e.type() == String ) && strcmp(e.fieldName(), "$where")==0 ) {
// $where: function()... // $where: function()...
uassert( "$where occurs twice?", where == 0 ); uassert( "$where occurs twice?", where == 0 );
where = new Where(); where = new Where();
Expand Down
103 changes: 102 additions & 1 deletion dbtests/jstests.cpp
Expand Up @@ -118,6 +118,12 @@ namespace JSTests {
s->setThis( & o ); s->setThis( & o );
s->invoke( "return this.z;" , BSONObj() ); s->invoke( "return this.z;" , BSONObj() );
ASSERT_EQUALS( "sara" , s->getString( "return" ) ); ASSERT_EQUALS( "sara" , s->getString( "return" ) );

s->invoke( "this.z == 'sara';" , BSONObj() );
ASSERT_EQUALS( true , s->getBoolean( "return" ) );

s->invoke( "this.z == 'asara';" , BSONObj() );
ASSERT_EQUALS( false , s->getBoolean( "return" ) );


s->invoke( "return this.x == 17;" , BSONObj() ); s->invoke( "return this.x == 17;" , BSONObj() );
ASSERT_EQUALS( true , s->getBoolean( "return" ) ); ASSERT_EQUALS( true , s->getBoolean( "return" ) );
Expand Down Expand Up @@ -214,7 +220,100 @@ namespace JSTests {
delete s; delete s;
} }
}; };


class OtherJSTypes {
public:
void run(){
Scope * s = globalScriptEngine->createScope();

{ // date
BSONObj o;
{
BSONObjBuilder b;
b.appendDate( "d" , 123456789 );
o = b.obj();
}
s->setObject( "x" , o );

s->invoke( "return x.d.getTime() != 12;" , BSONObj() );
ASSERT_EQUALS( true, s->getBoolean( "return" ) );

s->invoke( "z = x.d.getTime();" , BSONObj() );
ASSERT_EQUALS( 123456789 , s->getNumber( "z" ) );

s->invoke( "z = { z : x.d }" , BSONObj() );
BSONObj out = s->getObject( "z" );
ASSERT( out["z"].type() == Date );
}

{ // regex
BSONObj o;
{
BSONObjBuilder b;
b.appendRegex( "r" , "^a" , "i" );
o = b.obj();
}
s->setObject( "x" , o );

s->invoke( "z = x.r.test( 'b' );" , BSONObj() );
ASSERT_EQUALS( false , s->getBoolean( "z" ) );

s->invoke( "z = x.r.test( 'a' );" , BSONObj() );
ASSERT_EQUALS( true , s->getBoolean( "z" ) );

s->invoke( "z = x.r.test( 'ba' );" , BSONObj() );
ASSERT_EQUALS( false , s->getBoolean( "z" ) );

s->invoke( "z = { a : x.r };" , BSONObj() );

BSONObj out = s->getObject("z");
ASSERT_EQUALS( (string)"^a" , out["a"].regex() );
ASSERT_EQUALS( (string)"i" , out["a"].regexFlags() );

}

delete s;
}
};

class SpecialDBTypes {
public:
void run(){
Scope * s = globalScriptEngine->createScope();

BSONObjBuilder b;
b.appendTimestamp( "a" , 123456789 );
b.appendMinKey( "b" );
b.appendMaxKey( "c" );
b.appendTimestamp( "d" , 1234000 , 9876 );


{
BSONObj t = b.done();
ASSERT_EQUALS( 1234000 , t["d"].timestampTime() );
ASSERT_EQUALS( 9876 , t["d"].timestampInc() );
}

s->setObject( "z" , b.obj() );

assert( s->invoke( "y = { a : z.a , b : z.b , c : z.c , d: z.d }" , BSONObj() ) == 0 );

BSONObj out = s->getObject( "y" );
ASSERT_EQUALS( Timestamp , out["a"].type() );
ASSERT_EQUALS( MinKey , out["b"].type() );
ASSERT_EQUALS( MaxKey , out["c"].type() );
ASSERT_EQUALS( Timestamp , out["d"].type() );

ASSERT_EQUALS( 9876 , out["d"].timestampInc() );
ASSERT_EQUALS( 1234000 , out["d"].timestampTime() );
ASSERT_EQUALS( 123456789 , out["a"].date() );


delete s;
}
};


class All : public Suite { class All : public Suite {
public: public:
All() { All() {
Expand All @@ -226,6 +325,8 @@ namespace JSTests {
add< ObjectDecoding >(); add< ObjectDecoding >();
add< JSOIDTests >(); add< JSOIDTests >();
add< ObjectModTests >(); add< ObjectModTests >();
add< OtherJSTypes >();
add< SpecialDBTypes >();
} }
}; };


Expand Down
25 changes: 13 additions & 12 deletions jstests/apitest_dbcollection.js
Expand Up @@ -64,51 +64,52 @@ assert(v.result.toString().match(/nrecords\?:(\d+)/)[1] == 100,11);
db.getCollection( "test_db" ).drop(); db.getCollection( "test_db" ).drop();
assert(db.getCollection( "test_db" ).count() == 0,12); assert(db.getCollection( "test_db" ).count() == 0,12);
db.getCollection( "test_db" ).dropIndexes(); db.getCollection( "test_db" ).dropIndexes();
assert(db.getCollection( "test_db" ).getIndexes().length() == 0,13); assert(db.getCollection( "test_db" ).getIndexes().length == 0,13);


db.getCollection( "test_db" ).save({a:10}); db.getCollection( "test_db" ).save({a:10});
assert(db.getCollection( "test_db" ).getIndexes().length() == 1,14); assert(db.getCollection( "test_db" ).getIndexes().length == 1,14);


db.getCollection( "test_db" ).ensureIndex({a:1}); db.getCollection( "test_db" ).ensureIndex({a:1});
db.getCollection( "test_db" ).save({a:10}); db.getCollection( "test_db" ).save({a:10});


assert(db.getCollection( "test_db" ).getIndexes().length() == 2,15); print( tojson( db.getCollection( "test_db" ).getIndexes() ) );
assert.eq(db.getCollection( "test_db" ).getIndexes().length , 2,15);


db.getCollection( "test_db" ).dropIndex({a:1}); db.getCollection( "test_db" ).dropIndex({a:1});
assert(db.getCollection( "test_db" ).getIndexes().length() == 1,16); assert(db.getCollection( "test_db" ).getIndexes().length == 1,16);


db.getCollection( "test_db" ).save({a:10}); db.getCollection( "test_db" ).save({a:10});
db.getCollection( "test_db" ).ensureIndex({a:1}); db.getCollection( "test_db" ).ensureIndex({a:1});
db.getCollection( "test_db" ).save({a:10}); db.getCollection( "test_db" ).save({a:10});


assert(db.getCollection( "test_db" ).getIndexes().length() == 2,17); assert(db.getCollection( "test_db" ).getIndexes().length == 2,17);


db.getCollection( "test_db" ).dropIndex("a_1"); db.getCollection( "test_db" ).dropIndex("a_1");
assert.eq( db.getCollection( "test_db" ).getIndexes().length() , 1,18); assert.eq( db.getCollection( "test_db" ).getIndexes().length , 1,18);


db.getCollection( "test_db" ).save({a:10, b:11}); db.getCollection( "test_db" ).save({a:10, b:11});
db.getCollection( "test_db" ).ensureIndex({a:1}); db.getCollection( "test_db" ).ensureIndex({a:1});
db.getCollection( "test_db" ).ensureIndex({b:1}); db.getCollection( "test_db" ).ensureIndex({b:1});
db.getCollection( "test_db" ).save({a:10, b:12}); db.getCollection( "test_db" ).save({a:10, b:12});


assert(db.getCollection( "test_db" ).getIndexes().length() == 3,19); assert(db.getCollection( "test_db" ).getIndexes().length == 3,19);


db.getCollection( "test_db" ).dropIndex({b:1}); db.getCollection( "test_db" ).dropIndex({b:1});
assert(db.getCollection( "test_db" ).getIndexes().length() == 2,20); assert(db.getCollection( "test_db" ).getIndexes().length == 2,20);
db.getCollection( "test_db" ).dropIndex({a:1}); db.getCollection( "test_db" ).dropIndex({a:1});
assert(db.getCollection( "test_db" ).getIndexes().length() == 1,21); assert(db.getCollection( "test_db" ).getIndexes().length == 1,21);


db.getCollection( "test_db" ).save({a:10, b:11}); db.getCollection( "test_db" ).save({a:10, b:11});
db.getCollection( "test_db" ).ensureIndex({a:1}); db.getCollection( "test_db" ).ensureIndex({a:1});
db.getCollection( "test_db" ).ensureIndex({b:1}); db.getCollection( "test_db" ).ensureIndex({b:1});
db.getCollection( "test_db" ).save({a:10, b:12}); db.getCollection( "test_db" ).save({a:10, b:12});


assert(db.getCollection( "test_db" ).getIndexes().length() == 3,22); assert(db.getCollection( "test_db" ).getIndexes().length == 3,22);


db.getCollection( "test_db" ).dropIndexes(); db.getCollection( "test_db" ).dropIndexes();
assert(db.getCollection( "test_db" ).getIndexes().length() == 1,23); assert(db.getCollection( "test_db" ).getIndexes().length == 1,23);


db.getCollection( "test_db" ).find(); db.getCollection( "test_db" ).find();


db.getCollection( "test_db" ).drop(); db.getCollection( "test_db" ).drop();
assert(db.getCollection( "test_db" ).getIndexes().length() == 0,24); assert(db.getCollection( "test_db" ).getIndexes().length == 0,24);
21 changes: 11 additions & 10 deletions jstests/count.js
Expand Up @@ -3,22 +3,23 @@ t = db.jstests_count;
t.drop(); t.drop();
t.save( { i: 1 } ); t.save( { i: 1 } );
t.save( { i: 2 } ); t.save( { i: 2 } );
assert.eq( 1, t.find( { i: 1 } ).count() ); assert.eq( 1, t.find( { i: 1 } ).count(), "A" );
assert.eq( 1, t.count( { i: 1 } ) ); assert.eq( 1, t.count( { i: 1 } ) , "B" );
assert.eq( 2, t.find().count() ); assert.eq( 2, t.find().count() , "C" );
assert.eq( 2, t.find( undefined ).count() ); assert.eq( 2, t.find( undefined ).count() , "D" );
assert.eq( 2, t.find( null ).count() ); assert.eq( 2, t.find( null ).count() , "E" );
assert.eq( 2, t.count() ); assert.eq( 2, t.count() , "F" );


t.drop(); t.drop();
t.save( {a:true,b:false} ); t.save( {a:true,b:false} );
t.ensureIndex( {b:1,a:1} ); t.ensureIndex( {b:1,a:1} );
assert.eq( 1, t.find( {a:true,b:false} ).count() ); assert.eq( 1, t.find( {a:true,b:false} ).count() , "G" );
assert.eq( 1, t.find( {b:false,a:true} ).count() ); assert.eq( 1, t.find( {b:false,a:true} ).count() , "H" );


t.drop(); t.drop();
t.save( {a:true,b:false} ); t.save( {a:true,b:false} );
t.ensureIndex( {b:1,a:1,c:1} ); t.ensureIndex( {b:1,a:1,c:1} );
assert.eq( 1, t.find( {a:true,b:false} ).count() );
assert.eq( 1, t.find( {b:false,a:true} ).count() ); assert.eq( 1, t.find( {a:true,b:false} ).count() , "I" );
assert.eq( 1, t.find( {b:false,a:true} ).count() , "J" );


8 changes: 8 additions & 0 deletions jstests/date1.js
@@ -0,0 +1,8 @@

t = db.date1;
t.drop();

d = new Date()
t.save( { a : 1 , d : d } );

assert.eq( d , t.findOne().d , "A" )
16 changes: 8 additions & 8 deletions jstests/drop.js
Expand Up @@ -2,20 +2,20 @@ f = db.jstests_drop;


f.drop(); f.drop();


assert.eq( 0, db.system.indexes.find( {ns:"test.jstests_drop"} ).count() ); assert.eq( 0, db.system.indexes.find( {ns:"test.jstests_drop"} ).count() , "A" );
f.save( {} ); f.save( {} );
assert.eq( 1, db.system.indexes.find( {ns:"test.jstests_drop"} ).count() ); assert.eq( 1, db.system.indexes.find( {ns:"test.jstests_drop"} ).count() , "B" );
f.ensureIndex( {a:1} ); f.ensureIndex( {a:1} );
assert.eq( 2, db.system.indexes.find( {ns:"test.jstests_drop"} ).count() ); assert.eq( 2, db.system.indexes.find( {ns:"test.jstests_drop"} ).count() , "C" );
assert.commandWorked( db.runCommand( {drop:"jstests_drop"} ) ); assert.commandWorked( db.runCommand( {drop:"jstests_drop"} ) );
assert.eq( 0, db.system.indexes.find( {ns:"test.jstests_drop"} ).count() ); assert.eq( 0, db.system.indexes.find( {ns:"test.jstests_drop"} ).count() , "D" );


f = db.jstests_drop; f.resetIndexCache();
f.ensureIndex( {a:1} ); f.ensureIndex( {a:1} );
assert.eq( 2, db.system.indexes.find( {ns:"test.jstests_drop"} ).count() ); assert.eq( 2, db.system.indexes.find( {ns:"test.jstests_drop"} ).count() , "E" );
assert.commandWorked( db.runCommand( {deleteIndexes:"jstests_drop",index:"*"} ) ); assert.commandWorked( db.runCommand( {deleteIndexes:"jstests_drop",index:"*"} ) );
assert.eq( 1, db.system.indexes.find( {ns:"test.jstests_drop"} ).count() ); assert.eq( 1, db.system.indexes.find( {ns:"test.jstests_drop"} ).count() , "G" );


// make sure we can still use it // make sure we can still use it
f.save( {} ); f.save( {} );
assert.eq( 1, f.find().hint( {_id:ObjectId( "000000000000000000000000" )} ).toArray().length ); assert.eq( 1, f.find().hint( {_id:new ObjectId( "000000000000000000000000" )} ).toArray().length , "H" );
2 changes: 1 addition & 1 deletion jstests/hint1.js
Expand Up @@ -5,4 +5,4 @@ p.ensureIndex( { ts: 1 } );


e = p.find( { live: true, ts: { $lt: new Date( 1234119308272 ) }, cls: "entry", verticals: " alleyinsider" } ).sort( { ts: -1 } ).hint( { ts: 1 } ).explain(); e = p.find( { live: true, ts: { $lt: new Date( 1234119308272 ) }, cls: "entry", verticals: " alleyinsider" } ).sort( { ts: -1 } ).hint( { ts: 1 } ).explain();
assert.eq( e.startKey.ts.getTime(), new Date( 1234119308272 ).getTime() ); assert.eq( e.startKey.ts.getTime(), new Date( 1234119308272 ).getTime() );
assert.eq( 1, e.endKey.ts.$minElement ); assert.eq( 1, e.endKey.ts.$minElement );

0 comments on commit 2db1e0c

Please sign in to comment.