0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-12-01 09:32:32 +01:00

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

This commit is contained in:
Eliot Horowitz 2009-04-07 12:19:36 -04:00
commit f93d932d0a
11 changed files with 83 additions and 55 deletions

2
README
View File

@ -22,6 +22,8 @@ BUILDING
$ cd v8
$ scons libv8.a
- Pre-requisite for 'test' binary, the MongoDB unit test suite:
To compile the unit tests, you need to install the unit test framework from:
http://unittest.red-bean.com/

View File

@ -44,7 +44,7 @@ namespace mongo {
~ClientCursor();
const CursorId cursorid;
string ns;
auto_ptr<JSMatcher> matcher;
auto_ptr<KeyValJSMatcher> matcher;
auto_ptr<Cursor> c;
int pos; /* # objects into the cursor so far */
DiskLoc lastLoc() const {

View File

@ -60,14 +60,14 @@ namespace mongo {
if ( !c_->ok() )
setComplete();
else
matcher_.reset( new JSMatcher( qp().query() ) );
matcher_.reset( new KeyValJSMatcher( qp().query(), qp().indexKey() ) );
}
virtual void next() {
if ( !c_->ok() ) {
setComplete();
return;
}
if ( matcher_->matches( c_->currLoc().rec() ) ) {
if ( matcher_->matches( c_->currKey(), c_->currLoc() ) ) {
one_ = c_->current();
setComplete();
} else {
@ -80,7 +80,7 @@ namespace mongo {
private:
bool requireIndex_;
auto_ptr< Cursor > c_;
auto_ptr< JSMatcher > matcher_;
auto_ptr< KeyValJSMatcher > matcher_;
BSONObj one_;
};

View File

@ -115,25 +115,19 @@ namespace mongo {
namespace mongo {
// KeyValJSMatcher::KeyValJSMatcher(const BSONObj &_jsobj, const BSONObj &indexKeyPattern) :
// keyMatcher_(_jsobj.filterFieldsUndotted(indexKeyPattern, true), indexKeyPattern),
// recordMatcher_(_jsobj.filterFieldsUndotted(indexKeyPattern, false)) {
// }
//
// bool KeyValJSMatcher::matches(const BSONObj &key, const DiskLoc &recLoc, bool *deep) {
// if ( keyMatcher_.keyMatch() ) {
// if ( !keyMatcher_.matches(key, deep) ) {
// return false;
// }
// } else {
// if ( !keyMatcher_.matches(recLoc.rec(), deep) ) {
// return false;
// }
// }
// if ( recordMatcher_.trivial() )
// return true;
// return recordMatcher_.matches(recLoc.rec(), deep);
// }
KeyValJSMatcher::KeyValJSMatcher(const BSONObj &_jsobj, const BSONObj &indexKeyPattern) :
keyMatcher_(_jsobj.filterFieldsUndotted(indexKeyPattern, true), indexKeyPattern),
recordMatcher_(_jsobj) {
}
bool KeyValJSMatcher::matches(const BSONObj &key, const DiskLoc &recLoc, bool *deep) {
if ( keyMatcher_.keyMatch() ) {
if ( !keyMatcher_.matches(key, deep) ) {
return false;
}
}
return recordMatcher_.matches(recLoc.rec(), deep);
}
/* _jsobj - the query pattern

View File

@ -143,15 +143,15 @@ namespace mongo {
int nBuilders;
};
// // If match succeeds on index key, then attempt to match full record.
// class KeyValJSMatcher : boost::noncopyable {
// public:
// KeyValJSMatcher(const BSONObj &pattern, const BSONObj &indexKeyPattern);
// bool matches(const BSONObj &j, bool *deep = 0);
// bool matches(const BSONObj &key, const DiskLoc &recLoc, bool *deep = 0);
// private:
// JSMatcher keyMatcher_;
// JSMatcher recordMatcher_;
// };
// If match succeeds on index key, then attempt to match full record.
class KeyValJSMatcher : boost::noncopyable {
public:
KeyValJSMatcher(const BSONObj &pattern, const BSONObj &indexKeyPattern);
bool matches(const BSONObj &j, bool *deep = 0);
bool matches(const BSONObj &key, const DiskLoc &recLoc, bool *deep = 0);
private:
JSMatcher keyMatcher_;
JSMatcher recordMatcher_;
};
} // namespace mongo

View File

@ -1144,7 +1144,9 @@ assert( !eloc.isNull() );
Note that btree buckets which we insert aren't BSONObj's, but in that case god==true.
*/
BSONObj io((const char *) obuf);
if( !io.hasField("_id") && !addIndex && strstr(ns, ".local.") == 0 ) {
BSONElement idField = io.getField( "_id" );
uassert( "_id cannot not be an array", idField.type() != Array );
if( idField.eoo() && !addIndex && strstr(ns, ".local.") == 0 ) {
addID = len;
if ( writeId.eoo() ) {
// Very likely we'll add this elt, so little harm in init'ing here.

View File

@ -60,7 +60,7 @@ namespace mongo {
}
virtual void init() {
c_ = qp().newCursor();
matcher_.reset( new JSMatcher( qp().query() ) );
matcher_.reset( new KeyValJSMatcher( qp().query(), qp().indexKey() ) );
}
virtual void next() {
if ( !c_->ok() ) {
@ -71,7 +71,7 @@ namespace mongo {
DiskLoc rloc = c_->currLoc();
bool deep;
if ( matcher_->matches(rloc.rec(), &deep) ) {
if ( matcher_->matches(c_->currKey(), rloc, &deep) ) {
if ( !deep || !c_->getsetdup(rloc) )
++count_;
}
@ -99,7 +99,7 @@ namespace mongo {
int &bestCount_;
long long nScanned_;
auto_ptr< Cursor > c_;
auto_ptr< JSMatcher > matcher_;
auto_ptr< KeyValJSMatcher > matcher_;
};
/* ns: namespace, e.g. <database>.<collection>
@ -130,13 +130,13 @@ namespace mongo {
if( !c->ok() )
return nDeleted;
JSMatcher matcher(pattern);
KeyValJSMatcher matcher(pattern, c->indexKeyPattern());
do {
DiskLoc rloc = c->currLoc();
bool deep;
if ( !matcher.matches(rloc.rec(), &deep) ) {
if ( !matcher.matches(c->currKey(), rloc, &deep) ) {
c->advance(); // advance must be after noMoreMatches() because it uses currKey()
}
else {
@ -545,7 +545,7 @@ namespace mongo {
if ( !c_->ok() )
setComplete();
else
matcher_.reset( new JSMatcher( pattern ) );
matcher_.reset( new KeyValJSMatcher( pattern, qp().indexKey() ) );
}
virtual void next() {
if ( !c_->ok() ) {
@ -553,7 +553,7 @@ namespace mongo {
return;
}
nscanned_++;
if ( matcher_->matches(c_->currLoc().rec()) ) {
if ( matcher_->matches(c_->currKey(), c_->currLoc()) ) {
setComplete();
return;
}
@ -568,7 +568,7 @@ namespace mongo {
private:
auto_ptr< Cursor > c_;
long long nscanned_;
auto_ptr< JSMatcher > matcher_;
auto_ptr< KeyValJSMatcher > matcher_;
};
int __updateObjects(const char *ns, BSONObj updateobj, BSONObj &pattern, bool upsert, stringstream& ss, bool logop=false) {
@ -810,7 +810,7 @@ namespace mongo {
break;
}
bool deep;
if ( !cc->matcher->matches(c->currLoc().rec(), &deep) ) {
if ( !cc->matcher->matches(c->currKey(), c->currLoc(), &deep) ) {
}
else {
//out() << "matches " << c->currLoc().toString() << ' ' << deep << '\n';
@ -862,7 +862,7 @@ namespace mongo {
bc_->forgetEndKey();
}
else {
matcher_.reset( new JSMatcher( query_ ) );
matcher_.reset( new KeyValJSMatcher( query_, c_->indexKeyPattern() ) );
}
}
virtual void next() {
@ -888,7 +888,7 @@ namespace mongo {
}
} else {
bool deep;
if ( !matcher_->matches(c_->currLoc().rec(), &deep) ) {
if ( !matcher_->matches(c_->currKey(), c_->currLoc(), &deep) ) {
}
else if ( !deep || !c_->getsetdup(c_->currLoc()) ) { // i.e., check for dups on deep items only
bool match = true;
@ -919,7 +919,7 @@ namespace mongo {
BSONObj query_;
set< string > fields_;
BtreeCursor *bc_;
auto_ptr< JSMatcher > matcher_;
auto_ptr< KeyValJSMatcher > matcher_;
BSONObj firstMatch_;
};
@ -978,7 +978,7 @@ namespace mongo {
else
c_ = qp().newCursor();
matcher_.reset(new JSMatcher(qp().query()));
matcher_.reset(new KeyValJSMatcher(qp().query(), qp().indexKey()));
if ( qp().scanAndOrderRequired() ) {
ordering_ = true;
@ -991,7 +991,7 @@ namespace mongo {
if ( !c_->ok() ) {
findingStart_ = false;
c_ = qp().newCursor();
} else if ( !matcher_->matches( c_->currLoc().rec() ) ) {
} else if ( !matcher_->matches( c_->currKey(), c_->currLoc() ) ) {
findingStart_ = false;
c_ = qp().newCursor( c_->currLoc() );
} else {
@ -1007,7 +1007,7 @@ namespace mongo {
nscanned_++;
bool deep;
if ( !matcher_->matches(c_->currLoc().rec(), &deep) ) {
if ( !matcher_->matches(c_->currKey(), c_->currLoc(), &deep) ) {
}
else if ( !deep || !c_->getsetdup(c_->currLoc()) ) { // i.e., check for dups on deep items only
BSONObj js = c_->current();
@ -1082,7 +1082,7 @@ namespace mongo {
BufBuilder &builder() { return b_; }
bool scanAndOrderRequired() const { return ordering_; }
auto_ptr< Cursor > cursor() { return c_; }
auto_ptr< JSMatcher > matcher() { return matcher_; }
auto_ptr< KeyValJSMatcher > matcher() { return matcher_; }
int n() const { return n_; }
long long nscanned() const { return nscanned_; }
bool saveClientCursor() const { return saveClientCursor_; }
@ -1098,7 +1098,7 @@ namespace mongo {
auto_ptr< Cursor > c_;
long long nscanned_;
int queryOptions_;
auto_ptr< JSMatcher > matcher_;
auto_ptr< KeyValJSMatcher > matcher_;
int n_;
int soSize_;
bool saveClientCursor_;

View File

@ -322,6 +322,20 @@ namespace QueryTests {
}
};
class ArrayId : public ClientBase {
public:
~ArrayId() {
client().dropCollection( "querytests.ArrayId" );
}
void run() {
const char *ns = "querytests.ArrayId";
client().ensureIndex( ns, BSON( "_id" << 1 ) );
ASSERT( !error() );
client().insert( ns, fromjson( "{'_id':[1,2]}" ) );
ASSERT( error() );
}
};
class All : public UnitTest::Suite {
public:
All() {
@ -338,6 +352,7 @@ namespace QueryTests {
add< TailableDelete >();
add< TailableInsertDelete >();
add< OplogReplayMode >();
add< ArrayId >();
}
};

View File

@ -4,3 +4,4 @@ t.drop();
t.ensureIndex( { a: 1 } );
t.save( { a: [ 1, 2 ] } );
assert.eq( 1, t.find( { a: { $gt: 0 } } ).count() );
assert.eq( 1, t.find( { a: { $gt: 0 } } ).toArray().length );

View File

@ -37,7 +37,7 @@
93278F670F72D39400844664 /* strategy_shard.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = strategy_shard.cpp; sourceTree = "<group>"; };
932AC3EB0F4A5B34005BF8B0 /* queryoptimizertests.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = queryoptimizertests.cpp; sourceTree = "<group>"; };
932AC4310F4A5E9D005BF8B0 /* SConstruct */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = SConstruct; sourceTree = "<group>"; };
9339D2610F8A5DD60063DBEF /* multi.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = multi.js; sourceTree = "<group>"; };
9339D4470F8B9D290063DBEF /* multi.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = multi.js; sourceTree = "<group>"; };
933A4D130F55A68600145C4B /* authTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = authTest.cpp; sourceTree = "<group>"; };
933A4D150F55A68600145C4B /* clientTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = clientTest.cpp; sourceTree = "<group>"; };
933A4D170F55A68600145C4B /* first.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = first.cpp; sourceTree = "<group>"; };
@ -540,7 +540,7 @@
93A8D1D10F37544800C92B85 /* jstests */ = {
isa = PBXGroup;
children = (
9339D2610F8A5DD60063DBEF /* multi.js */,
9339D4470F8B9D290063DBEF /* multi.js */,
93202DE40F879CB600AF3B71 /* all.js */,
93CCC87F0F8562E900E20FA0 /* datasize.js */,
93D949B40F7D2A7700C3C768 /* median.js */,

View File

@ -467,6 +467,16 @@ v8::Handle< v8::Value > ResetDbpath( const v8::Arguments &a ) {
return v8::Undefined();
}
inline void time_t_to_String(time_t t, char *buf) {
#if defined(_WIN32)
ctime_s(buf, 64, &t);
#else
ctime_r(&t, buf);
#endif
buf[24] = 0; // don't want the \n
buf[ 20 ] = 0;
}
void killDb( int port, int signal ) {
if( dbs.count( port ) != 1 ) {
cout << "No db started on port: " << port << endl;
@ -479,7 +489,9 @@ void killDb( int port, int signal ) {
int i = 0;
for( ; i < 65; ++i ) {
if ( i == 5 ) {
cout << "process on port " << port << ", with pid " << pid << " not terminated, sending sigkill" << endl;
char now[64];
time_t_to_String(time(0), now);
cout << now << " process on port " << port << ", with pid " << pid << " not terminated, sending sigkill" << endl;
assert( 0 == kill( pid, SIGKILL ) );
}
int temp;
@ -489,7 +501,9 @@ void killDb( int port, int signal ) {
sleepms( 1000 );
}
if ( i == 65 ) {
cout << "failed to terminate process on port " << port << ", with pid " << pid << endl;
char now[64];
time_t_to_String(time(0), now);
cout << now << " failed to terminate process on port " << port << ", with pid " << pid << endl;
assert( "Failed to terminate process" == 0 );
}