Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
astaple committed Jul 8, 2010
2 parents f17aefd + ce24481 commit 0adc465
Show file tree
Hide file tree
Showing 15 changed files with 324 additions and 198 deletions.
4 changes: 2 additions & 2 deletions bson/stringdata.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ namespace mongo {
// 'data' *always* finishes with a null terminator
// 'size' does *not* account for the null terminator
// These assumptions may make it easier to minimize changes to existing code
const char* data;
const unsigned size;
const char* const data;
const unsigned size;

StringData( const char* c )
: data(c), size(strlen(c)) {}
Expand Down
9 changes: 4 additions & 5 deletions db/btree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,14 +310,13 @@ namespace mongo {
topSize = 0;
int i = 0;
for ( int j = 0; j < n; j++ ) {
if( j > 0 && k( j ).isUnused() && k( j ).prevChildBucket.isNull() ) {
if ( i < refPos ) {
--refPos;
}
// FIXME don't drop ref pos
if( j > 0 && ( j != refPos ) && k( j ).isUnused() && k( j ).prevChildBucket.isNull() ) {
continue; // key is unused and has no children - drop it
}
if( i != j ) {
if ( j == refPos ) {
refPos = i; // i < j so j will never be refPos again
}
k( i ) = k( j );
}
short ofsold = k(i).keyDataOfs();
Expand Down
82 changes: 12 additions & 70 deletions db/db.rc
Original file line number Diff line number Diff line change
@@ -1,70 +1,12 @@
// Microsoft Visual C++ generated resource script.
//
#include "resource.h"

#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "afxres.h"

/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS

/////////////////////////////////////////////////////////////////////////////
// English (United States) resources

#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)

#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//

1 TEXTINCLUDE
BEGIN
"resource.h\0"
END

2 TEXTINCLUDE
BEGIN
"#include ""afxres.h""\r\n"
"\0"
END

3 TEXTINCLUDE
BEGIN
"\r\n"
"\0"
END

#endif // APSTUDIO_INVOKED


/////////////////////////////////////////////////////////////////////////////
//
// Icon
//

// Icon with lowest ID value placed first to ensure application icon
// remains consistent on all systems.
IDI_ICON2 ICON "mongo.ico"
#endif // English (United States) resources
/////////////////////////////////////////////////////////////////////////////



#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//


/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED

// Microsoft Visual C++ generated resource script.
//
#include "resource.h"

/////////////////////////////////////////////////////////////////////////////
//
// Icon
//
// Icon with lowest ID value placed first to ensure application icon
// remains consistent on all systems.
IDI_ICON2 ICON "mongo.ico"
/////////////////////////////////////////////////////////////////////////////
4 changes: 4 additions & 0 deletions db/repl/heartbeat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ namespace mongo {
/* throws dbexception */
bool requestHeartbeat(string setName, string memberFullName, BSONObj& result, int myCfgVersion, int& theirCfgVersion, bool checkEmpty) {
BSONObj cmd = BSON( "replSetHeartbeat" << setName << "v" << myCfgVersion << "pv" << 1 << "checkEmpty" << checkEmpty );

// we might be talking to ourself - generally not a great idea to do outbound waiting calls in a write lock
assert( !dbMutex.isWriteLocked() );

ScopedConn conn(memberFullName);
return conn->runCommand("admin", cmd, result);
}
Expand Down
14 changes: 7 additions & 7 deletions db/repl/rs_initiate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ namespace mongo {
}
}
catch(DBException& e) {
log() << "replSet info " << i->h.toString() << " : " << e.toString() << rsLog;
log() << "replSet requestHeartbeat " << i->h.toString() << " : " << e.toString() << rsLog;
}
catch(...) {
log() << "replSet error exception in requestHeartbeat?" << rsLog;
Expand All @@ -78,7 +78,7 @@ namespace mongo {

class CmdReplSetInitiate : public ReplSetCommand {
public:
virtual LockType locktype() const { return WRITE; }
virtual LockType locktype() const { return NONE; }
CmdReplSetInitiate() : ReplSetCommand("replSetInitiate") { }
virtual void help(stringstream& h) const {
h << "Initiate/christen a replica set.";
Expand Down Expand Up @@ -145,19 +145,19 @@ namespace mongo {

log() << "replSet replSetInitiate all members seem up" << rsLog;

writelock lk("");
bo comment = BSON( "msg" << "initiating set");
newConfig.saveConfigLocally(comment);
log() << "replSet replSetInitiate config now saved locally. Should come online in about a minute." << rsLog;
result.append("info", "Config now saved locally. Should come online in about a minute.");
ReplSet::startupStatus = ReplSet::SOON;
ReplSet::startupStatusMsg = "Received replSetInitiate - should come online shortly.";
}
catch( DBException& e ) {
log() << "replSet replSetInitiate exception: " << e.what() << rsLog;
throw;
}

log() << "replSet replSetInitiate config now saved locally. Should come online in about a minute." << rsLog;
result.append("info", "Config now saved locally. Should come online in about a minute.");
ReplSet::startupStatus = ReplSet::SOON;
ReplSet::startupStatusMsg = "Received replSetInitiate - should come online shortly.";

return true;
}
} cmdReplSetInitiate;
Expand Down
33 changes: 32 additions & 1 deletion dbtests/btreetests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ namespace BtreeTests {

ASSERT( unused2 < unused );
}
private:
protected:
void insert( long long n ) {
string val( 800, ' ' );
for( int i = 0; i < 800; i += 8 ) {
Expand All @@ -337,6 +337,36 @@ namespace BtreeTests {
}
};

class DontDropReferenceKey : public PackUnused {
public:
void run() {
// with 80 root node is full
for ( long long i = 0; i < 80; i += 1 ) {
insert( i );
}

BSONObjBuilder start;
start.appendMinKey( "a" );
BSONObjBuilder end;
end.appendMaxKey( "a" );
BSONObj l = bt()->keyNode( 0 ).key;
string toInsert;
auto_ptr< BtreeCursor > c( new BtreeCursor( nsdetails( ns() ), 1, id(), start.done(), end.done(), false, 1 ) );
while( c->ok() ) {
if ( c->currKey().woCompare( l ) > 0 ) {
toInsert = c->currKey().firstElement().valuestr();
break;
}
c->advance();
}
// too much work to try to make this happen through inserts and deletes
const_cast< DiskLoc& >( bt()->keyNode( 1 ).prevChildBucket ) = DiskLoc();
const_cast< DiskLoc& >( bt()->keyNode( 1 ).recordLoc ).GETOFS() |= 1; // make unused
BSONObj k = BSON( "a" << toInsert );
Base::insert( k );
}
};

class All : public Suite {
public:
All() : Suite( "btree" ){
Expand All @@ -352,6 +382,7 @@ namespace BtreeTests {
add< SERVER983 >();
add< ReuseUnused >();
add< PackUnused >();
add< DontDropReferenceKey >();
}
} myall;
}
Expand Down
2 changes: 1 addition & 1 deletion dbtests/jstests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -825,7 +825,7 @@ namespace JSTests {
// check that BinData js class is utilized
s->invokeSafe( "q = x.b.toString();", BSONObj() );
stringstream expected;
expected << "BinData( type: " << BinDataGeneral << ", base64: \"" << base64 << "\" )";
expected << "BinData(" << BinDataGeneral << ",\"" << base64 << "\")";
ASSERT_EQUALS( expected.str(), s->getString( "q" ) );

stringstream scriptBuilder;
Expand Down
65 changes: 60 additions & 5 deletions scripting/sm_db.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,6 @@ namespace mongo {
{ 0 }
};


// ------------- db_collection -------------

JSBool db_collection_constructor( JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval ){
Expand Down Expand Up @@ -590,8 +589,19 @@ namespace mongo {
if ( argc == 2 ){

int type = (int)c.toNumber( argv[ 0 ] );
if( type < 0 || type > 255 ) {
JS_ReportError( cx , "invalid BinData subtype -- range is 0..255 see bsonspec.org" );
return JS_FALSE;
}
string encoded = c.toString( argv[ 1 ] );
string decoded = base64::decode( encoded );
string decoded;
try {
decoded = base64::decode( encoded );
}
catch(...) {
JS_ReportError(cx, "BinData could not decode base64 parameter");
return JS_FALSE;
}

assert( JS_SetPrivate( cx, obj, new BinDataHolder( decoded.data(), decoded.length() ) ) );
c.setProperty( obj, "len", c.toval( (double)decoded.length() ) );
Expand All @@ -600,7 +610,7 @@ namespace mongo {
return JS_TRUE;
}
else {
JS_ReportError( cx , "BinData needs 2 arguments" );
JS_ReportError( cx , "BinData needs 2 arguments -- BinData(subtype,data)" );
return JS_FALSE;
}
}
Expand All @@ -613,13 +623,54 @@ namespace mongo {
assert( holder );
const char *data = ( ( BinDataHolder* )( holder ) )->c_;
stringstream ss;
ss << "BinData( type: " << type << ", base64: \"";
ss << "BinData(" << type << ",\"";
base64::encode( ss, (const char *)data, len );
ss << "\" )";
ss << "\")";
string ret = ss.str();
return *rval = c.toval( ret.c_str() );
}

JSBool bindataBase64(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval){
Convertor c(cx);
int len = (int)c.getNumber( obj, "len" );
void *holder = JS_GetPrivate( cx, obj );
assert( holder );
const char *data = ( ( BinDataHolder* )( holder ) )->c_;
stringstream ss;
base64::encode( ss, (const char *)data, len );
string ret = ss.str();
return *rval = c.toval( ret.c_str() );
}

JSBool bindataAsHex(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval){
Convertor c(cx);
int type = (int)c.getNumber( obj , "type" );
int len = (int)c.getNumber( obj, "len" );
void *holder = JS_GetPrivate( cx, obj );
assert( holder );
const char *data = ( ( BinDataHolder* )( holder ) )->c_;
stringstream ss;
ss << hex;
for( int i = 0; i < len; i++ ) {
unsigned v = (unsigned char) data[i];
ss << v;
}
string ret = ss.str();
return *rval = c.toval( ret.c_str() );
}

JSBool bindataLength(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval){
Convertor c(cx);
int len = (int)c.getNumber( obj, "len" );
return *rval = c.toval((double) len);
}

JSBool bindataSubtype(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval){
Convertor c(cx);
int t = (int)c.getNumber( obj, "type" );
return *rval = c.toval((double) t);
}

void bindata_finalize( JSContext * cx , JSObject * obj ){
Convertor c(cx);
void *holder = JS_GetPrivate( cx, obj );
Expand All @@ -638,6 +689,10 @@ namespace mongo {

JSFunctionSpec bindata_functions[] = {
{ "toString" , bindata_tostring , 0 , JSPROP_READONLY | JSPROP_PERMANENT, 0 } ,
{ "hex", bindataAsHex, 0, JSPROP_READONLY | JSPROP_PERMANENT, 0 } ,
{ "base64", bindataBase64, 0, JSPROP_READONLY | JSPROP_PERMANENT, 0 } ,
{ "length", bindataLength, 0, JSPROP_READONLY | JSPROP_PERMANENT, 0 } ,
{ "subtype", bindataSubtype, 0, JSPROP_READONLY | JSPROP_PERMANENT, 0 } ,
{ 0 }
};

Expand Down

0 comments on commit 0adc465

Please sign in to comment.