accumulator.h   accumulator.h 
skipping to change at line 19 skipping to change at line 19
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details. * GNU Affero General Public License for more details.
* *
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#pragma once #pragma once
#include "pch.h" #include "mongo/pch.h"
#include <boost/unordered_set.hpp> #include <boost/unordered_set.hpp>
#include "db/pipeline/value.h" #include "db/pipeline/value.h"
#include "db/pipeline/expression.h" #include "db/pipeline/expression.h"
#include "bson/bsontypes.h" #include "bson/bsontypes.h"
namespace mongo { namespace mongo {
class ExpressionContext; class ExpressionContext;
class Accumulator : class Accumulator :
skipping to change at line 59 skipping to change at line 59
/* /*
Convenience method for doing this for accumulators. The pattern Convenience method for doing this for accumulators. The pattern
is always the same, so a common implementation works, but require s is always the same, so a common implementation works, but require s
knowing the operator name. knowing the operator name.
@param pBuilder the builder to add to @param pBuilder the builder to add to
@param fieldName the projected name @param fieldName the projected name
@param opName the operator name @param opName the operator name
*/ */
void opToBson( void opToBson(
BSONObjBuilder *pBuilder, string fieldName, string opName) cons BSONObjBuilder *pBuilder, string fieldName, string opName,
t; bool requireExpression) const;
}; };
class AccumulatorAddToSet : class AccumulatorAddToSet :
public Accumulator { public Accumulator {
public: public:
// virtuals from Expression // virtuals from Expression
virtual intrusive_ptr<const Value> evaluate( virtual intrusive_ptr<const Value> evaluate(
const intrusive_ptr<Document> &pDocument) const; const intrusive_ptr<Document> &pDocument) const;
virtual intrusive_ptr<const Value> getValue() const; virtual intrusive_ptr<const Value> getValue() const;
virtual const char *getOpName() const; virtual const char *getOpName() const;
skipping to change at line 170 skipping to change at line 171
*/ */
static intrusive_ptr<Accumulator> create( static intrusive_ptr<Accumulator> create(
const intrusive_ptr<ExpressionContext> &pCtx); const intrusive_ptr<ExpressionContext> &pCtx);
protected: /* reused by AccumulatorAvg */ protected: /* reused by AccumulatorAvg */
AccumulatorSum(); AccumulatorSum();
mutable BSONType totalType; mutable BSONType totalType;
mutable long long longTotal; mutable long long longTotal;
mutable double doubleTotal; mutable double doubleTotal;
// count is only used by AccumulatorAvg, but lives here to avoid co
unting non-numeric values
mutable long long count;
}; };
class AccumulatorMinMax : class AccumulatorMinMax :
public AccumulatorSingleValue { public AccumulatorSingleValue {
public: public:
// virtuals from Expression // virtuals from Expression
virtual intrusive_ptr<const Value> evaluate( virtual intrusive_ptr<const Value> evaluate(
const intrusive_ptr<Document> &pDocument) const; const intrusive_ptr<Document> &pDocument) const;
virtual const char *getOpName() const; virtual const char *getOpName() const;
skipping to change at line 246 skipping to change at line 249
*/ */
static intrusive_ptr<Accumulator> create( static intrusive_ptr<Accumulator> create(
const intrusive_ptr<ExpressionContext> &pCtx); const intrusive_ptr<ExpressionContext> &pCtx);
private: private:
static const char subTotalName[]; static const char subTotalName[];
static const char countName[]; static const char countName[];
AccumulatorAvg(const intrusive_ptr<ExpressionContext> &pCtx); AccumulatorAvg(const intrusive_ptr<ExpressionContext> &pCtx);
mutable long long count;
intrusive_ptr<ExpressionContext> pCtx; intrusive_ptr<ExpressionContext> pCtx;
}; };
} }
 End of changes. 4 change blocks. 
4 lines changed or deleted 6 lines changed or added


 authentication_table.h   authentication_table.h 
skipping to change at line 59 skipping to change at line 59
// Takes the authentication state from the given BSONObj, replcacin g whatever state it had. // Takes the authentication state from the given BSONObj, replcacin g whatever state it had.
void setFromBSON( const BSONObj& obj ); void setFromBSON( const BSONObj& obj );
BSONObj toBSON() const; BSONObj toBSON() const;
BSONObj copyCommandObjAddingAuth( const BSONObj& cmdObj ) const; BSONObj copyCommandObjAddingAuth( const BSONObj& cmdObj ) const;
static const AuthenticationTable& getInternalSecurityAuthentication Table(); static const AuthenticationTable& getInternalSecurityAuthentication Table();
// Only used once at startup to setup the authentication table. // Only used once at startup to setup the authentication table.
static AuthenticationTable& getMutableInternalSecurityAuthenticatio nTable(); static AuthenticationTable& getMutableInternalSecurityAuthenticatio nTable();
static const string fieldName;
private: private:
typedef map<std::string,Auth> DBAuthMap; typedef map<std::string,Auth> DBAuthMap;
DBAuthMap _dbs; // dbname -> auth DBAuthMap _dbs; // dbname -> auth
}; };
} }
 End of changes. 1 change blocks. 
0 lines changed or deleted 2 lines changed or added


 balance.h   balance.h 
skipping to change at line 21 skipping to change at line 21
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details. * GNU Affero General Public License for more details.
* *
* You should have received a copy of the GNU Affero General Public Licen se * You should have received a copy of the GNU Affero General Public Licen se
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#pragma once #pragma once
#include "../pch.h" #include "mongo/pch.h"
#include "../util/background.h" #include "../util/background.h"
#include "balancer_policy.h" #include "balancer_policy.h"
namespace mongo { namespace mongo {
/** /**
* The balancer is a background task that tries to keep the number of c hunks across all servers of the cluster even. Although * The balancer is a background task that tries to keep the number of c hunks across all servers of the cluster even. Although
* every mongos will have one balancer running, only one of them will b e active at the any given point in time. The balancer * every mongos will have one balancer running, only one of them will b e active at the any given point in time. The balancer
* uses a 'DistributedLock' for that coordination. * uses a 'DistributedLock' for that coordination.
* *
skipping to change at line 87 skipping to change at line 87
* @param candidateChunks (IN/OUT) filled with candidate chunks, on e per collection, that could possibly be moved * @param candidateChunks (IN/OUT) filled with candidate chunks, on e per collection, that could possibly be moved
*/ */
void _doBalanceRound( DBClientBase& conn, vector<CandidateChunkPtr> * candidateChunks ); void _doBalanceRound( DBClientBase& conn, vector<CandidateChunkPtr> * candidateChunks );
/** /**
* Issues chunk migration request, one at a time. * Issues chunk migration request, one at a time.
* *
* @param candidateChunks possible chunks to move * @param candidateChunks possible chunks to move
* @return number of chunks effectively moved * @return number of chunks effectively moved
*/ */
int _moveChunks( const vector<CandidateChunkPtr>* candidateChunks ) ; int _moveChunks( const vector<CandidateChunkPtr>* candidateChunks , bool secondaryThrottle );
/** /**
* Marks this balancer as being live on the config server(s). * Marks this balancer as being live on the config server(s).
* *
* @param conn is the connection with the config server(s) * @param conn is the connection with the config server(s)
*/ */
void _ping( DBClientBase& conn, bool waiting = false ); void _ping( DBClientBase& conn, bool waiting = false );
/** /**
* @return true if all the servers listed in configdb as being shar ds are reachable and are distinct processes * @return true if all the servers listed in configdb as being shar ds are reachable and are distinct processes
 End of changes. 2 change blocks. 
2 lines changed or deleted 2 lines changed or added


 bgsync.h   bgsync.h 
skipping to change at line 88 skipping to change at line 88
// Notifier thread // Notifier thread
// used to wait until another op has been replicated // used to wait until another op has been replicated
boost::condition_variable _lastOpCond; boost::condition_variable _lastOpCond;
boost::mutex _lastOpMutex; boost::mutex _lastOpMutex;
Member* _oplogMarkerTarget; Member* _oplogMarkerTarget;
OplogReader _oplogMarker; // not locked, only used by notifier thre ad OplogReader _oplogMarker; // not locked, only used by notifier thre ad
OpTime _consumedOpTime; // not locked, only used by notifier thread OpTime _consumedOpTime; // not locked, only used by notifier thread
struct { struct QueueCounter {
QueueCounter();
unsigned long long waitTime; unsigned long long waitTime;
unsigned int numElems; unsigned int numElems;
} _queueCounter; } _queueCounter;
BackgroundSync(); BackgroundSync();
BackgroundSync(const BackgroundSync& s); BackgroundSync(const BackgroundSync& s);
BackgroundSync operator=(const BackgroundSync& s); BackgroundSync operator=(const BackgroundSync& s);
// Production thread // Production thread
void _producerThread(); void _producerThread();
 End of changes. 1 change blocks. 
1 lines changed or deleted 2 lines changed or added


 bson_util.h   bson_util.h 
skipping to change at line 20 skipping to change at line 20
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or impli ed. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or impli ed.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#pragma once #pragma once
#include "../pch.h" #include "mongo/pch.h"
namespace mongo { namespace mongo {
template <typename T> template <typename T>
void bsonArrToNumVector(BSONElement el, vector<T>& results){ void bsonArrToNumVector(BSONElement el, vector<T>& results){
if(el.type() == Array){ if(el.type() == Array){
vector<BSONElement> elements = el.Array(); vector<BSONElement> elements = el.Array();
 End of changes. 1 change blocks. 
1 lines changed or deleted 1 lines changed or added


 bsonelement.h   bsonelement.h 
skipping to change at line 526 skipping to change at line 526
return 60; return 60;
case CodeWScope: case CodeWScope:
return 65; return 65;
default: default:
verify(0); verify(0);
return -1; return -1;
} }
} }
inline bool BSONElement::trueValue() const { inline bool BSONElement::trueValue() const {
// NOTE Behavior changes must be replicated in Value::coerceToBool( ).
switch( type() ) { switch( type() ) {
case NumberLong: case NumberLong:
return *reinterpret_cast< const long long* >( value() ) != 0; return *reinterpret_cast< const long long* >( value() ) != 0;
case NumberDouble: case NumberDouble:
return (reinterpret_cast < const PackedDouble* >(value ()))->d != 0; return (reinterpret_cast < const PackedDouble* >(value ()))->d != 0;
case NumberInt: case NumberInt:
return *reinterpret_cast< const int* >( value() ) != 0; return *reinterpret_cast< const int* >( value() ) != 0;
case mongo::Bool: case mongo::Bool:
return boolean(); return boolean();
case EOO: case EOO:
 End of changes. 1 change blocks. 
0 lines changed or deleted 1 lines changed or added


 bsonmisc.h   bsonmisc.h 
skipping to change at line 190 skipping to change at line 190
BSONSizeTracker() { BSONSizeTracker() {
_pos = 0; _pos = 0;
for ( int i=0; i<SIZE; i++ ) for ( int i=0; i<SIZE; i++ )
_sizes[i] = 512; // this is the default, so just be consist ent _sizes[i] = 512; // this is the default, so just be consist ent
} }
~BSONSizeTracker() { ~BSONSizeTracker() {
} }
void got( int size ) { void got( int size ) {
_sizes[_pos++] = size; _sizes[_pos] = size;
if ( _pos >= SIZE ) _pos = (_pos + 1) % SIZE; // thread safe at least on certain co
_pos = 0; mpilers
} }
/** /**
* right now choosing largest size * right now choosing largest size
*/ */
int getSize() const { int getSize() const {
int x = 16; // sane min int x = 16; // sane min
for ( int i=0; i<SIZE; i++ ) { for ( int i=0; i<SIZE; i++ ) {
if ( _sizes[i] > x ) if ( _sizes[i] > x )
x = _sizes[i]; x = _sizes[i];
 End of changes. 1 change blocks. 
3 lines changed or deleted 3 lines changed or added


 bsonobjbuilder.h   bsonobjbuilder.h 
skipping to change at line 722 skipping to change at line 722
template <typename T> template <typename T>
BSONArrayBuilder& operator<<(const T& x) { BSONArrayBuilder& operator<<(const T& x) {
return append(x); return append(x);
} }
void appendNull() { void appendNull() {
_b.appendNull(num()); _b.appendNull(num());
} }
void appendUndefined() {
_b.appendUndefined(num());
}
/** /**
* destructive - ownership moves to returned BSONArray * destructive - ownership moves to returned BSONArray
* @return owned BSONArray * @return owned BSONArray
*/ */
BSONArray arr() { return BSONArray(_b.obj()); } BSONArray arr() { return BSONArray(_b.obj()); }
BSONObj obj() { return _b.obj(); } BSONObj obj() { return _b.obj(); }
BSONObj done() { return _b.done(); } BSONObj done() { return _b.done(); }
void doneFast() { _b.doneFast(); } void doneFast() { _b.doneFast(); }
skipping to change at line 802 skipping to change at line 806
_b.appendArray( num(), subObj ); _b.appendArray( num(), subObj );
return *this; return *this;
} }
BSONArrayBuilder& appendAs( const BSONElement &e, const StringData& name) { BSONArrayBuilder& appendAs( const BSONElement &e, const StringData& name) {
fill( name ); fill( name );
append( e ); append( e );
return *this; return *this;
} }
BSONArrayBuilder& appendTimestamp(unsigned int sec, unsigned int in
c) {
_b.appendTimestamp(num(), sec, inc);
return *this;
}
bool isArray() const { bool isArray() const {
return true; return true;
} }
int len() const { return _b.len(); } int len() const { return _b.len(); }
int arrSize() const { return _i; } int arrSize() const { return _i; }
private: private:
// These two are undefined privates to prevent their accidental // These two are undefined privates to prevent their accidental
// use as we don't support unsigned ints in BSON // use as we don't support unsigned ints in BSON
 End of changes. 2 change blocks. 
0 lines changed or deleted 10 lines changed or added


 bsontypes.h   bsontypes.h 
skipping to change at line 89 skipping to change at line 89
/** Updated to a Date with value next OpTime on insert */ /** Updated to a Date with value next OpTime on insert */
Timestamp = 17, Timestamp = 17,
/** 64 bit integer */ /** 64 bit integer */
NumberLong = 18, NumberLong = 18,
/** max type that is not MaxKey */ /** max type that is not MaxKey */
JSTypeMax=18, JSTypeMax=18,
/** larger than all other types */ /** larger than all other types */
MaxKey=127 MaxKey=127
}; };
/**
* returns the name of the argument's type
* defined in jsobj.cpp
*/
const char* typeName (BSONType type);
/* subtypes of BinData. /* subtypes of BinData.
bdtCustom and above are ones that the JS compiler understands, but a re bdtCustom and above are ones that the JS compiler understands, but a re
opaque to the database. opaque to the database.
*/ */
enum BinDataType { enum BinDataType {
BinDataGeneral=0, BinDataGeneral=0,
Function=1, Function=1,
ByteArrayDeprecated=2, /* use BinGeneral instead */ ByteArrayDeprecated=2, /* use BinGeneral instead */
bdtUUID = 3, /* deprecated */ bdtUUID = 3, /* deprecated */
newUUID=4, /* language-independent UUID format across all drivers * / newUUID=4, /* language-independent UUID format across all drivers * /
 End of changes. 1 change blocks. 
0 lines changed or deleted 6 lines changed or added


 btree.h   btree.h 
skipping to change at line 21 skipping to change at line 21
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details. * GNU Affero General Public License for more details.
* *
* You should have received a copy of the GNU Affero General Public Licen se * You should have received a copy of the GNU Affero General Public Licen se
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#pragma once #pragma once
#include "pch.h" #include "mongo/pch.h"
#include "mongo/db/jsobj.h" #include "mongo/db/jsobj.h"
#include "mongo/db/diskloc.h" #include "mongo/db/diskloc.h"
#include "mongo/db/pdfile.h" #include "mongo/db/pdfile.h"
#include "mongo/db/key.h" #include "mongo/db/key.h"
namespace mongo { namespace mongo {
/** /**
* Our btree implementation generally follows the standard btree algori thm, * Our btree implementation generally follows the standard btree algori thm,
* which is described in many places. The nodes of our btree are refer red to * which is described in many places. The nodes of our btree are refer red to
 End of changes. 1 change blocks. 
1 lines changed or deleted 1 lines changed or added


 checksum.h   checksum.h 
#pragma once #pragma once
#include "../pch.h" #include "mongo/pch.h"
namespace mongo { namespace mongo {
/** a simple, rather dumb, but very fast checksum. see perftests.cpp f or unit tests. */ /** a simple, rather dumb, but very fast checksum. see perftests.cpp f or unit tests. */
struct Checksum { struct Checksum {
union { union {
unsigned char bytes[16]; unsigned char bytes[16];
unsigned long long words[2]; unsigned long long words[2];
}; };
// if you change this you must bump dur::CurrentVersion // if you change this you must bump dur::CurrentVersion
void gen(const void *buf, unsigned len) { void gen(const void *buf, unsigned len) {
 End of changes. 1 change blocks. 
1 lines changed or deleted 1 lines changed or added


 chunk.h   chunk.h 
skipping to change at line 21 skipping to change at line 21
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details. * GNU Affero General Public License for more details.
* *
* You should have received a copy of the GNU Affero General Public Licen se * You should have received a copy of the GNU Affero General Public Licen se
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#pragma once #pragma once
#include "../pch.h" #include "mongo/pch.h"
#include "../bson/util/atomic_int.h" #include "../bson/util/atomic_int.h"
#include "../client/distlock.h" #include "../client/distlock.h"
#include "shardkey.h" #include "shardkey.h"
#include "shard.h" #include "shard.h"
#include "util.h" #include "util.h"
#include "mongo/util/concurrency/ticketholder.h" #include "mongo/util/concurrency/ticketholder.h"
namespace mongo { namespace mongo {
skipping to change at line 148 skipping to change at line 148
// //
// migration support // migration support
// //
/** /**
* Issues a migrate request for this chunk * Issues a migrate request for this chunk
* *
* @param to shard to move this chunk to * @param to shard to move this chunk to
* @param chunSize maximum number of bytes beyond which the migrate should no go trhough * @param chunSize maximum number of bytes beyond which the migrate should no go trhough
* @param secondaryThrottle whether during migrate all writes shoul d block for repl
* @param res the object containing details about the migrate execu tion * @param res the object containing details about the migrate execu tion
* @return true if move was successful * @return true if move was successful
*/ */
bool moveAndCommit( const Shard& to , long long chunkSize , BSONObj & res ) const; bool moveAndCommit( const Shard& to , long long chunkSize , bool se condaryThrottle, BSONObj& res ) const;
/** /**
* @return size of shard in bytes * @return size of shard in bytes
* talks to mongod to do this * talks to mongod to do this
*/ */
long getPhysicalSize() const; long getPhysicalSize() const;
/** /**
* marks this chunk as a jumbo chunk * marks this chunk as a jumbo chunk
* that means the chunk will be inelligble for migrates * that means the chunk will be inelligble for migrates
skipping to change at line 179 skipping to change at line 180
*/ */
static void refreshChunkSize(); static void refreshChunkSize();
// //
// public constants // public constants
// //
static string chunkMetadataNS; static string chunkMetadataNS;
static int MaxChunkSize; static int MaxChunkSize;
static int MaxObjectPerChunk; static int MaxObjectPerChunk;
static bool ShouldAutoSplit;
// //
// accessors and helpers // accessors and helpers
// //
string toString() const; string toString() const;
friend ostream& operator << (ostream& out, const Chunk& c) { return (out << c.toString()); } friend ostream& operator << (ostream& out, const Chunk& c) { return (out << c.toString()); }
bool operator==(const Chunk& s) const; bool operator==(const Chunk& s) const;
bool operator!=(const Chunk& s) const { return ! ( *this == s ); } bool operator!=(const Chunk& s) const { return ! ( *this == s ); }
 End of changes. 4 change blocks. 
2 lines changed or deleted 5 lines changed or added


 client.h   client.h 
skipping to change at line 27 skipping to change at line 27
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details. * GNU Affero General Public License for more details.
* *
* You should have received a copy of the GNU Affero General Public Licen se * You should have received a copy of the GNU Affero General Public Licen se
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#pragma once #pragma once
#include "../pch.h" #include "mongo/pch.h"
#include "security.h" #include "security.h"
#include "namespace-inl.h" #include "namespace-inl.h"
#include "lasterror.h" #include "lasterror.h"
#include "stats/top.h" #include "stats/top.h"
#include "../db/client_common.h" #include "../db/client_common.h"
#include "../util/concurrency/threadlocal.h" #include "../util/concurrency/threadlocal.h"
#include "../util/net/message_port.h" #include "../util/net/message_port.h"
#include "../util/concurrency/rwlock.h" #include "../util/concurrency/rwlock.h"
#include "d_concurrency.h" #include "d_concurrency.h"
#include "mongo/db/lockstate.h" #include "mongo/db/lockstate.h"
skipping to change at line 66 skipping to change at line 66
/** the database's concept of an outside "client" */ /** the database's concept of an outside "client" */
class Client : public ClientBasic { class Client : public ClientBasic {
static Client *syncThread; static Client *syncThread;
public: public:
// always be in clientsMutex when manipulating this. killop stuff u ses these. // always be in clientsMutex when manipulating this. killop stuff u ses these.
static set<Client*>& clients; static set<Client*>& clients;
static mongo::mutex& clientsMutex; static mongo::mutex& clientsMutex;
static int getActiveClientCount( int& writers , int& readers ); static int getActiveClientCount( int& writers , int& readers );
class Context; class Context;
~Client(); ~Client();
static int recommendedYieldMicros( int * writers = 0 , int * reader static int recommendedYieldMicros( int * writers = 0 , int * reader
s = 0 ); s = 0,
bool needExact = false );
/** each thread which does db operations has a Client object in TLS . /** each thread which does db operations has a Client object in TLS .
* call this when your thread starts. * call this when your thread starts.
*/ */
static Client& initThread(const char *desc, AbstractMessagingPort * mp = 0); static Client& initThread(const char *desc, AbstractMessagingPort * mp = 0);
static void initThreadIfNotAlready(const char *desc) { static void initThreadIfNotAlready(const char *desc) {
if( currentClient.get() ) if( currentClient.get() )
return; return;
initThread(desc); initThread(desc);
} }
skipping to change at line 146 skipping to change at line 146
CurOp * _curOp; CurOp * _curOp;
Context * _context; Context * _context;
bool _shutdown; // to track if Client::shutdown() gets called bool _shutdown; // to track if Client::shutdown() gets called
std::string _desc; std::string _desc;
bool _god; bool _god;
AuthenticationInfo _ai; AuthenticationInfo _ai;
OpTime _lastOp; OpTime _lastOp;
BSONObj _handshake; BSONObj _handshake;
BSONObj _remoteId; BSONObj _remoteId;
AbstractMessagingPort * const _mp; AbstractMessagingPort * const _mp;
unsigned _sometimes;
bool _hasWrittenThisPass; bool _hasWrittenThisPass;
PageFaultRetryableSection *_pageFaultRetryableSection; PageFaultRetryableSection *_pageFaultRetryableSection;
LockState _ls; LockState _ls;
friend class PageFaultRetryableSection; // TEMP friend class PageFaultRetryableSection; // TEMP
friend class NoPageFaultsAllowed; // TEMP friend class NoPageFaultsAllowed; // TEMP
public: public:
/** the concept here is the same as MONGO_SOMETIMES. however that
macro uses a static that will be shared by all threads, and eac
h
time incremented it might eject that line from the other cpu ca
ches (?),
so idea is that this is better.
*/
bool sometimes(unsigned howOften) { return ++_sometimes % howOften
== 0; }
/* set _god=true temporarily, safely */ /* set _god=true temporarily, safely */
class GodScope { class GodScope {
bool _prev; bool _prev;
public: public:
GodScope(); GodScope();
~GodScope(); ~GodScope();
}; };
//static void assureDatabaseIsOpen(const string& ns, string path=db path); //static void assureDatabaseIsOpen(const string& ns, string path=db path);
 End of changes. 4 change blocks. 
15 lines changed or deleted 4 lines changed or added


 client_info.h   client_info.h 
skipping to change at line 24 skipping to change at line 24
* *
* You should have received a copy of the GNU Affero General Public Lice nse * You should have received a copy of the GNU Affero General Public Lice nse
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#pragma once #pragma once
#include "mongo/pch.h" #include "mongo/pch.h"
#include "mongo/db/client_common.h" #include "mongo/db/client_common.h"
#include "mongo/db/security.h" #include "mongo/db/security.h"
#include "mongo/s/chunk.h"
#include "mongo/s/writeback_listener.h" #include "mongo/s/writeback_listener.h"
#include "mongo/util/net/hostandport.h" #include "mongo/util/net/hostandport.h"
namespace mongo { namespace mongo {
/** /**
* holds information about a client connected to a mongos * holds information about a client connected to a mongos
* 1 per client socket * 1 per client socket
* currently implemented with a thread local * currently implemented with a thread local
*/ */
skipping to change at line 91 skipping to change at line 92
void disableForCommand(); void disableForCommand();
/** /**
* calls getLastError * calls getLastError
* resets shards since get last error * resets shards since get last error
* @return if the command was ok or if there was an error * @return if the command was ok or if there was an error
*/ */
bool getLastError( const string& dbName, bool getLastError( const string& dbName,
const BSONObj& options , const BSONObj& options ,
BSONObjBuilder& result , BSONObjBuilder& result ,
string& errmsg,
bool fromWriteBackListener = false ); bool fromWriteBackListener = false );
/** @return if its ok to auto split from this client */ /** @return if its ok to auto split from this client */
bool autoSplitOk() const { return _autoSplitOk; } bool autoSplitOk() const { return _autoSplitOk && Chunk::ShouldAuto Split; }
void noAutoSplit() { _autoSplitOk = false; } void noAutoSplit() { _autoSplitOk = false; }
static ClientInfo * get(); static ClientInfo * get();
const AuthenticationInfo* getAuthenticationInfo() const { return (A uthenticationInfo*)&_ai; } const AuthenticationInfo* getAuthenticationInfo() const { return (A uthenticationInfo*)&_ai; }
AuthenticationInfo* getAuthenticationInfo() { return (Authenticatio nInfo*)&_ai; } AuthenticationInfo* getAuthenticationInfo() { return (Authenticatio nInfo*)&_ai; }
bool isAdmin() { return _ai.isAuthorized( "admin" ); } bool isAdmin() { return _ai.isAuthorized( "admin" ); }
private: private:
AuthenticationInfo _ai; AuthenticationInfo _ai;
 End of changes. 3 change blocks. 
1 lines changed or deleted 3 lines changed or added


 clientcursor.h   clientcursor.h 
skipping to change at line 27 skipping to change at line 27
*/ */
/* Cursor -- and its derived classes -- are our internal cursors. /* Cursor -- and its derived classes -- are our internal cursors.
ClientCursor is a wrapper that represents a cursorid from our database ClientCursor is a wrapper that represents a cursorid from our database
application's perspective. application's perspective.
*/ */
#pragma once #pragma once
#include "pch.h" #include "mongo/pch.h"
#include <boost/thread/recursive_mutex.hpp> #include <boost/thread/recursive_mutex.hpp>
#include "cursor.h" #include "cursor.h"
#include "jsobj.h" #include "jsobj.h"
#include "../util/net/message.h" #include "../util/net/message.h"
#include "../util/net/listen.h" #include "../util/net/listen.h"
#include "../util/background.h" #include "../util/background.h"
#include "diskloc.h" #include "diskloc.h"
#include "dbhelpers.h" #include "dbhelpers.h"
 End of changes. 1 change blocks. 
1 lines changed or deleted 1 lines changed or added


 cmdline.h   cmdline.h 
skipping to change at line 19 skipping to change at line 19
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details. * GNU Affero General Public License for more details.
* *
* You should have received a copy of the GNU Affero General Public Licen se * You should have received a copy of the GNU Affero General Public Licen se
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#pragma once #pragma once
#include "../pch.h" #include "mongo/pch.h"
#include "jsobj.h" #include "jsobj.h"
namespace boost { namespace boost {
namespace program_options { namespace program_options {
class options_description; class options_description;
class positional_options_description; class positional_options_description;
class variables_map; class variables_map;
} }
} }
skipping to change at line 71 skipping to change at line 71
string _replSet; // --replSet[/<seedlist>] string _replSet; // --replSet[/<seedlist>]
string ourSetName() const { string ourSetName() const {
string setname; string setname;
size_t sl = _replSet.find('/'); size_t sl = _replSet.find('/');
if( sl == string::npos ) if( sl == string::npos )
return _replSet; return _replSet;
return _replSet.substr(0, sl); return _replSet.substr(0, sl);
} }
bool usingReplSets() const { return !_replSet.empty(); } bool usingReplSets() const { return !_replSet.empty(); }
string rsIndexPrefetch;// --indexPrefetch
// for master/slave replication // for master/slave replication
string source; // --source string source; // --source
string only; // --only string only; // --only
bool quiet; // --quiet bool quiet; // --quiet
bool noTableScan; // --notablescan no table scans allowed bool noTableScan; // --notablescan no table scans allowed
bool prealloc; // --noprealloc no preallocation of data fil es bool prealloc; // --noprealloc no preallocation of data fil es
bool preallocj; // --nopreallocj no preallocation of journal files bool preallocj; // --nopreallocj no preallocation of journal files
bool smallfiles; // --smallfiles allocate smaller data files bool smallfiles; // --smallfiles allocate smaller data files
skipping to change at line 136 skipping to change at line 138
bool sslOnNormalPorts; // --sslOnNormalPorts bool sslOnNormalPorts; // --sslOnNormalPorts
string sslPEMKeyFile; // --sslPEMKeyFile string sslPEMKeyFile; // --sslPEMKeyFile
string sslPEMKeyPassword; // --sslPEMKeyPassword string sslPEMKeyPassword; // --sslPEMKeyPassword
SSLManager* sslServerManager; // currently leaks on close SSLManager* sslServerManager; // currently leaks on close
#endif #endif
static void launchOk(); static void launchOk();
static void addGlobalOptions( boost::program_options::options_descr iption& general , static void addGlobalOptions( boost::program_options::options_descr iption& general ,
boost::program_options::options_descr boost::program_options::options_descr
iption& hidden ); iption& hidden ,
boost::program_options::options_descr
iption& ssl_options );
static void addWindowsOptions( boost::program_options::options_desc ription& windows , static void addWindowsOptions( boost::program_options::options_desc ription& windows ,
boost::program_options::options_desc ription& hidden ); boost::program_options::options_desc ription& hidden );
static void parseConfigFile( istream &f, stringstream &ss); static void parseConfigFile( istream &f, stringstream &ss);
/** /**
* @return true if should run program, false if should exit * @return true if should run program, false if should exit
*/ */
static bool store( int argc , char ** argv , static bool store( int argc , char ** argv ,
boost::program_options::options_description& vis ible, boost::program_options::options_description& vis ible,
skipping to change at line 160 skipping to change at line 163
time_t started; time_t started;
}; };
// todo move to cmdline.cpp? // todo move to cmdline.cpp?
inline CmdLine::CmdLine() : inline CmdLine::CmdLine() :
port(DefaultDBPort), rest(false), jsonp(false), quiet(false), port(DefaultDBPort), rest(false), jsonp(false), quiet(false),
noTableScan(false), prealloc(true), preallocj(true), smallfiles(siz eof(int*) == 4), noTableScan(false), prealloc(true), preallocj(true), smallfiles(siz eof(int*) == 4),
configsvr(false), quota(false), quotaFiles(8), cpu(false), configsvr(false), quota(false), quotaFiles(8), cpu(false),
durOptions(0), objcheck(false), oplogSize(0), defaultProfile(0), durOptions(0), objcheck(false), oplogSize(0), defaultProfile(0),
slowMS(100), defaultLocalThresholdMillis(10), pretouch(0), movePara noia( true ), slowMS(100), defaultLocalThresholdMillis(15), pretouch(0), movePara noia( true ),
syncdelay(60), noUnixSocket(false), doFork(0), socket("/tmp") syncdelay(60), noUnixSocket(false), doFork(0), socket("/tmp")
{ {
started = time(0); started = time(0);
journalCommitInterval = 0; // 0 means use default journalCommitInterval = 0; // 0 means use default
dur = false; dur = false;
#if defined(_DURABLEDEFAULTON) #if defined(_DURABLEDEFAULTON)
dur = true; dur = true;
#endif #endif
if( sizeof(void*) == 8 ) if( sizeof(void*) == 8 )
 End of changes. 4 change blocks. 
4 lines changed or deleted 8 lines changed or added


 core.h   core.h 
skipping to change at line 21 skipping to change at line 21
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details. * GNU Affero General Public License for more details.
* *
* You should have received a copy of the GNU Affero General Public Licen se * You should have received a copy of the GNU Affero General Public Licen se
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#pragma once #pragma once
#include "../../pch.h" #include "mongo/pch.h"
#include "../jsobj.h" #include "../jsobj.h"
#include <cmath> #include <cmath>
#ifndef M_PI #ifndef M_PI
# define M_PI 3.14159265358979323846 # define M_PI 3.14159265358979323846
#endif #endif
namespace mongo { namespace mongo {
 End of changes. 1 change blocks. 
1 lines changed or deleted 1 lines changed or added


 counters.h   counters.h 
skipping to change at line 20 skipping to change at line 20
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details. * GNU Affero General Public License for more details.
* *
* You should have received a copy of the GNU Affero General Public Lice nse * You should have received a copy of the GNU Affero General Public Lice nse
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#pragma once #pragma once
#include "../../pch.h" #include "mongo/pch.h"
#include "../jsobj.h" #include "../jsobj.h"
#include "../../util/net/message.h" #include "../../util/net/message.h"
#include "../../util/processinfo.h" #include "../../util/processinfo.h"
#include "../../util/concurrency/spin_lock.h" #include "../../util/concurrency/spin_lock.h"
#include "mongo/db/pdfile.h" #include "mongo/db/pdfile.h"
namespace mongo { namespace mongo {
/** /**
* for storing operation counters * for storing operation counters
skipping to change at line 49 skipping to change at line 49
void gotQuery() { _query++; } void gotQuery() { _query++; }
void gotUpdate() { _update++; } void gotUpdate() { _update++; }
void gotDelete() { _delete++; } void gotDelete() { _delete++; }
void gotGetMore() { _getmore++; } void gotGetMore() { _getmore++; }
void gotCommand() { _command++; } void gotCommand() { _command++; }
void gotOp( int op , bool isCommand ); void gotOp( int op , bool isCommand );
BSONObj getObj(); BSONObj getObj();
// thse are used by snmp, and other things, do not remove
const AtomicUInt * getInsert() const { return &_insert; }
const AtomicUInt * getQuery() const { return &_query; }
const AtomicUInt * getUpdate() const { return &_update; }
const AtomicUInt * getDelete() const { return &_delete; }
const AtomicUInt * getGetMore() const { return &_getmore; }
const AtomicUInt * getCommand() const { return &_command; }
private: private:
// todo: there will be a lot of cache line contention on these. ne ed to do something // todo: there will be a lot of cache line contention on these. ne ed to do something
// else eventually. // else eventually.
AtomicUInt _insert; AtomicUInt _insert;
AtomicUInt _query; AtomicUInt _query;
AtomicUInt _update; AtomicUInt _update;
AtomicUInt _delete; AtomicUInt _delete;
AtomicUInt _getmore; AtomicUInt _getmore;
AtomicUInt _command; AtomicUInt _command;
 End of changes. 2 change blocks. 
1 lines changed or deleted 9 lines changed or added


 cursor.h   cursor.h 
skipping to change at line 19 skipping to change at line 19
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details. * GNU Affero General Public License for more details.
* *
* You should have received a copy of the GNU Affero General Public Licen se * You should have received a copy of the GNU Affero General Public Licen se
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#pragma once #pragma once
#include "../pch.h" #include "mongo/pch.h"
#include "jsobj.h" #include "jsobj.h"
#include "diskloc.h" #include "diskloc.h"
#include "matcher.h" #include "matcher.h"
#include "mongo/db/projection.h" #include "mongo/db/projection.h"
namespace mongo { namespace mongo {
class NamespaceDetails; class NamespaceDetails;
class Record; class Record;
 End of changes. 1 change blocks. 
1 lines changed or deleted 1 lines changed or added


 cursors.h   cursors.h 
skipping to change at line 20 skipping to change at line 20
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details. * GNU Affero General Public License for more details.
* *
* You should have received a copy of the GNU Affero General Public Lice nse * You should have received a copy of the GNU Affero General Public Lice nse
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#pragma once #pragma once
#include "../pch.h" #include "mongo/pch.h"
#include "../db/jsobj.h" #include "../db/jsobj.h"
#include "../db/dbmessage.h" #include "../db/dbmessage.h"
#include "../client/parallel.h" #include "../client/parallel.h"
#include "request.h" #include "request.h"
namespace mongo { namespace mongo {
class ShardedClientCursor : boost::noncopyable { class ShardedClientCursor : boost::noncopyable {
 End of changes. 1 change blocks. 
1 lines changed or deleted 1 lines changed or added


 d_chunk_manager.h   d_chunk_manager.h 
skipping to change at line 21 skipping to change at line 21
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details. * GNU Affero General Public License for more details.
* *
* You should have received a copy of the GNU Affero General Public Licen se * You should have received a copy of the GNU Affero General Public Licen se
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#pragma once #pragma once
#include "../pch.h" #include "mongo/pch.h"
#include "../db/jsobj.h" #include "../db/jsobj.h"
#include "util.h" #include "util.h"
namespace mongo { namespace mongo {
class ClientCursor; class ClientCursor;
class DBClientCursorInterface; class DBClientCursorInterface;
class ShardChunkManager; class ShardChunkManager;
 End of changes. 1 change blocks. 
1 lines changed or deleted 1 lines changed or added


 d_concurrency.h   d_concurrency.h 
skipping to change at line 80 skipping to change at line 80
class ParallelBatchWriterMode : boost::noncopyable { class ParallelBatchWriterMode : boost::noncopyable {
RWLockRecursive::Exclusive _lk; RWLockRecursive::Exclusive _lk;
public: public:
ParallelBatchWriterMode() : _lk(_batchLock) {} ParallelBatchWriterMode() : _lk(_batchLock) {}
static void iAmABatchParticipant(); static void iAmABatchParticipant();
static RWLockRecursive &_batchLock; static RWLockRecursive &_batchLock;
}; };
private: private:
class ParallelBatchWriterSupport : boost::noncopyable { class ParallelBatchWriterSupport : boost::noncopyable {
scoped_ptr<RWLockRecursive::Shared> _lk;
public: public:
ParallelBatchWriterSupport(); ParallelBatchWriterSupport();
private:
void tempRelease();
void relock();
scoped_ptr<RWLockRecursive::Shared> _lk;
friend class ScopedLock;
}; };
public: public:
class ScopedLock : boost::noncopyable { class ScopedLock : boost::noncopyable {
public: public:
virtual ~ScopedLock(); virtual ~ScopedLock();
/** @return micros since we started acquiring */ /** @return micros since we started acquiring */
long long acquireFinished( LockStat* stat ); long long acquireFinished( LockStat* stat );
protected: // Accrue elapsed lock time since last we called reset
friend struct TempRelease; void recordTime();
// Start recording a new period, starting now()
void resetTime();
protected:
explicit ScopedLock( char type ); explicit ScopedLock( char type );
void tempRelease(); private:
friend struct TempRelease;
void tempRelease(); // TempRelease class calls these
void relock(); void relock();
void _recordTime( long long micros ); protected:
virtual void _tempRelease() = 0; virtual void _tempRelease() = 0;
virtual void _relock() = 0; virtual void _relock() = 0;
ParallelBatchWriterSupport _lk;
private: private:
Timer _timer; // this is counting the current state ParallelBatchWriterSupport _pbws_lk;
char _type;
void _recordTime( long long micros );
Timer _timer;
char _type; // 'r','w','R','W'
LockStat* _stat; // the stat for the relevant lock to increment when we're done LockStat* _stat; // the stat for the relevant lock to increment when we're done
}; };
// note that for these classes recursive locking is ok if the recur sive locking "makes sense" // note that for these classes recursive locking is ok if the recur sive locking "makes sense"
// i.e. you could grab globalread after globalwrite. // i.e. you could grab globalread after globalwrite.
class GlobalWrite : public ScopedLock { class GlobalWrite : public ScopedLock {
bool noop; bool noop;
protected: protected:
void _tempRelease(); void _tempRelease();
 End of changes. 8 change blocks. 
10 lines changed or deleted 21 lines changed or added


 d_logic.h   d_logic.h 
skipping to change at line 20 skipping to change at line 20
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details. * GNU Affero General Public License for more details.
* *
* You should have received a copy of the GNU Affero General Public Lice nse * You should have received a copy of the GNU Affero General Public Lice nse
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#pragma once #pragma once
#include "../pch.h" #include "mongo/pch.h"
#include "../db/jsobj.h" #include "../db/jsobj.h"
#include "d_chunk_manager.h" #include "d_chunk_manager.h"
#include "util.h" #include "util.h"
#include "mongo/util/concurrency/ticketholder.h" #include "mongo/util/concurrency/ticketholder.h"
namespace mongo { namespace mongo {
class Database; class Database;
 End of changes. 1 change blocks. 
1 lines changed or deleted 1 lines changed or added


 d_writeback.h   d_writeback.h 
skipping to change at line 21 skipping to change at line 21
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details. * GNU Affero General Public License for more details.
* *
* You should have received a copy of the GNU Affero General Public Licen se * You should have received a copy of the GNU Affero General Public Licen se
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#pragma once #pragma once
#include "../pch.h" #include "mongo/pch.h"
#include "../util/queue.h" #include "../util/queue.h"
#include "../util/background.h" #include "../util/background.h"
namespace mongo { namespace mongo {
/* /*
* The WriteBackManager keeps one queue of pending operations per mongo s. The operations get here * The WriteBackManager keeps one queue of pending operations per mongo s. The operations get here
* if they were directed to a chunk that is no longer in this mongod se rver. The operations are * if they were directed to a chunk that is no longer in this mongod se rver. The operations are
* "written back" to the mongos server per its request (command 'writeb acklisten'). * "written back" to the mongos server per its request (command 'writeb acklisten').
 End of changes. 1 change blocks. 
1 lines changed or deleted 1 lines changed or added


 db.h   db.h 
skipping to change at line 19 skipping to change at line 19
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details. * GNU Affero General Public License for more details.
* *
* You should have received a copy of the GNU Affero General Public Licen se * You should have received a copy of the GNU Affero General Public Licen se
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#pragma once #pragma once
#include "../pch.h" #include "mongo/pch.h"
#include "../util/net/message.h" #include "../util/net/message.h"
#include "pdfile.h" #include "pdfile.h"
#include "curop.h" #include "curop.h"
#include "client.h" #include "client.h"
#include "databaseholder.h" #include "databaseholder.h"
namespace mongo { namespace mongo {
// todo: relocked is being called when there was no unlock below. // todo: relocked is being called when there was no unlock below.
// that is weird. // that is weird.
 End of changes. 1 change blocks. 
1 lines changed or deleted 1 lines changed or added


 dbclient.h   dbclient.h 
skipping to change at line 30 skipping to change at line 30
*/ */
#pragma once #pragma once
#ifdef MONGO_EXPOSE_MACROS #ifdef MONGO_EXPOSE_MACROS
#error dbclient.h is for C++ driver consumer use only #error dbclient.h is for C++ driver consumer use only
#endif #endif
#include "mongo/client/redef_macros.h" #include "mongo/client/redef_macros.h"
#include "pch.h" #include "mongo/pch.h"
#include "mongo/client/connpool.h" #include "mongo/client/connpool.h"
#include "mongo/client/dbclient_rs.h" #include "mongo/client/dbclient_rs.h"
#include "mongo/client/dbclientcursor.h" #include "mongo/client/dbclientcursor.h"
#include "mongo/client/dbclientinterface.h" #include "mongo/client/dbclientinterface.h"
#include "mongo/client/gridfs.h" #include "mongo/client/gridfs.h"
#include "mongo/client/model.h" #include "mongo/client/model.h"
#include "mongo/client/syncclusterconnection.h" #include "mongo/client/syncclusterconnection.h"
#include "mongo/client/undef_macros.h" #include "mongo/client/undef_macros.h"
 End of changes. 1 change blocks. 
1 lines changed or deleted 1 lines changed or added


 dbclient_rs.h   dbclient_rs.h 
skipping to change at line 20 skipping to change at line 20
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or impli ed. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or impli ed.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#pragma once #pragma once
#include "pch.h" #include "mongo/pch.h"
#include <boost/function.hpp> #include <boost/function.hpp>
#include <boost/shared_ptr.hpp> #include <boost/shared_ptr.hpp>
#include <set> #include <set>
#include <utility> #include <utility>
#include "mongo/client/dbclientinterface.h" #include "mongo/client/dbclientinterface.h"
#include "mongo/util/net/hostandport.h" #include "mongo/util/net/hostandport.h"
namespace mongo { namespace mongo {
class ReplicaSetMonitor; class ReplicaSetMonitor;
class TagSet;
typedef shared_ptr<ReplicaSetMonitor> ReplicaSetMonitorPtr; typedef shared_ptr<ReplicaSetMonitor> ReplicaSetMonitorPtr;
typedef pair<set<string>,set<int> > NodeDiff; typedef pair<set<string>,set<int> > NodeDiff;
/** /**
* manages state about a replica set for client * manages state about a replica set for client
* keeps tabs on whose master and what slaves are up * keeps tabs on whose master and what slaves are up
* can hand a slave to someone for SLAVE_OK * can hand a slave to someone for SLAVE_OK
* one instace per process per replica set * one instace per process per replica set
* TODO: we might be able to use a regular Node * to avoid _lock * TODO: we might be able to use a regular Node * to avoid _lock
*/ */
skipping to change at line 90 skipping to change at line 91
* match: { "region": "na", "dc": "nyc" } * match: { "region": "na", "dc": "nyc" }
* not match: { "dc: "nyc", "rack": 2 } * not match: { "dc: "nyc", "rack": 2 }
* not match: { "dc": "sf" } * not match: { "dc": "sf" }
* *
* @param tag the tag to use to compare. Should not contain any * @param tag the tag to use to compare. Should not contain any
* embedded documents. * embedded documents.
* *
* @return true if the given tag matches the this node's tag * @return true if the given tag matches the this node's tag
* specification * specification
*/ */
bool matchesTag( const BSONObj& tag ) const; bool matchesTag(const BSONObj& tag) const;
/** /**
* @param threshold max ping time (in ms) to be considered lo cal * @param threshold max ping time (in ms) to be considered lo cal
* @return true if node is a local secondary, and can handle qu eries * @return true if node is a local secondary, and can handle qu eries
**/ **/
bool isLocalSecondary( const int threshold ) const { bool isLocalSecondary( const int threshold ) const {
return pingTimeMillis < threshold; return pingTimeMillis < threshold;
} }
/**
* Checks whether this nodes is compatible with the given readP
reference and
* tag. Compatibility check is strict in the sense that seconda
ry preferred
* is treated like secondary only and primary preferred is trea
ted like
* primary only.
*
* @return true if this node is compatible with the read prefer
ence and tags.
*/
bool isCompatible(ReadPreference readPreference, const TagSet*
tag) const;
BSONObj toBSON() const; BSONObj toBSON() const;
string toString() const { string toString() const {
return toBSON().toString(); return toBSON().toString();
} }
HostAndPort addr; HostAndPort addr;
boost::shared_ptr<DBClientConnection> conn; boost::shared_ptr<DBClientConnection> conn;
// if this node is in a failure state // if this node is in a failure state
skipping to change at line 129 skipping to change at line 140
bool hidden; bool hidden;
int pingTimeMillis; int pingTimeMillis;
}; };
/** /**
* Selects the right node given the nodes to pick from and the pref erence. * Selects the right node given the nodes to pick from and the pref erence.
* *
* @param nodes the nodes to select from * @param nodes the nodes to select from
* @param readPreference the read mode to use * @param preference the read mode to use
* @param readPreferenceTag the tags used for filtering nodes * @param tags the tags used for filtering nodes
* @param localThresholdMillis the exclusive upper bound of ping ti me to be * @param localThresholdMillis the exclusive upper bound of ping ti me to be
* considered as a local node. Local nodes are favored over non -local * considered as a local node. Local nodes are favored over non -local
* nodes if multiple nodes matches the other criteria. * nodes if multiple nodes matches the other criteria.
* @param primaryNodeIndex the index of the primary node * @param lastHost the host used in the last successful request. Th
* @param nextNodeIndex the index of the next node to begin from ch is is used for
ecking. * selecting a different node as much as possible, by doing a s
* Can advance to a different index (mainly used for doing roun imple round
d-robin). * robin, starting from the node next to this lastHost. This wi
ll be overwritten
* with the newly chosen host if not empty, not primary and whe
n preference
* is not Nearest.
*
* @return the host object of the node selected. If none of the nod
es are
* eligible, returns an empty host.
*/
static HostAndPort selectNode(const std::vector<Node>& nodes,
ReadPreference preference,
TagSet* tags,
int localThresholdMillis,
HostAndPort* lastHost);
/**
* Selects the right node given the nodes to pick from and the pref
erence. This
* will also attempt to refresh the local view of the replica set c
onfiguration
* if the primary node needs to be returned but is not currently av
ailable (except
* for ReadPrefrence_Nearest).
*
* @param preference the read mode to use
* @param tags the tags used for filtering nodes
* *
* @return the host object of the node selected. If none of the nod es are * @return the host object of the node selected. If none of the nod es are
* eligible, returns an empty host. * eligible, returns an empty host.
*/ */
static HostAndPort selectNode( const std::vector<Node>& nodes, HostAndPort selectAndCheckNode(ReadPreference preference,
ReadPreference readPreference, TagSet* tags);
const BSONObj& readPreferenceTag,
int localThresholdMillis,
int primaryNodeIndex,
int& nextNodeIndex );
/** /**
* Creates a new ReplicaSetMonitor, if it doesn't already exist. * Creates a new ReplicaSetMonitor, if it doesn't already exist.
*/ */
static void createIfNeeded( const string& name , const vector<HostA ndPort>& servers ); static void createIfNeeded( const string& name , const vector<HostA ndPort>& servers );
/** /**
* gets a cached Monitor per name. If the monitor is not found and createFromSeed is false, * gets a cached Monitor per name. If the monitor is not found and createFromSeed is false,
* it will return none. If createFromSeed is true, it will try to l ook up the last known * it will return none. If createFromSeed is true, it will try to l ook up the last known
* servers list for this set and will create a new monitor using th at as the seed list. * servers list for this set and will create a new monitor using th at as the seed list.
skipping to change at line 194 skipping to change at line 221
~ReplicaSetMonitor(); ~ReplicaSetMonitor();
/** @return HostAndPort or throws an exception */ /** @return HostAndPort or throws an exception */
HostAndPort getMaster(); HostAndPort getMaster();
/** /**
* notify the monitor that server has faild * notify the monitor that server has faild
*/ */
void notifyFailure( const HostAndPort& server ); void notifyFailure( const HostAndPort& server );
/** @return prev if its still ok, and if not returns a random slave /**
that is ok for reads */ * @deprecated use #getCandidateNode instead
* @return prev if its still ok, and if not returns a random slave
that is ok for reads
*/
HostAndPort getSlave( const HostAndPort& prev ); HostAndPort getSlave( const HostAndPort& prev );
/** /**
* @param preferLocal Prefer a local secondary, otherwise pick an y * @param preferLocal Prefer a local secondary, otherwise pick an y
* secondary, or fall back to primary * secondary, or fall back to primary
* @return a random slave that is ok for reads * @return a random slave that is ok for reads
*/ */
HostAndPort getSlave( bool preferLocal = true ); HostAndPort getSlave( bool preferLocal = true );
/** /**
skipping to change at line 228 skipping to change at line 258
bool contains( const string& server ) const; bool contains( const string& server ) const;
void appendInfo( BSONObjBuilder& b ) const; void appendInfo( BSONObjBuilder& b ) const;
/** /**
* Set the threshold value (in ms) for a node to be considered loca l. * Set the threshold value (in ms) for a node to be considered loca l.
* NOTE: This function acquires the _lock mutex. * NOTE: This function acquires the _lock mutex.
**/ **/
void setLocalThresholdMillis( const int millis ); void setLocalThresholdMillis( const int millis );
/**
* @return true if the host is compatible with the given readPrefer
ence and tag set.
*/
bool isHostCompatible(const HostAndPort& host, ReadPreference readP
reference,
const TagSet* tagSet) const;
private: private:
/** /**
* This populates a list of hosts from the list of seeds (discardin g the * This populates a list of hosts from the list of seeds (discardin g the
* seed list). Should only be called from within _setsLock. * seed list). Should only be called from within _setsLock.
* @param name set name * @param name set name
* @param servers seeds * @param servers seeds
*/ */
ReplicaSetMonitor( const string& name , const vector<HostAndPort>& servers ); ReplicaSetMonitor( const string& name , const vector<HostAndPort>& servers );
static void _remove_inlock( const string& name, bool clearSeedCache = false ); static void _remove_inlock( const string& name, bool clearSeedCache = false );
skipping to change at line 305 skipping to change at line 341
/** /**
* Checks whether the given connection matches the connection store d in _nodes. * Checks whether the given connection matches the connection store d in _nodes.
* Mainly used for sanity checking to confirm that nodeOffset still * Mainly used for sanity checking to confirm that nodeOffset still
* refers to the right connection after releasing and reacquiring * refers to the right connection after releasing and reacquiring
* a mutex. * a mutex.
*/ */
bool _checkConnMatch_inlock( DBClientConnection* conn, size_t nodeO ffset ) const; bool _checkConnMatch_inlock( DBClientConnection* conn, size_t nodeO ffset ) const;
/** /**
* Selects the right node given the nodes to pick from and the pref * Populates the local view of the set using the list of servers.
erence.
*
* @param nodes the nodes to select from
* @param readPreferenceTag the tags to use for choosing the right
node
* @param secOnly never select a primary if true
* @param localThresholdMillis the exclusive upper bound of ping ti
me to be
* considered as a local node. Local nodes are favored over non
-local
* nodes if multiple nodes matches the other criteria.
* @param nextNodeIndex the index of the next node to begin from ch
ecking.
* Can advance to a different index (mainly used for doing roun
d-robin).
* *
* @return the host object of the node selected. If none of the nod * Invariants:
es are * 1. Should be called while holding _setsLock and while not holdin
* eligible, returns an empty host. g _lock since
*/ * this calls #_checkConnection, which locks _checkConnectionLoc
static HostAndPort selectNode( const std::vector<Node>& nodes, k
const BSONObj& readPreferenceTag, * 2. _nodes should be empty before this is called
bool secOnly,
int localThresholdMillis,
int& nextNodeIndex );
/**
* @return the primary if it is ok to use, otherwise returns an emp
ty
* HostAndPort object.
*/ */
static HostAndPort checkPrimary( const std::vector<Node>& nodes, void _populateHosts_inSetsLock(const std::vector<HostAndPort>& seed
int primaryNodeIndex ); List);
// protects _localThresholdMillis, _nodes and refs to _nodes (eg. _ // protects _localThresholdMillis, _nodes and refs to _nodes
master & _nextSlave) // (eg. _master & _lastReadPrefHost)
mutable mongo::mutex _lock; mutable mongo::mutex _lock;
/** /**
* "Synchronizes" the _checkConnection method. Should ideally be on e mutex per * "Synchronizes" the _checkConnection method. Should ideally be on e mutex per
* connection object being used. The purpose of this lock is to mak e sure that * connection object being used. The purpose of this lock is to mak e sure that
* the reply from the connection the lock holder got is the actual response * the reply from the connection the lock holder got is the actual response
* to what it sent. * to what it sent.
* *
* Deadlock WARNING: never acquire this while holding _lock * Deadlock WARNING: never acquire this while holding _lock
*/ */
mutable mongo::mutex _checkConnectionLock; mutable mongo::mutex _checkConnectionLock;
string _name; string _name;
/** /**
* Host list. * Host list.
*/ */
std::vector<Node> _nodes; std::vector<Node> _nodes;
int _master; // which node is the current master. -1 means no mast er is known int _master; // which node is the current master. -1 means no mast er is known
int _nextSlave; // which node is the current slave int _nextSlave; // which node is the current slave, only used by th
e deprecated getSlave
// last host returned by _selectNode, used for round robin selectio
n
HostAndPort _lastReadPrefHost;
// The number of consecutive times the set has been checked and eve ry member in the set was down. // The number of consecutive times the set has been checked and eve ry member in the set was down.
int _failedChecks; int _failedChecks;
static mongo::mutex _setsLock; // protects _sets and _setServers static mongo::mutex _setsLock; // protects _sets and _setServers
static map<string,ReplicaSetMonitorPtr> _sets; // set name to Monit or static map<string,ReplicaSetMonitorPtr> _sets; // set name to Monit or
static map<string,vector<HostAndPort> > _setServers; // set name to seed list. Used to rebuild the monitor if it is cleaned up but then the se t is accessed again. static map<string,vector<HostAndPort> > _seedServers; // set name t o seed list. Used to rebuild the monitor if it is cleaned up but then the s et is accessed again.
static ConfigChangeHook _hook; static ConfigChangeHook _hook;
int _localThresholdMillis; // local ping latency threshold (protect ed by _lock) int _localThresholdMillis; // local ping latency threshold (protect ed by _lock)
static int _maxFailedChecks; static int _maxFailedChecks;
}; };
/** Use this class to connect to a replica set of servers. The class w ill manage /** Use this class to connect to a replica set of servers. The class w ill manage
checking for which server in a replica set is master, and do failove r automatically. checking for which server in a replica set is master, and do failove r automatically.
skipping to change at line 396 skipping to change at line 418
* master, although, * master, although,
* when false returned, you can still try to use this connection ob ject, it will * when false returned, you can still try to use this connection ob ject, it will
* try reconnects. * try reconnects.
*/ */
bool connect(); bool connect();
/** Authorize. Authorizes all nodes as needed /** Authorize. Authorizes all nodes as needed
*/ */
virtual bool auth(const string &dbname, const string &username, con st string &pwd, string& errmsg, bool digestPassword = true, Auth::Level * l evel = NULL); virtual bool auth(const string &dbname, const string &username, con st string &pwd, string& errmsg, bool digestPassword = true, Auth::Level * l evel = NULL);
/**
* Logs out the connection for the given database.
*
* @param dbname the database to logout from.
* @param info the result object for the logout command (provided f
or backwards
* compatibility with mongo shell)
*/
virtual void logout(const string& dbname, BSONObj& info);
// ----------- simple functions -------------- // ----------- simple functions --------------
/** throws userassertion "no master found" */ /** throws userassertion "no master found" */
virtual auto_ptr<DBClientCursor> query(const string &ns, Query quer y, int nToReturn = 0, int nToSkip = 0, virtual auto_ptr<DBClientCursor> query(const string &ns, Query quer y, int nToReturn = 0, int nToSkip = 0,
const BSONObj *fieldsToRetur n = 0, int queryOptions = 0 , int batchSize = 0 ); const BSONObj *fieldsToRetur n = 0, int queryOptions = 0 , int batchSize = 0 );
/** throws userassertion "no master found" */ /** throws userassertion "no master found" */
virtual BSONObj findOne(const string &ns, const Query& query, const BSONObj *fieldsToReturn = 0, int queryOptions = 0); virtual BSONObj findOne(const string &ns, const Query& query, const BSONObj *fieldsToReturn = 0, int queryOptions = 0);
virtual void insert( const string &ns , BSONObj obj , int flags=0); virtual void insert( const string &ns , BSONObj obj , int flags=0);
skipping to change at line 460 skipping to change at line 491
// ---- low level ------ // ---- low level ------
virtual bool call( Message &toSend, Message &response, bool assertO k=true , string * actualServer = 0 ); virtual bool call( Message &toSend, Message &response, bool assertO k=true , string * actualServer = 0 );
virtual bool callRead( Message& toSend , Message& response ) { retu rn checkMaster()->callRead( toSend , response ); } virtual bool callRead( Message& toSend , Message& response ) { retu rn checkMaster()->callRead( toSend , response ); }
protected: protected:
virtual void sayPiggyBack( Message &toSend ) { checkMaster()->say( toSend ); } virtual void sayPiggyBack( Message &toSend ) { checkMaster()->say( toSend ); }
private: private:
/**
// Used to simplify slave-handling logic on errors * Used to simplify slave-handling logic on errors
*
* @return back the passed cursor
* @throws DBException if the directed node cannot accept the query
because it
* is not a master
*/
auto_ptr<DBClientCursor> checkSlaveQueryResult( auto_ptr<DBClientCu rsor> result ); auto_ptr<DBClientCursor> checkSlaveQueryResult( auto_ptr<DBClientCu rsor> result );
DBClientConnection * checkMaster(); DBClientConnection * checkMaster();
DBClientConnection * checkSlave();
/**
* Helper method for selecting a node based on the read preference.
Will advance
* the tag tags object if it cannot find a node that matches the cu
rrent tag.
*
* @param preference the preference to use for selecting a node
* @param tags pointer to the list of tags.
*
* @return a pointer to the new connection object if it can find a
good connection.
* Otherwise it returns NULL.
*
* @throws DBException when an error occurred either when trying to
connect to
* a node that was thought to be ok or when an assertion happen
ed.
*/
DBClientConnection* selectNodeUsingTags(ReadPreference preference,
TagSet* tags);
/**
* @return true if the last host used in the last slaveOk query is
still in the
* set and can be used for the given read preference.
*/
bool checkLastHost( ReadPreference preference, const TagSet* tags )
;
/**
* Destroys all cached information about the last slaveOk operation
.
*/
void invalidateLastSlaveOkCache();
void _auth( DBClientConnection * conn ); void _auth( DBClientConnection * conn );
/**
* Maximum number of retries to make for auto-retry logic when perf
orming a slave ok
* operation.
*/
static const size_t MAX_RETRY;
// Throws a DBException if the monitor doesn't exist and there isn' t a cached seed to use. // Throws a DBException if the monitor doesn't exist and there isn' t a cached seed to use.
ReplicaSetMonitorPtr _getMonitor() const; ReplicaSetMonitorPtr _getMonitor() const;
string _setName; string _setName;
HostAndPort _masterHost; HostAndPort _masterHost;
scoped_ptr<DBClientConnection> _master; scoped_ptr<DBClientConnection> _master;
HostAndPort _slaveHost; // Last used host in a slaveOk query (can be a primary)
scoped_ptr<DBClientConnection> _slave; HostAndPort _lastSlaveOkHost;
// Last used connection in a slaveOk query (can be a primary)
scoped_ptr<DBClientConnection> _lastSlaveOkConn;
double _so_timeout; double _so_timeout;
/** /**
* for storing authentication info * for storing authentication info
* fields are exactly for DBClientConnection::auth * fields are exactly for DBClientConnection::auth
*/ */
struct AuthInfo { struct AuthInfo {
// Default constructor provided only to make it compatible with
std::map::operator[]
AuthInfo(): digestPassword(false) { }
AuthInfo( string d , string u , string p , bool di ) AuthInfo( string d , string u , string p , bool di )
: dbname( d ) , username( u ) , pwd( p ) , digestPassword( di ) {} : dbname( d ) , username( u ) , pwd( p ) , digestPassword( di ) {}
string dbname; string dbname;
string username; string username;
string pwd; string pwd;
bool digestPassword; bool digestPassword;
}; };
// we need to store so that when we connect to a new node on failur e // we need to store so that when we connect to a new node on failur e
// we can re-auth // we can re-auth
// this could be a security issue, as the password is stored in mem ory // this could be a security issue, as the password is stored in mem ory
// not sure if/how we should handle // not sure if/how we should handle
list<AuthInfo> _auths; std::map<string, AuthInfo> _auths; // dbName -> AuthInfo
protected: protected:
/** /**
* for storing (non-threadsafe) information between lazy calls * for storing (non-threadsafe) information between lazy calls
*/ */
class LazyState { class LazyState {
public: public:
LazyState() : _lastClient( NULL ), _lastOp( -1 ), _slaveOk( fal se ), _retries( 0 ) {} LazyState() : _lastClient( NULL ), _lastOp( -1 ), _slaveOk( fal se ), _retries( 0 ) {}
DBClientConnection* _lastClient; DBClientConnection* _lastClient;
int _lastOp; int _lastOp;
bool _slaveOk; bool _slaveOk;
int _retries; int _retries;
} _lazyState; } _lazyState;
}; };
/**
* A simple object for representing the list of tags. The initial state
will
* have a valid current tag as long as the list is not empty.
*/
class TagSet : public boost::noncopyable { // because of BSONArrayItera
torSorted
public:
/**
* Creates an empty tag list that is initially exhausted.
*/
TagSet();
/**
* Creates a tag set object that lazily iterates over the tag list.
*
* @param tags the list of tags associated with this option. This o
bject
* will get a shared copy of the list. Therefore, it is importa
nt
* for the the given tag to live longer than the created tag se
t.
*/
explicit TagSet(const BSONArray& tags);
/**
* Advance to the next tag.
*
* @throws AssertionException if iterator is exhausted before this
is called.
*/
void next();
//
// Getters
//
/**
* @return the current tag. Returned tag is invalid if isExhausted
is true.
*/
const BSONObj& getCurrentTag() const;
/**
* @return true if the iterator has been exhausted.
*/
bool isExhausted() const;
/**
* @return an unordered iterator to the tag list. The caller is res
ponsible for
* destroying the returned iterator.
*/
BSONObjIterator* getIterator() const;
private:
BSONObj _currentTag;
bool _isExhausted;
// Important: do not re-order _tags & _tagIterator
BSONArray _tags;
BSONArrayIteratorSorted _tagIterator;
};
} }
 End of changes. 24 change blocks. 
60 lines changed or deleted 216 lines changed or added


 dbclientcursor.h   dbclientcursor.h 
skipping to change at line 20 skipping to change at line 20
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or impli ed. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or impli ed.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#pragma once #pragma once
#include "pch.h" #include "mongo/pch.h"
#include <stack> #include <stack>
#include "mongo/client/dbclientinterface.h" #include "mongo/client/dbclientinterface.h"
#include "mongo/db/jsobj.h" #include "mongo/db/jsobj.h"
#include "mongo/db/json.h" #include "mongo/db/json.h"
#include "mongo/util/net/message.h" #include "mongo/util/net/message.h"
namespace mongo { namespace mongo {
skipping to change at line 171 skipping to change at line 171
/** by default we "own" the cursor and will send the server a KillC ursor /** by default we "own" the cursor and will send the server a KillC ursor
message when ~DBClientCursor() is called. This function overrid es that. message when ~DBClientCursor() is called. This function overrid es that.
*/ */
void decouple() { _ownCursor = false; } void decouple() { _ownCursor = false; }
void attach( AScopedConnection * conn ); void attach( AScopedConnection * conn );
string originalHost() const { return _originalHost; } string originalHost() const { return _originalHost; }
string getns() const { return ns; }
Message* getMessage(){ return batch.m.get(); } Message* getMessage(){ return batch.m.get(); }
/** /**
* Used mainly to run commands on connections that doesn't support lazy initialization and * Used mainly to run commands on connections that doesn't support lazy initialization and
* does not support commands through the call interface. * does not support commands through the call interface.
* *
* @param cmd The BSON representation of the command to send. * @param cmd The BSON representation of the command to send.
* *
* @return true if command was sent successfully * @return true if command was sent successfully
*/ */
 End of changes. 2 change blocks. 
1 lines changed or deleted 3 lines changed or added


 dbclientinterface.h   dbclientinterface.h 
skipping to change at line 23 skipping to change at line 23
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or impli ed. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or impli ed.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#pragma once #pragma once
#include "pch.h" #include "mongo/pch.h"
#include "mongo/client/authlevel.h" #include "mongo/client/authlevel.h"
#include "mongo/client/authentication_table.h" #include "mongo/client/authentication_table.h"
#include "mongo/db/jsobj.h" #include "mongo/db/jsobj.h"
#include "mongo/util/net/message.h" #include "mongo/util/net/message.h"
#include "mongo/util/net/message_port.h" #include "mongo/util/net/message_port.h"
namespace mongo { namespace mongo {
/** the query field 'options' can have these bits set: */ /** the query field 'options' can have these bits set: */
skipping to change at line 587 skipping to change at line 587
Authentication is separate for each database on the server -- y ou may authenticate for any Authentication is separate for each database on the server -- y ou may authenticate for any
number of databases on a single connection. number of databases on a single connection.
The "admin" database is special and once authenticated provides access to all databases on the The "admin" database is special and once authenticated provides access to all databases on the
server. server.
@param digestPassword if password is plain text, set this to true. otherwise assumed to be pre-digested @param digestPassword if password is plain text, set this to true. otherwise assumed to be pre-digested
@param[out] authLevel level of authentication for the giv en user @param[out] authLevel level of authentication for the giv en user
@return true if successful @return true if successful
*/ */
virtual bool auth(const string &dbname, const string &username, con st string &pwd, string& errmsg, bool digestPassword = true, Auth::Level * l evel = NULL); virtual bool auth(const string &dbname, const string &username, con st string &pwd, string& errmsg, bool digestPassword = true, Auth::Level * l evel = NULL);
/**
* Logs out the connection for the given database.
*
* @param dbname the database to logout from.
* @param info the result object for the logout command (provided f
or backwards
* compatibility with mongo shell)
*/
virtual void logout(const string& dbname, BSONObj& info);
/** count number of objects in collection ns that match the query c riteria specified /** count number of objects in collection ns that match the query c riteria specified
throws UserAssertion if database returns an error throws UserAssertion if database returns an error
*/ */
virtual unsigned long long count(const string &ns, const BSONObj& q uery = BSONObj(), int options=0, int limit=0, int skip=0 ); virtual unsigned long long count(const string &ns, const BSONObj& q uery = BSONObj(), int options=0, int limit=0, int skip=0 );
string createPasswordDigest( const string &username , const string &clearTextPassword ); string createPasswordDigest( const string &username , const string &clearTextPassword );
/** returns true in isMaster parm if this db is the current master /** returns true in isMaster parm if this db is the current master
of a replica pair. of a replica pair.
skipping to change at line 728 skipping to change at line 737
MROutput(const char* collection) : out(BSON("replace" << collec tion)) {} MROutput(const char* collection) : out(BSON("replace" << collec tion)) {}
MROutput(const string& collection) : out(BSON("replace" << coll ection)) {} MROutput(const string& collection) : out(BSON("replace" << coll ection)) {}
MROutput(const BSONObj& obj) : out(obj) {} MROutput(const BSONObj& obj) : out(obj) {}
BSONObj out; BSONObj out;
}; };
static MROutput MRInline; static MROutput MRInline;
/** Run a map/reduce job on the server. /** Run a map/reduce job on the server.
See http://www.mongodb.org/display/DOCS/MapReduce See http://dochub.mongodb.org/core/mapreduce
ns namespace (db+collection name) of input data ns namespace (db+collection name) of input data
jsmapf javascript map function code jsmapf javascript map function code
jsreducef javascript reduce function code. jsreducef javascript reduce function code.
query optional query filter for the input query optional query filter for the input
output either a string collection name or an object represen ting output type output either a string collection name or an object represen ting output type
if not specified uses inline output type if not specified uses inline output type
returns a result object which contains: returns a result object which contains:
{ result : <collection_name>, { result : <collection_name>,
 End of changes. 3 change blocks. 
2 lines changed or deleted 12 lines changed or added


 dbhelpers.h   dbhelpers.h 
skipping to change at line 25 skipping to change at line 25
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details. * GNU Affero General Public License for more details.
* *
* You should have received a copy of the GNU Affero General Public Licen se * You should have received a copy of the GNU Affero General Public Licen se
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#pragma once #pragma once
#include "../pch.h" #include "mongo/pch.h"
#include "client.h" #include "client.h"
#include "db.h" #include "db.h"
namespace mongo { namespace mongo {
extern const BSONObj reverseNaturalObj; // {"$natural": -1 } extern const BSONObj reverseNaturalObj; // {"$natural": -1 }
class Cursor; class Cursor;
class CoveredIndexMatcher; class CoveredIndexMatcher;
skipping to change at line 167 skipping to change at line 167
* *
* Caller must hold a write lock on 'ns' * Caller must hold a write lock on 'ns'
* *
* Does oplog the individual document deletions. * Does oplog the individual document deletions.
*/ */
static long long removeRange( const string& ns , static long long removeRange( const string& ns ,
const BSONObj& min , const BSONObj& min ,
const BSONObj& max , const BSONObj& max ,
const BSONObj& keyPattern , const BSONObj& keyPattern ,
bool maxInclusive = false , bool maxInclusive = false ,
bool secondaryThrottle = false ,
RemoveCallback * callback = 0, RemoveCallback * callback = 0,
bool fromMigrate = false ); bool fromMigrate = false );
/** /**
* Remove all documents from a collection. * Remove all documents from a collection.
* You do not need to set the database before calling. * You do not need to set the database before calling.
* Does not oplog the operation. * Does not oplog the operation.
*/ */
static void emptyCollection(const char *ns); static void emptyCollection(const char *ns);
 End of changes. 2 change blocks. 
1 lines changed or deleted 2 lines changed or added


 dbmessage.h   dbmessage.h 
skipping to change at line 108 skipping to change at line 108
void initializeResultFlags() { void initializeResultFlags() {
_resultFlags() = 0; _resultFlags() = 0;
} }
}; };
#pragma pack() #pragma pack()
/* For the database/server protocol, these objects and functions encaps ulate /* For the database/server protocol, these objects and functions encaps ulate
the various messages transmitted over the connection. the various messages transmitted over the connection.
See http://www.mongodb.org/display/DOCS/Mongo+Wire+Protocol See http://dochub.mongodb.org/core/mongowireprotocol
*/ */
class DbMessage { class DbMessage {
public: public:
DbMessage(const Message& _m) : m(_m) , mark(0) { DbMessage(const Message& _m) : m(_m) , mark(0) {
// for received messages, Message has only one buffer // for received messages, Message has only one buffer
theEnd = _m.singleData()->_data + _m.header()->dataLen(); theEnd = _m.singleData()->_data + _m.header()->dataLen();
char *r = _m.singleData()->_data; char *r = _m.singleData()->_data;
reserved = (int *) r; reserved = (int *) r;
data = r + 4; data = r + 4;
nextjsobj = data; nextjsobj = data;
 End of changes. 1 change blocks. 
1 lines changed or deleted 1 lines changed or added


 delete.h   delete.h 
skipping to change at line 21 skipping to change at line 21
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details. * GNU Affero General Public License for more details.
* *
* You should have received a copy of the GNU Affero General Public Licen se * You should have received a copy of the GNU Affero General Public Licen se
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#pragma once #pragma once
#include "../../pch.h" #include "mongo/pch.h"
#include "../jsobj.h" #include "../jsobj.h"
#include "../clientcursor.h" #include "../clientcursor.h"
namespace mongo { namespace mongo {
class RemoveSaver; class RemoveSaver;
// If justOne is true, deletedId is set to the id of the deleted object . // If justOne is true, deletedId is set to the id of the deleted object .
long long deleteObjects(const char *ns, BSONObj pattern, bool justOne, bool logop = false, bool god=false, RemoveSaver * rs=0); long long deleteObjects(const char *ns, BSONObj pattern, bool justOne, bool logop = false, bool god=false, RemoveSaver * rs=0);
 End of changes. 1 change blocks. 
1 lines changed or deleted 1 lines changed or added


 distlock.h   distlock.h 
skipping to change at line 20 skipping to change at line 20
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or impli ed. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or impli ed.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#pragma once #pragma once
#include "../pch.h" #include "mongo/pch.h"
#include "connpool.h" #include "connpool.h"
#include "syncclusterconnection.h" #include "syncclusterconnection.h"
#define LOCK_TIMEOUT (15 * 60 * 1000) #define LOCK_TIMEOUT (15 * 60 * 1000)
#define LOCK_SKEW_FACTOR (30) #define LOCK_SKEW_FACTOR (30)
#define LOCK_PING (LOCK_TIMEOUT / LOCK_SKEW_FACTOR) #define LOCK_PING (LOCK_TIMEOUT / LOCK_SKEW_FACTOR)
#define MAX_LOCK_NET_SKEW (LOCK_TIMEOUT / LOCK_SKEW_FACTOR) #define MAX_LOCK_NET_SKEW (LOCK_TIMEOUT / LOCK_SKEW_FACTOR)
#define MAX_LOCK_CLOCK_SKEW (LOCK_TIMEOUT / LOCK_SKEW_FACTOR) #define MAX_LOCK_CLOCK_SKEW (LOCK_TIMEOUT / LOCK_SKEW_FACTOR)
#define NUM_LOCK_SKEW_CHECKS (3) #define NUM_LOCK_SKEW_CHECKS (3)
 End of changes. 1 change blocks. 
1 lines changed or deleted 1 lines changed or added


 doc_mem_monitor.h   doc_mem_monitor.h 
skipping to change at line 19 skipping to change at line 19
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details. * GNU Affero General Public License for more details.
* *
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#pragma once #pragma once
#include "pch.h" #include "mongo/pch.h"
#include "util/string_writer.h" #include "util/string_writer.h"
namespace mongo { namespace mongo {
/* /*
This utility class provides an easy way to total up, monitor, warn, a nd This utility class provides an easy way to total up, monitor, warn, a nd
signal an error when the amount of memory used for an operation excee ds signal an error when the amount of memory used for an operation excee ds
given thresholds. given thresholds.
Create a local instance of this class, and then inform it of any memo ry Create a local instance of this class, and then inform it of any memo ry
 End of changes. 1 change blocks. 
1 lines changed or deleted 1 lines changed or added


 docgenerator.h   docgenerator.h 
skipping to change at line 20 skipping to change at line 20
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details. * GNU Affero General Public License for more details.
* *
* You should have received a copy of the GNU Affero General Public Licen se * You should have received a copy of the GNU Affero General Public Licen se
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
/** /**
* This is a simple document generator. It generates documents of the form at * This is a simple document generator. It generates documents of the form at
* { id:xxx, counterUp:xxx, hashIdUp: hashof(counterUp), blob: xxx, counte * { _id: xxx, blob: "xxx", nestedDoc: {xxx}, list: [xxx,yyy,zzz], counter
rDown:xxx, : xxx }
* hashIdUp: hashof(counterDown) }
*/ */
#include <limits> #pragma once
#include <string> #include <string>
#include <vector>
#include "mongo/db/jsobj.h" #include "mongo/db/jsobj.h"
namespace mongo { namespace mongo {
struct DocGeneratorOptions { struct DocGeneratorOptions {
DocGeneratorOptions() : DocGeneratorOptions() :
hostname(""), hostname(""),
dbSize( 0.0 ), dbSize( 0.0 ),
numdbs( 0 ), numdbs( 0 ),
prefix("") prefix("")
{ } { }
std::string hostname; std::string hostname;
double dbSize; double dbSize;
int numdbs; int numdbs;
std::string prefix; std::string prefix;
}; };
struct DocConfig { struct DocConfig {
DocConfig() : DocConfig() :
counterUp( 0 ), id( 0 ),
counterDown( std::numeric_limits<long long>::max() ),
blob( "" ), blob( "" ),
md5seed( "" ) counter( 0 )
{ } { }
long long counterUp; long long id;
long long counterDown;
std::string blob; std::string blob;
std::string md5seed; BSONObj nestedDoc;
std::vector<std::string> list;
long long counter;
}; };
// Creates a documentGenerator that can be used to create sample docume nts // Creates a documentGenerator that can be used to create sample docume nts
class DocumentGenerator { class DocumentGenerator {
public: public:
DocumentGenerator( ) { } DocumentGenerator( ) { }
~DocumentGenerator() { } ~DocumentGenerator() { }
void init( BSONObj& args ); void init( BSONObj& args );
BSONObj createDocument(); BSONObj createDocument();
 End of changes. 7 change blocks. 
10 lines changed or deleted 11 lines changed or added


 document.h   document.h 
skipping to change at line 19 skipping to change at line 19
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details. * GNU Affero General Public License for more details.
* *
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#pragma once #pragma once
#include "pch.h" #include "mongo/pch.h"
#include "util/intrusive_counter.h" #include "util/intrusive_counter.h"
namespace mongo { namespace mongo {
class BSONObj; class BSONObj;
class DependencyTracker;
class FieldIterator; class FieldIterator;
class Value; class Value;
class Document : class Document :
public IntrusiveCounterUnsigned { public IntrusiveCounterUnsigned {
public: public:
~Document(); ~Document();
/* /*
Create a new Document from the given BSONObj. Create a new Document from the given BSONObj.
Document field values may be pointed to in the BSONObj, so it Document field values may be pointed to in the BSONObj, so it
must live at least as long as the resulting Document. must live at least as long as the resulting Document.
LATER - use an abstract class for the dependencies; something lik
e
a "lookup(const string &fieldName)" so there can be other
implementations.
@returns shared pointer to the newly created Document @returns shared pointer to the newly created Document
*/ */
static intrusive_ptr<Document> createFromBsonObj( static intrusive_ptr<Document> createFromBsonObj(BSONObj* pBsonObj)
BSONObj *pBsonObj, const DependencyTracker *pDependencies = NUL ;
L);
/* /*
Create a new empty Document. Create a new empty Document.
@param sizeHint a hint at what the number of fields will be; if @param sizeHint a hint at what the number of fields will be; if
known, this can be used to increase memory allocation efficienc y known, this can be used to increase memory allocation efficienc y
@returns shared pointer to the newly created Document @returns shared pointer to the newly created Document
*/ */
static intrusive_ptr<Document> create(size_t sizeHint = 0); static intrusive_ptr<Document> create(size_t sizeHint = 0);
skipping to change at line 74 skipping to change at line 68
are cloned. are cloned.
@returns the shallow clone of the document @returns the shallow clone of the document
*/ */
intrusive_ptr<Document> clone(); intrusive_ptr<Document> clone();
/* /*
Add this document to the BSONObj under construction with the Add this document to the BSONObj under construction with the
given BSONObjBuilder. given BSONObjBuilder.
*/ */
void toBson(BSONObjBuilder *pBsonObjBuilder); void toBson(BSONObjBuilder *pBsonObjBuilder) const;
/* /*
Create a new FieldIterator that can be used to examine the Create a new FieldIterator that can be used to examine the
Document's fields. Document's fields.
*/ */
FieldIterator *createFieldIterator(); FieldIterator *createFieldIterator();
/* /*
Get the value of the specified field. Get the value of the specified field.
skipping to change at line 106 skipping to change at line 100
It is an error to add a field that has the same name as another It is an error to add a field that has the same name as another
field. field.
*/ */
void addField(const string &fieldName, void addField(const string &fieldName,
const intrusive_ptr<const Value> &pValue); const intrusive_ptr<const Value> &pValue);
/* /*
Set the given field to be at the specified position in the Set the given field to be at the specified position in the
Document. This will replace any field that is currently in that Document. This will replace any field that is currently in that
position. The index must be within the current range of field position. The index must be within the current range of field
indices. indices, otherwise behavior is undefined.
pValue.get() may be NULL, in which case the field will be pValue.get() may be NULL, in which case the field will be
removed. fieldName is ignored in this case. removed. fieldName is ignored in this case.
@param index the field index in the list of fields @param index the field index in the list of fields
@param fieldName the new field name @param fieldName the new field name
@param pValue the new Value @param pValue the new Value
*/ */
void setField(size_t index, void setField(size_t index,
const string &fieldName, const string &fieldName,
skipping to change at line 189 skipping to change at line 183
/* /*
Calculate a hash value. Calculate a hash value.
Meant to be used to create composite hashes suitable for Meant to be used to create composite hashes suitable for
boost classes such as unordered_map<>. boost classes such as unordered_map<>.
@param seed value to augment with this' hash @param seed value to augment with this' hash
*/ */
void hash_combine(size_t &seed) const; void hash_combine(size_t &seed) const;
// For debugging purposes only!
string toString() const;
private: private:
friend class FieldIterator; friend class FieldIterator;
Document(size_t sizeHint); Document(size_t sizeHint);
Document(BSONObj *pBsonObj, const DependencyTracker *pDependencies) ; Document(BSONObj* pBsonObj);
/* these two vectors parallel each other */ /* these two vectors parallel each other */
vector<string> vFieldName; vector<string> vFieldName;
vector<intrusive_ptr<const Value> > vpValue; vector<intrusive_ptr<const Value> > vpValue;
}; };
class FieldIterator : class FieldIterator :
boost::noncopyable { boost::noncopyable {
public: public:
/* /*
skipping to change at line 217 skipping to change at line 214
*/ */
bool more() const; bool more() const;
/* /*
Move the iterator to point to the next field and return it. Move the iterator to point to the next field and return it.
@return the next field's <name, Value> @return the next field's <name, Value>
*/ */
Document::FieldPair next(); Document::FieldPair next();
private:
friend class Document;
/* /*
Constructor. Constructor.
@param pDocument points to the document whose fields are being @param pDocument points to the document whose fields are being
iterated iterated
*/ */
FieldIterator(const intrusive_ptr<Document> &pDocument); FieldIterator(const intrusive_ptr<Document> &pDocument);
private:
friend class Document;
/* /*
We'll hang on to the original document to ensure we keep the We'll hang on to the original document to ensure we keep the
fieldPtr vector alive. fieldPtr vector alive.
*/ */
intrusive_ptr<Document> pDocument; intrusive_ptr<Document> pDocument;
size_t index; // current field in iteration size_t index; // current field in iteration
}; };
} }
/* ======================= INLINED IMPLEMENTATIONS ======================== == */ /* ======================= INLINED IMPLEMENTATIONS ======================== == */
 End of changes. 10 change blocks. 
16 lines changed or deleted 12 lines changed or added


 document_source.h   document_source.h 
skipping to change at line 19 skipping to change at line 19
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details. * GNU Affero General Public License for more details.
* *
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#pragma once #pragma once
#include "pch.h" #include "mongo/pch.h"
#include <boost/unordered_map.hpp> #include <boost/unordered_map.hpp>
#include "util/intrusive_counter.h" #include "util/intrusive_counter.h"
#include "client/parallel.h"
#include "db/clientcursor.h" #include "db/clientcursor.h"
#include "db/jsobj.h" #include "db/jsobj.h"
#include "db/pipeline/dependency_tracker.h"
#include "db/pipeline/document.h" #include "db/pipeline/document.h"
#include "db/pipeline/expression.h" #include "db/pipeline/expression.h"
#include "mongo/db/pipeline/expression_context.h"
#include "db/pipeline/value.h" #include "db/pipeline/value.h"
#include "util/string_writer.h" #include "util/string_writer.h"
#include "mongo/db/projection.h"
namespace mongo { namespace mongo {
class Accumulator; class Accumulator;
class Cursor; class Cursor;
class DependencyTracker;
class Document; class Document;
class Expression; class Expression;
class ExpressionContext; class ExpressionContext;
class ExpressionFieldPath; class ExpressionFieldPath;
class ExpressionObject; class ExpressionObject;
class Matcher; class Matcher;
class Shard;
class ShardChunkManager;
class DocumentSource : class DocumentSource :
public IntrusiveCounterUnsigned, public IntrusiveCounterUnsigned,
public StringWriter { public StringWriter {
public: public:
virtual ~DocumentSource(); virtual ~DocumentSource();
// virtuals from StringWriter // virtuals from StringWriter
virtual void writeString(stringstream &ss) const; virtual void writeString(stringstream &ss) const;
skipping to change at line 89 skipping to change at line 90
The default implementation returns false, after checking for The default implementation returns false, after checking for
interrupts. Derived classes can call the default implementation interrupts. Derived classes can call the default implementation
in their own implementations in order to check for interrupts. in their own implementations in order to check for interrupts.
@returns whether there is another document to fetch, i.e., whethe r or @returns whether there is another document to fetch, i.e., whethe r or
not getCurrent() will succeed. This default implementation alw ays not getCurrent() will succeed. This default implementation alw ays
returns false. returns false.
*/ */
virtual bool advance(); virtual bool advance();
/** /** @returns the current Document without advancing.
Advance the source, and return the next Expression. *
* some implementations do the equivalent of verify(!eof()) so che
@returns the current Document ck eof() first
TODO throws an exception if there are no more expressions to retu */
rn.
*/
virtual intrusive_ptr<Document> getCurrent() = 0; virtual intrusive_ptr<Document> getCurrent() = 0;
/** /**
* Inform the source that it is no longer needed and may release it
s resources. After
* dispose() is called the source must still be able to handle iter
ation requests, but may
* become eof().
* NOTE: For proper mutex yielding, dispose() must be called on any
DocumentSource that will
* not be advanced until eof(), see SERVER-6123.
*/
virtual void dispose();
/**
Get the source's name. Get the source's name.
@returns the string name of the source as a constant string; @returns the string name of the source as a constant string;
this is static, and there's no need to worry about adopting it this is static, and there's no need to worry about adopting it
*/ */
virtual const char *getSourceName() const; virtual const char *getSourceName() const;
/** /**
Set the underlying source this source should use to get Documents Set the underlying source this source should use to get Documents
from. from.
skipping to change at line 150 skipping to change at line 158
optimization that only looks within this DocumentSource. For bes t optimization that only looks within this DocumentSource. For bes t
results, first coalesce compatible sources using coalesce(). results, first coalesce compatible sources using coalesce().
This is intended for any operations that include expressions, and This is intended for any operations that include expressions, and
provides a hook for those to optimize those operations. provides a hook for those to optimize those operations.
The default implementation is to do nothing. The default implementation is to do nothing.
*/ */
virtual void optimize(); virtual void optimize();
/** enum GetDepsReturn {
Adjust dependencies according to the needs of this source. NOT_SUPPORTED, // This means the set should be ignored
EXHAUSTIVE, // This means that everything needed should be in t
he set
SEE_NEXT, // Add the next Source's deps to the set
};
/** Get the fields this operation needs to do its job.
* Deps should be in "a.b.c" notation
*
* @param deps results are added here. NOT CLEARED
*/
virtual GetDepsReturn getDependencies(set<string>& deps) const {
return NOT_SUPPORTED;
}
$$$ MONGO_LATER_SERVER_4644 /** This takes dependencies from getDependencies and
@param pTracker the dependency tracker * returns a projection that includes all of them
*/ */
virtual void manageDependencies( static BSONObj depsToProjection(const set<string>& deps);
const intrusive_ptr<DependencyTracker> &pTracker);
/** /**
Add the DocumentSource to the array builder. Add the DocumentSource to the array builder.
The default implementation calls sourceToBson() in order to The default implementation calls sourceToBson() in order to
convert the inner part of the object which will be added to the convert the inner part of the object which will be added to the
array being built here. array being built here.
@param pBuilder the array builder to add the operation to. @param pBuilder the array builder to add the operation to.
@param explain create explain output @param explain create explain output
skipping to change at line 217 skipping to change at line 236
intrusive_ptr<ExpressionContext> pExpCtx; intrusive_ptr<ExpressionContext> pExpCtx;
/* /*
for explain: # of rows returned by this source for explain: # of rows returned by this source
This is *not* unsigned so it can be passed to BSONObjBuilder.appe nd(). This is *not* unsigned so it can be passed to BSONObjBuilder.appe nd().
*/ */
long long nRowsOut; long long nRowsOut;
}; };
/** This class marks DocumentSources that should be split between the r
outer and the shards
* See Pipeline::splitForSharded() for details
*/
class SplittableDocumentSource : public DocumentSource {
public:
/** returns a source to be run on the shards.
* if NULL, don't run on shards
*/
virtual intrusive_ptr<DocumentSource> getShardSource() = 0;
/** returns a source that combines results from shards.
* if NULL, don't run on router
*/
virtual intrusive_ptr<DocumentSource> getRouterSource() = 0;
protected:
SplittableDocumentSource(intrusive_ptr<ExpressionContext> ctx) :Doc
umentSource(ctx) {}
};
class DocumentSourceBsonArray : class DocumentSourceBsonArray :
public DocumentSource { public DocumentSource {
public: public:
// virtuals from DocumentSource // virtuals from DocumentSource
virtual ~DocumentSourceBsonArray(); virtual ~DocumentSourceBsonArray();
virtual bool eof(); virtual bool eof();
virtual bool advance(); virtual bool advance();
virtual intrusive_ptr<Document> getCurrent(); virtual intrusive_ptr<Document> getCurrent();
virtual void setSource(DocumentSource *pSource); virtual void setSource(DocumentSource *pSource);
skipping to change at line 259 skipping to change at line 296
private: private:
DocumentSourceBsonArray(BSONElement *pBsonElement, DocumentSourceBsonArray(BSONElement *pBsonElement,
const intrusive_ptr<ExpressionContext> &pExpCtx); const intrusive_ptr<ExpressionContext> &pExpCtx);
BSONObj embeddedObject; BSONObj embeddedObject;
BSONObjIterator arrayIterator; BSONObjIterator arrayIterator;
BSONElement currentElement; BSONElement currentElement;
bool haveCurrent; bool haveCurrent;
}; };
class DocumentSourceCommandFutures : class DocumentSourceCommandShards :
public DocumentSource { public DocumentSource {
public: public:
// virtuals from DocumentSource // virtuals from DocumentSource
virtual ~DocumentSourceCommandFutures(); virtual ~DocumentSourceCommandShards();
virtual bool eof(); virtual bool eof();
virtual bool advance(); virtual bool advance();
virtual intrusive_ptr<Document> getCurrent(); virtual intrusive_ptr<Document> getCurrent();
virtual void setSource(DocumentSource *pSource); virtual void setSource(DocumentSource *pSource);
/* convenient shorthand for a commonly used type */ /* convenient shorthand for a commonly used type */
typedef list<shared_ptr<Future::CommandResult> > FuturesList; typedef map<Shard, BSONObj> ShardOutput;
/** /**
Create a DocumentSource that wraps a list of Command::Futures. Create a DocumentSource that wraps the output of many shards
@param errmsg place to write error messages to; must exist for th @param shardOutput output from the individual shards
e
lifetime of the created DocumentSourceCommandFutures
@param pList the list of futures
@param pExpCtx the expression context for the pipeline @param pExpCtx the expression context for the pipeline
@returns the newly created DocumentSource @returns the newly created DocumentSource
*/ */
static intrusive_ptr<DocumentSourceCommandFutures> create( static intrusive_ptr<DocumentSourceCommandShards> create(
string &errmsg, FuturesList *pList, const ShardOutput& shardOutput,
const intrusive_ptr<ExpressionContext> &pExpCtx); const intrusive_ptr<ExpressionContext>& pExpCtx);
protected: protected:
// virtuals from DocumentSource // virtuals from DocumentSource
virtual void sourceToBson(BSONObjBuilder *pBuilder, bool explain) c onst; virtual void sourceToBson(BSONObjBuilder *pBuilder, bool explain) c onst;
private: private:
DocumentSourceCommandFutures(string &errmsg, FuturesList *pList, DocumentSourceCommandShards(const ShardOutput& shardOutput,
const intrusive_ptr<ExpressionContext> &pExpCtx); const intrusive_ptr<ExpressionContext>& pExpCtx);
/** /**
Advance to the next document, setting pCurrent appropriately. Advance to the next document, setting pCurrent appropriately.
Adjusts pCurrent, pBsonSource, and iterator, as needed. On exit, Adjusts pCurrent, pBsonSource, and iterator, as needed. On exit,
pCurrent is the Document to return, or NULL. If NULL, this pCurrent is the Document to return, or NULL. If NULL, this
indicates there is nothing more to return. indicates there is nothing more to return.
*/ */
void getNextDocument(); void getNextDocument();
bool newSource; // set to true for the first item of a new source bool newSource; // set to true for the first item of a new source
intrusive_ptr<DocumentSourceBsonArray> pBsonSource; intrusive_ptr<DocumentSourceBsonArray> pBsonSource;
intrusive_ptr<Document> pCurrent; intrusive_ptr<Document> pCurrent;
FuturesList::iterator iterator; ShardOutput::const_iterator iterator;
FuturesList::iterator listEnd; ShardOutput::const_iterator listEnd;
string &errmsg;
}; };
/**
* Constructs and returns Documents from the BSONObj objects produced b
y a supplied Cursor.
* An object of this type may only be used by one thread, see SERVER-61
23.
*/
class DocumentSourceCursor : class DocumentSourceCursor :
public DocumentSource { public DocumentSource {
public: public:
/**
* Holds a Cursor and all associated state required to access the c
ursor. An object of this
* type may only be used by one thread.
*/
struct CursorWithContext {
/** Takes a read lock that will be held for the lifetime of the
object. */
CursorWithContext( const string& ns );
// Must be the first struct member for proper construction and
destruction, as other
// members may depend on the read lock it acquires.
Client::ReadContext _readContext;
shared_ptr<ShardChunkManager> _chunkMgr;
ClientCursor::Holder _cursor;
};
// virtuals from DocumentSource // virtuals from DocumentSource
virtual ~DocumentSourceCursor(); virtual ~DocumentSourceCursor();
virtual bool eof(); virtual bool eof();
virtual bool advance(); virtual bool advance();
virtual intrusive_ptr<Document> getCurrent(); virtual intrusive_ptr<Document> getCurrent();
virtual void setSource(DocumentSource *pSource); virtual void setSource(DocumentSource *pSource);
virtual void manageDependencies(
const intrusive_ptr<DependencyTracker> &pTracker); /**
* Release the Cursor and the read lock it requires, but without ch
anging the other data.
* Releasing the lock is required for proper concurrency, see SERVE
R-6123. This
* functionality is also used by the explain version of pipeline ex
ecution.
*/
virtual void dispose();
/** /**
Create a document source based on a cursor. Create a document source based on a cursor.
This is usually put at the beginning of a chain of document sourc es This is usually put at the beginning of a chain of document sourc es
in order to fetch data from the database. in order to fetch data from the database.
@param pCursor the cursor to use to fetch data @param pCursor the cursor to use to fetch data
@param pExpCtx the expression context for the pipeline @param pExpCtx the expression context for the pipeline
*/ */
static intrusive_ptr<DocumentSourceCursor> create( static intrusive_ptr<DocumentSourceCursor> create(
const shared_ptr<Cursor> &pCursor, const shared_ptr<CursorWithContext>& cursorWithContext,
const string &ns,
const intrusive_ptr<ExpressionContext> &pExpCtx); const intrusive_ptr<ExpressionContext> &pExpCtx);
/* /*
Record the namespace. Required for explain. Record the namespace. Required for explain.
@param namespace the namespace @param namespace the namespace
*/ */
void setNamespace(const string &ns); void setNamespace(const string &ns);
/* /*
skipping to change at line 369 skipping to change at line 426
This should be captured after any optimizations are applied to This should be captured after any optimizations are applied to
the pipeline so that it reflects what is really used. the pipeline so that it reflects what is really used.
This gets used for explain output. This gets used for explain output.
@param pBsonObj the sort to record @param pBsonObj the sort to record
*/ */
void setSort(const shared_ptr<BSONObj> &pBsonObj); void setSort(const shared_ptr<BSONObj> &pBsonObj);
/** void setProjection(BSONObj projection);
Release the cursor, but without changing the other data. This
is used for the explain version of pipeline execution.
*/
void releaseCursor();
protected: protected:
// virtuals from DocumentSource // virtuals from DocumentSource
virtual void sourceToBson(BSONObjBuilder *pBuilder, bool explain) c onst; virtual void sourceToBson(BSONObjBuilder *pBuilder, bool explain) c onst;
private: private:
DocumentSourceCursor( DocumentSourceCursor(
const shared_ptr<Cursor> &pTheCursor, const string &ns, const shared_ptr<CursorWithContext>& cursorWithContext,
const intrusive_ptr<ExpressionContext> &pExpCtx); const intrusive_ptr<ExpressionContext> &pExpCtx);
void findNext(); void findNext();
intrusive_ptr<Document> pCurrent; intrusive_ptr<Document> pCurrent;
string ns; // namespace string ns; // namespace
/* /*
The bsonDependencies must outlive the Cursor wrapped by this The bson dependencies must outlive the Cursor wrapped by this
source. Therefore, bsonDependencies must appear before pCursor source. Therefore, bson dependencies must appear before pCursor
in order cause its destructor to be called *after* pCursor's. in order cause its destructor to be called *after* pCursor's.
*/ */
shared_ptr<BSONObj> pQuery; shared_ptr<BSONObj> pQuery;
shared_ptr<BSONObj> pSort; shared_ptr<BSONObj> pSort;
vector<shared_ptr<BSONObj> > bsonDependencies; shared_ptr<Projection> _projection; // shared with pClientCursor
shared_ptr<Cursor> pCursor;
/* shared_ptr<CursorWithContext> _cursorWithContext;
In order to yield, we need a ClientCursor.
*/
ClientCursor::Holder pClientCursor;
/* ClientCursor::Holder& cursor();
Advance the cursor, and yield sometimes. const ShardChunkManager* chunkMgr() { return _cursorWithContext->_c
hunkMgr.get(); }
If the state of the world changed during the yield such that we bool canUseCoveredIndex();
are unable to continue execution of the query, this will release
the
client cursor, and throw an error.
*/
void advanceAndYield();
/* /*
This document source hangs on to the dependency tracker when it Yield the cursor sometimes.
gets it so that it can be used for selective reification of
fields in order to avoid fields that are not required through the
pipeline.
*/
intrusive_ptr<DependencyTracker> pDependencies;
/**
(5/14/12 - moved this to private because it's not used atm)
Add a BSONObj dependency.
Some Cursor creation functions rely on BSON objects to specify
their query predicate or sort. These often take a BSONObj
by reference for these, but do not copy it. As a result, the
BSONObjs specified must outlive the Cursor. In order to ensure
that, use this to preserve a pointer to the BSONObj here.
From the outside, you must also make sure the BSONObjBuilder
creates a lasting copy of the data, otherwise it will go away
when the builder goes out of scope. Therefore, the typical usag
e
pattern for this is
{
BSONObjBuilder builder;
// do stuff to the builder
shared_ptr<BSONObj> pBsonObj(new BSONObj(builder.obj()));
pDocumentSourceCursor->addBsonDependency(pBsonObj);
}
@param pBsonObj pointer to the BSON object to preserve If the state of the world changed during the yield such that we
are unable to continue execution of the query, this will release
the
client cursor, and throw an error. NOTE This differs from the
behavior of most other operations, see SERVER-2454.
*/ */
void addBsonDependency(const shared_ptr<BSONObj> &pBsonObj); void yieldSometimes();
}; };
/* /*
This contains all the basic mechanics for filtering a stream of This contains all the basic mechanics for filtering a stream of
Documents, except for the actual predicate evaluation itself. This w as Documents, except for the actual predicate evaluation itself. This w as
factored out so we could create DocumentSources that use both Matcher factored out so we could create DocumentSources that use both Matcher
style predicates as well as full Expressions. style predicates as well as full Expressions.
*/ */
class DocumentSourceFilterBase : class DocumentSourceFilterBase :
public DocumentSource { public DocumentSource {
skipping to change at line 558 skipping to change at line 580
virtual bool accept(const intrusive_ptr<Document> &pDocument) const ; virtual bool accept(const intrusive_ptr<Document> &pDocument) const ;
private: private:
DocumentSourceFilter(const intrusive_ptr<Expression> &pFilter, DocumentSourceFilter(const intrusive_ptr<Expression> &pFilter,
const intrusive_ptr<ExpressionContext> &pExpCt x); const intrusive_ptr<ExpressionContext> &pExpCt x);
intrusive_ptr<Expression> pFilter; intrusive_ptr<Expression> pFilter;
}; };
class DocumentSourceGroup : class DocumentSourceGroup :
public DocumentSource { public SplittableDocumentSource {
public: public:
// virtuals from DocumentSource // virtuals from DocumentSource
virtual ~DocumentSourceGroup(); virtual ~DocumentSourceGroup();
virtual bool eof(); virtual bool eof();
virtual bool advance(); virtual bool advance();
virtual const char *getSourceName() const; virtual const char *getSourceName() const;
virtual intrusive_ptr<Document> getCurrent(); virtual intrusive_ptr<Document> getCurrent();
virtual GetDepsReturn getDependencies(set<string>& deps) const;
/** /**
Create a new grouping DocumentSource. Create a new grouping DocumentSource.
@param pExpCtx the expression context for the pipeline @param pExpCtx the expression context for the pipeline
@returns the DocumentSource @returns the DocumentSource
*/ */
static intrusive_ptr<DocumentSourceGroup> create( static intrusive_ptr<DocumentSourceGroup> create(
const intrusive_ptr<ExpressionContext> &pExpCtx); const intrusive_ptr<ExpressionContext> &pExpCtx);
skipping to change at line 619 skipping to change at line 642
element named $group. element named $group.
@param pBsonElement the BSONELement that defines the group @param pBsonElement the BSONELement that defines the group
@param pExpCtx the expression context @param pExpCtx the expression context
@returns the grouping DocumentSource @returns the grouping DocumentSource
*/ */
static intrusive_ptr<DocumentSource> createFromBson( static intrusive_ptr<DocumentSource> createFromBson(
BSONElement *pBsonElement, BSONElement *pBsonElement,
const intrusive_ptr<ExpressionContext> &pExpCtx); const intrusive_ptr<ExpressionContext> &pExpCtx);
/** // Virtuals for SplittableDocumentSource
Create a unifying group that can be used to combine group results virtual intrusive_ptr<DocumentSource> getShardSource();
from shards. virtual intrusive_ptr<DocumentSource> getRouterSource();
@returns the grouping DocumentSource
*/
intrusive_ptr<DocumentSource> createMerger();
static const char groupName[]; static const char groupName[];
protected: protected:
// virtuals from DocumentSource // virtuals from DocumentSource
virtual void sourceToBson(BSONObjBuilder *pBuilder, bool explain) c onst; virtual void sourceToBson(BSONObjBuilder *pBuilder, bool explain) c onst;
private: private:
DocumentSourceGroup(const intrusive_ptr<ExpressionContext> &pExpCtx ); DocumentSourceGroup(const intrusive_ptr<ExpressionContext> &pExpCtx );
skipping to change at line 681 skipping to change at line 700
GroupsType::iterator groupsIterator; GroupsType::iterator groupsIterator;
intrusive_ptr<Document> pCurrent; intrusive_ptr<Document> pCurrent;
}; };
class DocumentSourceMatch : class DocumentSourceMatch :
public DocumentSourceFilterBase { public DocumentSourceFilterBase {
public: public:
// virtuals from DocumentSource // virtuals from DocumentSource
virtual ~DocumentSourceMatch(); virtual ~DocumentSourceMatch();
virtual const char *getSourceName() const; virtual const char *getSourceName() const;
virtual void manageDependencies(
const intrusive_ptr<DependencyTracker> &pTracker);
/** /**
Create a filter. Create a filter.
@param pBsonElement the raw BSON specification for the filter @param pBsonElement the raw BSON specification for the filter
@returns the filter @returns the filter
*/ */
static intrusive_ptr<DocumentSource> createFromBson( static intrusive_ptr<DocumentSource> createFromBson(
BSONElement *pBsonElement, BSONElement *pBsonElement,
const intrusive_ptr<ExpressionContext> &pCtx); const intrusive_ptr<ExpressionContext> &pCtx);
skipping to change at line 768 skipping to change at line 785
class DocumentSourceProject : class DocumentSourceProject :
public DocumentSource { public DocumentSource {
public: public:
// virtuals from DocumentSource // virtuals from DocumentSource
virtual ~DocumentSourceProject(); virtual ~DocumentSourceProject();
virtual bool eof(); virtual bool eof();
virtual bool advance(); virtual bool advance();
virtual const char *getSourceName() const; virtual const char *getSourceName() const;
virtual intrusive_ptr<Document> getCurrent(); virtual intrusive_ptr<Document> getCurrent();
virtual void optimize(); virtual void optimize();
virtual void manageDependencies(
const intrusive_ptr<DependencyTracker> &pTracker);
/**
Create a new DocumentSource that can implement projection.
@param pExpCtx the expression context for the pipeline
@returns the projection DocumentSource
*/
static intrusive_ptr<DocumentSourceProject> create(
const intrusive_ptr<ExpressionContext> &pExpCtx);
/**
Include a field path in a projection.
@param fieldPath the path of the field to include
*/
void includePath(const string &fieldPath);
/**
Exclude a field path from the projection.
@param fieldPath the path of the field to exclude
*/
void excludePath(const string &fieldPath);
/**
Add an output Expression in the projection.
BSON document fields are ordered, so the new field will be
appended to the existing set.
@param fieldName the name of the field as it will appear virtual GetDepsReturn getDependencies(set<string>& deps) const;
@param pExpression the expression used to compute the field
*/
void addField(const string &fieldName,
const intrusive_ptr<Expression> &pExpression);
/** /**
Create a new projection DocumentSource from BSON. Create a new projection DocumentSource from BSON.
This is a convenience for directly handling BSON, and relies on t he This is a convenience for directly handling BSON, and relies on t he
above methods. above methods.
@param pBsonElement the BSONElement with an object named $project @param pBsonElement the BSONElement with an object named $project
@param pExpCtx the expression context for the pipeline @param pExpCtx the expression context for the pipeline
@returns the created projection @returns the created projection
*/ */
static intrusive_ptr<DocumentSource> createFromBson( static intrusive_ptr<DocumentSource> createFromBson(
BSONElement *pBsonElement, BSONElement *pBsonElement,
const intrusive_ptr<ExpressionContext> &pExpCtx); const intrusive_ptr<ExpressionContext> &pExpCtx);
static const char projectName[]; static const char projectName[];
/** projection as specified by the user */
BSONObj getRaw() const { return _raw; }
protected: protected:
// virtuals from DocumentSource // virtuals from DocumentSource
virtual void sourceToBson(BSONObjBuilder *pBuilder, bool explain) c onst; virtual void sourceToBson(BSONObjBuilder *pBuilder, bool explain) c onst;
private: private:
DocumentSourceProject(const intrusive_ptr<ExpressionContext> &pExpC tx); DocumentSourceProject(const intrusive_ptr<ExpressionContext> &pExpC tx);
// configuration state // configuration state
bool excludeId;
intrusive_ptr<ExpressionObject> pEO; intrusive_ptr<ExpressionObject> pEO;
BSONObj _raw;
/* #if defined(_DEBUG)
Utility object used by manageDependencies(). // this is used in DEBUG builds to ensure we are compatible
Projection _simpleProjection;
Removes dependencies from a DependencyTracker. #endif
*/
class DependencyRemover :
public ExpressionObject::PathSink {
public:
// virtuals from PathSink
virtual void path(const string &path, bool include);
/*
Constructor.
Captures a reference to the smart pointer to the DependencyTr
acker
that this will remove dependencies from via
ExpressionObject::emitPaths().
@param pTracker reference to the smart pointer to the
DependencyTracker
*/
DependencyRemover(const intrusive_ptr<DependencyTracker> &pTrac
ker);
private:
const intrusive_ptr<DependencyTracker> &pTracker;
};
/*
Utility object used by manageDependencies().
Checks dependencies to see if they are present. If not, then
throws a user error.
*/
class DependencyChecker :
public ExpressionObject::PathSink {
public:
// virtuals from PathSink
virtual void path(const string &path, bool include);
/*
Constructor.
Captures a reference to the smart pointer to the DependencyTr
acker
that this will check dependencies from from
ExpressionObject::emitPaths() to see if they are required.
@param pTracker reference to the smart pointer to the
DependencyTracker
@param pThis the projection that is making this request
*/
DependencyChecker(
const intrusive_ptr<DependencyTracker> &pTracker,
const DocumentSourceProject *pThis);
private:
const intrusive_ptr<DependencyTracker> &pTracker;
const DocumentSourceProject *pThis;
};
}; };
class DocumentSourceSort : class DocumentSourceSort :
public DocumentSource { public SplittableDocumentSource {
public: public:
// virtuals from DocumentSource // virtuals from DocumentSource
virtual ~DocumentSourceSort(); virtual ~DocumentSourceSort();
virtual bool eof(); virtual bool eof();
virtual bool advance(); virtual bool advance();
virtual const char *getSourceName() const; virtual const char *getSourceName() const;
virtual intrusive_ptr<Document> getCurrent(); virtual intrusive_ptr<Document> getCurrent();
virtual void manageDependencies(
const intrusive_ptr<DependencyTracker> &pTracker); virtual GetDepsReturn getDependencies(set<string>& deps) const;
/* /*
TODO TODO
Adjacent sorts should reduce to the last sort. Adjacent sorts should reduce to the last sort.
virtual bool coalesce(const intrusive_ptr<DocumentSource> &pNextSou rce); virtual bool coalesce(const intrusive_ptr<DocumentSource> &pNextSou rce);
*/ */
/** /**
Create a new sorting DocumentSource. Create a new sorting DocumentSource.
@param pExpCtx the expression context for the pipeline @param pExpCtx the expression context for the pipeline
@returns the DocumentSource @returns the DocumentSource
*/ */
static intrusive_ptr<DocumentSourceSort> create( static intrusive_ptr<DocumentSourceSort> create(
const intrusive_ptr<ExpressionContext> &pExpCtx); const intrusive_ptr<ExpressionContext> &pExpCtx);
// Virtuals for SplittableDocumentSource
// All work for sort is done in router currently
// TODO: do partial sorts on the shards then merge in the router
// Not currently possible due to DocumentSource's cursor-like
interface
virtual intrusive_ptr<DocumentSource> getShardSource() { return NUL
L; }
virtual intrusive_ptr<DocumentSource> getRouterSource() { return th
is; }
/** /**
Add sort key field. Add sort key field.
Adds a sort key field to the key being built up. A concatenated Adds a sort key field to the key being built up. A concatenated
key is built up by calling this repeatedly. key is built up by calling this repeatedly.
@param fieldPath the field path to the key component @param fieldPath the field path to the key component
@param ascending if true, use the key for an ascending sort, @param ascending if true, use the key for an ascending sort,
otherwise, use it for descending otherwise, use it for descending
*/ */
skipping to change at line 971 skipping to change at line 910
DocumentSourceSort(const intrusive_ptr<ExpressionContext> &pExpCtx) ; DocumentSourceSort(const intrusive_ptr<ExpressionContext> &pExpCtx) ;
/* /*
Before returning anything, this source must fetch everything from Before returning anything, this source must fetch everything from
the underlying source and group it. populate() is used to do tha t the underlying source and group it. populate() is used to do tha t
on the first call to any method on this source. The populated on the first call to any method on this source. The populated
boolean indicates that this has been done. boolean indicates that this has been done.
*/ */
void populate(); void populate();
bool populated; bool populated;
long long count;
/* these two parallel each other */ /* these two parallel each other */
typedef vector<intrusive_ptr<ExpressionFieldPath> > SortPaths; typedef vector<intrusive_ptr<ExpressionFieldPath> > SortPaths;
SortPaths vSortKey; SortPaths vSortKey;
vector<bool> vAscending; vector<bool> vAscending;
/* /*
Compare two documents according to the specified sort key. Compare two documents according to the specified sort key.
@param rL reference to the left document @param rL reference to the left document
skipping to change at line 1027 skipping to change at line 965
public DocumentSource { public DocumentSource {
public: public:
// virtuals from DocumentSource // virtuals from DocumentSource
virtual ~DocumentSourceLimit(); virtual ~DocumentSourceLimit();
virtual bool eof(); virtual bool eof();
virtual bool advance(); virtual bool advance();
virtual intrusive_ptr<Document> getCurrent(); virtual intrusive_ptr<Document> getCurrent();
virtual const char *getSourceName() const; virtual const char *getSourceName() const;
virtual bool coalesce(const intrusive_ptr<DocumentSource> &pNextSou rce); virtual bool coalesce(const intrusive_ptr<DocumentSource> &pNextSou rce);
virtual GetDepsReturn getDependencies(set<string>& deps) const {
return SEE_NEXT; // This doesn't affect needed fields
}
/** /**
Create a new limiting DocumentSource. Create a new limiting DocumentSource.
@param pExpCtx the expression context for the pipeline @param pExpCtx the expression context for the pipeline
@returns the DocumentSource @returns the DocumentSource
*/ */
static intrusive_ptr<DocumentSourceLimit> create( static intrusive_ptr<DocumentSourceLimit> create(
const intrusive_ptr<ExpressionContext> &pExpCtx); const intrusive_ptr<ExpressionContext> &pExpCtx);
/** /**
skipping to change at line 1077 skipping to change at line 1019
public DocumentSource { public DocumentSource {
public: public:
// virtuals from DocumentSource // virtuals from DocumentSource
virtual ~DocumentSourceSkip(); virtual ~DocumentSourceSkip();
virtual bool eof(); virtual bool eof();
virtual bool advance(); virtual bool advance();
virtual intrusive_ptr<Document> getCurrent(); virtual intrusive_ptr<Document> getCurrent();
virtual const char *getSourceName() const; virtual const char *getSourceName() const;
virtual bool coalesce(const intrusive_ptr<DocumentSource> &pNextSou rce); virtual bool coalesce(const intrusive_ptr<DocumentSource> &pNextSou rce);
virtual GetDepsReturn getDependencies(set<string>& deps) const {
return SEE_NEXT; // This doesn't affect needed fields
}
/** /**
Create a new skipping DocumentSource. Create a new skipping DocumentSource.
@param pExpCtx the expression context @param pExpCtx the expression context
@returns the DocumentSource @returns the DocumentSource
*/ */
static intrusive_ptr<DocumentSourceSkip> create( static intrusive_ptr<DocumentSourceSkip> create(
const intrusive_ptr<ExpressionContext> &pExpCtx); const intrusive_ptr<ExpressionContext> &pExpCtx);
/** /**
skipping to change at line 1129 skipping to change at line 1075
class DocumentSourceUnwind : class DocumentSourceUnwind :
public DocumentSource { public DocumentSource {
public: public:
// virtuals from DocumentSource // virtuals from DocumentSource
virtual ~DocumentSourceUnwind(); virtual ~DocumentSourceUnwind();
virtual bool eof(); virtual bool eof();
virtual bool advance(); virtual bool advance();
virtual const char *getSourceName() const; virtual const char *getSourceName() const;
virtual intrusive_ptr<Document> getCurrent(); virtual intrusive_ptr<Document> getCurrent();
virtual void manageDependencies(
const intrusive_ptr<DependencyTracker> &pTracker);
/**
Create a new DocumentSource that can implement unwind.
@param pExpCtx the expression context for the pipeline virtual GetDepsReturn getDependencies(set<string>& deps) const;
@returns the projection DocumentSource
*/
static intrusive_ptr<DocumentSourceUnwind> create(
const intrusive_ptr<ExpressionContext> &pExpCtx);
/**
Specify the field to unwind. There must be exactly one before
the pipeline begins execution.
@param rFieldPath - path to the field to unwind
*/
void unwindField(const FieldPath &rFieldPath);
/** /**
Create a new projection DocumentSource from BSON. Create a new projection DocumentSource from BSON.
This is a convenience for directly handling BSON, and relies on t he This is a convenience for directly handling BSON, and relies on t he
above methods. above methods.
@param pBsonElement the BSONElement with an object named $project @param pBsonElement the BSONElement with an object named $project
@param pExpCtx the expression context for the pipeline @param pExpCtx the expression context for the pipeline
@returns the created projection @returns the created projection
skipping to change at line 1172 skipping to change at line 1101
static const char unwindName[]; static const char unwindName[];
protected: protected:
// virtuals from DocumentSource // virtuals from DocumentSource
virtual void sourceToBson(BSONObjBuilder *pBuilder, bool explain) c onst; virtual void sourceToBson(BSONObjBuilder *pBuilder, bool explain) c onst;
private: private:
DocumentSourceUnwind(const intrusive_ptr<ExpressionContext> &pExpCt x); DocumentSourceUnwind(const intrusive_ptr<ExpressionContext> &pExpCt x);
// configuration state /**
FieldPath unwindPath; * Lazily construct the _unwinder and initialize the iterator state
of this DocumentSource.
vector<int> fieldIndex; /* for the current document, the indices * To be called by all members that depend on the iterator state.
leading down to the field being unwound
*/
// iteration state
intrusive_ptr<Document> pNoUnwindDocument;
// document to return, pre-un
wind
intrusive_ptr<const Value> pUnwindArray; // field being unwound
intrusive_ptr<ValueIterator> pUnwinder; // iterator used for unwind
ing
intrusive_ptr<const Value> pUnwindValue; // current value
/*
Clear all the state related to unwinding an array.
*/ */
void resetArray(); void lazyInit();
/* /**
Clone the current document being unwound. * If the _unwinder is exhausted and the source may be advanced, ad
vance the pSource and
* reset the _unwinder's source document.
*/
void mayAdvanceSource();
This is a partial deep clone. Because we're going to replace the /** Specify the field to unwind. */
value at the end, we have to replace everything along the path void unwindPath(const FieldPath &fieldPath);
leading to that in order to not share that change with any other
clones (or the original) that we've made.
This expects pUnwindValue to have been set by a prior call to // Configuration state.
advance(). However, pUnwindValue may also be NULL, in which case scoped_ptr<FieldPath> _unwindPath;
the field will be removed -- this is the action for an empty
array.
@returns a partial deep clone of pNoUnwindDocument // Iteration state.
*/ class Unwinder;
intrusive_ptr<Document> clonePath() const; scoped_ptr<Unwinder> _unwinder;
}; };
} }
/* ======================= INLINED IMPLEMENTATIONS ======================== == */ /* ======================= INLINED IMPLEMENTATIONS ======================== == */
namespace mongo { namespace mongo {
inline void DocumentSource::setPipelineStep(int s) { inline void DocumentSource::setPipelineStep(int s) {
step = s; step = s;
} }
inline int DocumentSource::getPipelineStep() const { inline int DocumentSource::getPipelineStep() const {
return step; return step;
} }
inline void DocumentSourceGroup::setIdExpression( inline void DocumentSourceGroup::setIdExpression(
const intrusive_ptr<Expression> &pExpression) { const intrusive_ptr<Expression> &pExpression) {
pIdExpression = pExpression; pIdExpression = pExpression;
} }
inline DocumentSourceProject::DependencyRemover::DependencyRemover(
const intrusive_ptr<DependencyTracker> &pT):
pTracker(pT) {
}
inline DocumentSourceProject::DependencyChecker::DependencyChecker(
const intrusive_ptr<DependencyTracker> &pTrack,
const DocumentSourceProject *pT):
pTracker(pTrack),
pThis(pT) {
}
inline void DocumentSourceUnwind::resetArray() {
pNoUnwindDocument.reset();
pUnwindArray.reset();
pUnwinder.reset();
pUnwindValue.reset();
}
} }
 End of changes. 61 change blocks. 
272 lines changed or deleted 180 lines changed or added


 explain.h   explain.h 
skipping to change at line 67 skipping to change at line 67
void notePicked(); void notePicked();
/** BSON summary of the plan. */ /** BSON summary of the plan. */
BSONObj bson() const; BSONObj bson() const;
/** Combined details of both the plan and its clause. */ /** Combined details of both the plan and its clause. */
BSONObj pickedPlanBson( const ExplainClauseInfo &clauseInfo ) const ; BSONObj pickedPlanBson( const ExplainClauseInfo &clauseInfo ) const ;
bool picked() const { return _picked; } bool picked() const { return _picked; }
bool done() const { return _done; } bool done() const { return _done; }
long long n() const { return _n; } long long n() const { return _n; }
long long nscannedObjects() const { return _nscannedObjects; }
long long nscanned() const { return _nscanned; } long long nscanned() const { return _nscanned; }
private: private:
void noteCursorUpdate( const Cursor &cursor ); void noteCursorUpdate( const Cursor &cursor );
string _cursorName; string _cursorName;
bool _isMultiKey; bool _isMultiKey;
long long _n; long long _n;
long long _nscannedObjects; long long _nscannedObjects;
long long _nscanned; long long _nscanned;
bool _scanAndOrder; bool _scanAndOrder;
skipping to change at line 103 skipping to change at line 104
/** Revise the total number of documents returned to match an exter nal count. */ /** Revise the total number of documents returned to match an exter nal count. */
void reviseN( long long n ); void reviseN( long long n );
/** Stop the clauses's timer. */ /** Stop the clauses's timer. */
void stopTimer(); void stopTimer();
/** Add information about a plan to this clause. */ /** Add information about a plan to this clause. */
void addPlanInfo( const shared_ptr<ExplainPlanInfo> &info ); void addPlanInfo( const shared_ptr<ExplainPlanInfo> &info );
BSONObj bson() const; BSONObj bson() const;
long long n() const { return _n; } long long n() const { return _n; }
long long nscannedObjects() const { return _nscannedObjects; } long long nscannedObjects() const;
long long nscanned() const; long long nscanned() const;
long long nscannedObjectsAllPlans() const { return _nscannedObjects
; }
long long nscannedAllPlans() const;
long long nChunkSkips() const { return _nChunkSkips; } long long nChunkSkips() const { return _nChunkSkips; }
int nYields() const { return _nYields; } int nYields() const { return _nYields; }
int millis() const { return _timer.duration(); } int millis() const { return _timer.duration(); }
private: private:
/**
* @return Plan explain information to be displayed at the top of t
he explain output. A
* picked() plan will be returned if one is available, otherwise a
successful non picked()
* plan will be returned.
*/
const ExplainPlanInfo &virtualPickedPlan() const; const ExplainPlanInfo &virtualPickedPlan() const;
list<shared_ptr<const ExplainPlanInfo> > _plans; list<shared_ptr<const ExplainPlanInfo> > _plans;
long long _n; long long _n;
long long _nscannedObjects; long long _nscannedObjects;
long long _nChunkSkips; long long _nChunkSkips;
int _nYields; int _nYields;
DurationTimer _timer; DurationTimer _timer;
}; };
/** Data describing execution of a query. */ /** Data describing execution of a query. */
 End of changes. 4 change blocks. 
1 lines changed or deleted 12 lines changed or added


 expression.h   expression.h 
skipping to change at line 19 skipping to change at line 19
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details. * GNU Affero General Public License for more details.
* *
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#pragma once #pragma once
#include "pch.h" #include "mongo/pch.h"
#include "db/pipeline/field_path.h" #include "db/pipeline/field_path.h"
#include "db/pipeline/value.h"
#include "util/intrusive_counter.h" #include "util/intrusive_counter.h"
#include "util/iterator.h"
namespace mongo { namespace mongo {
class BSONArrayBuilder; class BSONArrayBuilder;
class BSONElement; class BSONElement;
class BSONObjBuilder; class BSONObjBuilder;
class Builder; class Builder;
class DependencyTracker;
class Document; class Document;
class DocumentSource; class DocumentSource;
class ExpressionContext; class ExpressionContext;
class Value; class Value;
class Expression : class Expression :
public IntrusiveCounterUnsigned { public IntrusiveCounterUnsigned {
public: public:
virtual ~Expression() {}; virtual ~Expression() {};
skipping to change at line 58 skipping to change at line 57
The Expression should be replaced with the return value, which ma y The Expression should be replaced with the return value, which ma y
or may not be the same object. In the case of constant folding, or may not be the same object. In the case of constant folding,
a computed expression may be replaced by a constant. a computed expression may be replaced by a constant.
@returns the optimized Expression @returns the optimized Expression
*/ */
virtual intrusive_ptr<Expression> optimize() = 0; virtual intrusive_ptr<Expression> optimize() = 0;
/** /**
Add this expression's field dependencies to the dependency track er. Add this expression's field dependencies to the set
Expressions are trees, so this is often recursive. Expressions are trees, so this is often recursive.
@params pTracker the tracker to add the dependencies to @param deps output parameter
@param path path to self if all ancestors are ExpressionObjects.
Top-level ExpressionObject gets pointer to empty vec
tor.
If any other Expression is an ancestor {a:1} object
aren't allowed, so they get NULL
*/ */
virtual void addDependencies( virtual void addDependencies(set<string>& deps, vector<string>* pat
const intrusive_ptr<DependencyTracker> &pTracker, h=NULL) const = 0;
const DocumentSource *pSource) const = 0;
/** simple expressions are just inclusion exclusion as supported by
ExpressionObject */
virtual bool isSimple() { return false; }
/* /*
Evaluate the Expression using the given document as input. Evaluate the Expression using the given document as input.
@returns the computed value @returns the computed value
*/ */
virtual intrusive_ptr<const Value> evaluate( virtual intrusive_ptr<const Value> evaluate(
const intrusive_ptr<Document> &pDocument) const = 0; const intrusive_ptr<Document> &pDocument) const = 0;
/* /*
skipping to change at line 130 skipping to change at line 135
implementation is to fail with an assertion; only a subset of implementation is to fail with an assertion; only a subset of
operators will be able to fulfill this request. operators will be able to fulfill this request.
@param pBuilder the builder to add the expression to. @param pBuilder the builder to add the expression to.
*/ */
virtual void toMatcherBson(BSONObjBuilder *pBuilder) const; virtual void toMatcherBson(BSONObjBuilder *pBuilder) const;
/* /*
Utility class for parseObject() below. Utility class for parseObject() below.
Only one array can be unwound in a processing pipeline. If the
UNWIND_OK option is used, unwindOk() will return true, and a fiel
d
can be declared as unwound using unwind(), after which unwindUsed
()
will return true. Only specify UNWIND_OK if it is OK to unwind a
n
array in the current context.
DOCUMENT_OK indicates that it is OK to use a Document in the curr ent DOCUMENT_OK indicates that it is OK to use a Document in the curr ent
context. context.
*/ */
class ObjectCtx { class ObjectCtx {
public: public:
ObjectCtx(int options); ObjectCtx(int options);
static const int UNWIND_OK = 0x0001; static const int DOCUMENT_OK = 0x0001;
static const int DOCUMENT_OK = 0x0002; static const int TOP_LEVEL = 0x0002;
static const int INCLUSION_OK = 0x0004;
bool unwindOk() const;
bool unwindUsed() const;
void unwind(string fieldName);
bool documentOk() const; bool documentOk() const;
bool topLevel() const;
bool inclusionOk() const;
private: private:
int options; int options;
string unwindField;
}; };
/* /*
Parse a BSONElement Object. The object could represent a functio nal Parse a BSONElement Object. The object could represent a functio nal
expression or a Document expression. expression or a Document expression.
@param pBsonElement the element representing the object @param pBsonElement the element representing the object
@param pCtx a MiniCtx representing the options above @param pCtx a MiniCtx representing the options above
@returns the parsed Expression @returns the parsed Expression
*/ */
static intrusive_ptr<Expression> parseObject( static intrusive_ptr<Expression> parseObject(
BSONElement *pBsonElement, ObjectCtx *pCtx); BSONElement *pBsonElement, ObjectCtx *pCtx);
static const char unwindName[];
/* /*
Parse a BSONElement Object which has already been determined to b e Parse a BSONElement Object which has already been determined to b e
functional expression. functional expression.
@param pOpName the name of the (prefix) operator @param pOpName the name of the (prefix) operator
@param pBsonElement the BSONElement to parse @param pBsonElement the BSONElement to parse
@returns the parsed Expression @returns the parsed Expression
*/ */
static intrusive_ptr<Expression> parseExpression( static intrusive_ptr<Expression> parseExpression(
const char *pOpName, BSONElement *pBsonElement); const char *pOpName, BSONElement *pBsonElement);
skipping to change at line 232 skipping to change at line 227
class ExpressionNary : class ExpressionNary :
public Expression { public Expression {
public: public:
// virtuals from Expression // virtuals from Expression
virtual intrusive_ptr<Expression> optimize(); virtual intrusive_ptr<Expression> optimize();
virtual void addToBsonObj( virtual void addToBsonObj(
BSONObjBuilder *pBuilder, string fieldName, BSONObjBuilder *pBuilder, string fieldName,
bool requireExpression) const; bool requireExpression) const;
virtual void addToBsonArray(BSONArrayBuilder *pBuilder) const; virtual void addToBsonArray(BSONArrayBuilder *pBuilder) const;
virtual void addDependencies( virtual void addDependencies(set<string>& deps, vector<string>* pat
const intrusive_ptr<DependencyTracker> &pTracker, h=NULL) const;
const DocumentSource *pSource) const;
/* /*
Add an operand to the n-ary expression. Add an operand to the n-ary expression.
@param pExpression the expression to add @param pExpression the expression to add
*/ */
virtual void addOperand(const intrusive_ptr<Expression> &pExpressio n); virtual void addOperand(const intrusive_ptr<Expression> &pExpressio n);
/* /*
Return a factory function that will make Expression nodes of Return a factory function that will make Expression nodes of
skipping to change at line 319 skipping to change at line 312
@param reqArgs the number of arguments this operator requires @param reqArgs the number of arguments this operator requires
*/ */
void checkArgCount(unsigned reqArgs) const; void checkArgCount(unsigned reqArgs) const;
}; };
class ExpressionAdd : class ExpressionAdd :
public ExpressionNary { public ExpressionNary {
public: public:
// virtuals from Expression // virtuals from Expression
virtual ~ExpressionAdd(); virtual ~ExpressionAdd();
virtual intrusive_ptr<Expression> optimize(); virtual intrusive_ptr<const Value> evaluate(const intrusive_ptr<Doc
virtual intrusive_ptr<const Value> evaluate( ument> &pDocument) const;
const intrusive_ptr<Document> &pDocument) const;
virtual const char *getOpName() const; virtual const char *getOpName() const;
// virtuals from ExpressionNary // virtuals from ExpressionNary
virtual intrusive_ptr<ExpressionNary> (*getFactory() const)(); virtual intrusive_ptr<ExpressionNary> (*getFactory() const)();
/* /*
Create an expression that finds the sum of n operands. Create an expression that finds the sum of n operands.
@returns addition expression @returns addition expression
*/ */
static intrusive_ptr<ExpressionNary> create(); static intrusive_ptr<ExpressionNary> create();
protected:
// virtuals from ExpressionNary
virtual void toBson(BSONObjBuilder *pBuilder,
const char *pOpName) const;
private:
ExpressionAdd();
/*
If the operator can be optimized, we save the original here.
This is necessary because addition must follow its original opera
nd
ordering strictly if a string is detected, otherwise string
concatenation may appear to have re-ordered the operands.
*/
intrusive_ptr<ExpressionAdd> pAdd;
mutable bool useOriginal;
}; };
class ExpressionAnd : class ExpressionAnd :
public ExpressionNary { public ExpressionNary {
public: public:
// virtuals from Expression // virtuals from Expression
virtual ~ExpressionAnd(); virtual ~ExpressionAnd();
virtual intrusive_ptr<Expression> optimize(); virtual intrusive_ptr<Expression> optimize();
virtual intrusive_ptr<const Value> evaluate( virtual intrusive_ptr<const Value> evaluate(
const intrusive_ptr<Document> &pDocument) const; const intrusive_ptr<Document> &pDocument) const;
skipping to change at line 388 skipping to change at line 361
private: private:
ExpressionAnd(); ExpressionAnd();
}; };
class ExpressionCoerceToBool : class ExpressionCoerceToBool :
public Expression { public Expression {
public: public:
// virtuals from ExpressionNary // virtuals from ExpressionNary
virtual ~ExpressionCoerceToBool(); virtual ~ExpressionCoerceToBool();
virtual intrusive_ptr<Expression> optimize(); virtual intrusive_ptr<Expression> optimize();
virtual void addDependencies( virtual void addDependencies(set<string>& deps, vector<string>* pat
const intrusive_ptr<DependencyTracker> &pTracker, h=NULL) const;
const DocumentSource *pSource) const;
virtual intrusive_ptr<const Value> evaluate( virtual intrusive_ptr<const Value> evaluate(
const intrusive_ptr<Document> &pDocument) const; const intrusive_ptr<Document> &pDocument) const;
virtual void addToBsonObj( virtual void addToBsonObj(
BSONObjBuilder *pBuilder, string fieldName, BSONObjBuilder *pBuilder, string fieldName,
bool requireExpression) const; bool requireExpression) const;
virtual void addToBsonArray(BSONArrayBuilder *pBuilder) const; virtual void addToBsonArray(BSONArrayBuilder *pBuilder) const;
static intrusive_ptr<ExpressionCoerceToBool> create( static intrusive_ptr<ExpressionCoerceToBool> create(
const intrusive_ptr<Expression> &pExpression); const intrusive_ptr<Expression> &pExpression);
skipping to change at line 463 skipping to change at line 434
private: private:
ExpressionCond(); ExpressionCond();
}; };
class ExpressionConstant : class ExpressionConstant :
public Expression { public Expression {
public: public:
// virtuals from Expression // virtuals from Expression
virtual ~ExpressionConstant(); virtual ~ExpressionConstant();
virtual intrusive_ptr<Expression> optimize(); virtual intrusive_ptr<Expression> optimize();
virtual void addDependencies( virtual void addDependencies(set<string>& deps, vector<string>* pat
const intrusive_ptr<DependencyTracker> &pTracker, h=NULL) const;
const DocumentSource *pSource) const;
virtual intrusive_ptr<const Value> evaluate( virtual intrusive_ptr<const Value> evaluate(
const intrusive_ptr<Document> &pDocument) const; const intrusive_ptr<Document> &pDocument) const;
virtual const char *getOpName() const; virtual const char *getOpName() const;
virtual void addToBsonObj( virtual void addToBsonObj(
BSONObjBuilder *pBuilder, string fieldName, BSONObjBuilder *pBuilder, string fieldName,
bool requireExpression) const; bool requireExpression) const;
virtual void addToBsonArray(BSONArrayBuilder *pBuilder) const; virtual void addToBsonArray(BSONArrayBuilder *pBuilder) const;
static intrusive_ptr<ExpressionConstant> createFromBsonElement( static intrusive_ptr<ExpressionConstant> createFromBsonElement(
BSONElement *pBsonElement); BSONElement *pBsonElement);
skipping to change at line 563 skipping to change at line 532
private: private:
ExpressionDivide(); ExpressionDivide();
}; };
class ExpressionFieldPath : class ExpressionFieldPath :
public Expression { public Expression {
public: public:
// virtuals from Expression // virtuals from Expression
virtual ~ExpressionFieldPath(); virtual ~ExpressionFieldPath();
virtual intrusive_ptr<Expression> optimize(); virtual intrusive_ptr<Expression> optimize();
virtual void addDependencies( virtual void addDependencies(set<string>& deps, vector<string>* pat
const intrusive_ptr<DependencyTracker> &pTracker, h=NULL) const;
const DocumentSource *pSource) const;
virtual intrusive_ptr<const Value> evaluate( virtual intrusive_ptr<const Value> evaluate(
const intrusive_ptr<Document> &pDocument) const; const intrusive_ptr<Document> &pDocument) const;
virtual void addToBsonObj( virtual void addToBsonObj(
BSONObjBuilder *pBuilder, string fieldName, BSONObjBuilder *pBuilder, string fieldName,
bool requireExpression) const; bool requireExpression) const;
virtual void addToBsonArray(BSONArrayBuilder *pBuilder) const; virtual void addToBsonArray(BSONArrayBuilder *pBuilder) const;
/* /*
Create a field path expression. Create a field path expression.
skipping to change at line 634 skipping to change at line 601
FieldPath fieldPath; FieldPath fieldPath;
}; };
class ExpressionFieldRange : class ExpressionFieldRange :
public Expression { public Expression {
public: public:
// virtuals from expression // virtuals from expression
virtual ~ExpressionFieldRange(); virtual ~ExpressionFieldRange();
virtual intrusive_ptr<Expression> optimize(); virtual intrusive_ptr<Expression> optimize();
virtual void addDependencies( virtual void addDependencies(set<string>& deps, vector<string>* pat
const intrusive_ptr<DependencyTracker> &pTracker, h=NULL) const;
const DocumentSource *pSource) const;
virtual intrusive_ptr<const Value> evaluate( virtual intrusive_ptr<const Value> evaluate(
const intrusive_ptr<Document> &pDocument) const; const intrusive_ptr<Document> &pDocument) const;
virtual void addToBsonObj( virtual void addToBsonObj(
BSONObjBuilder *pBuilder, string fieldName, BSONObjBuilder *pBuilder, string fieldName,
bool requireExpression) const; bool requireExpression) const;
virtual void addToBsonArray(BSONArrayBuilder *pBuilder) const; virtual void addToBsonArray(BSONArrayBuilder *pBuilder) const;
virtual void toMatcherBson(BSONObjBuilder *pBuilder) const; virtual void toMatcherBson(BSONObjBuilder *pBuilder) const;
/* /*
Create a field range expression. Create a field range expression.
skipping to change at line 754 skipping to change at line 719
const intrusive_ptr<Document> &pDocument) const; const intrusive_ptr<Document> &pDocument) const;
virtual const char *getOpName() const; virtual const char *getOpName() const;
virtual void addOperand(const intrusive_ptr<Expression> &pExpressio n); virtual void addOperand(const intrusive_ptr<Expression> &pExpressio n);
static intrusive_ptr<ExpressionNary> create(); static intrusive_ptr<ExpressionNary> create();
private: private:
ExpressionIfNull(); ExpressionIfNull();
}; };
class ExpressionIsoDate :
public ExpressionNary {
public:
// virtuals from ExpressionNary
virtual ~ExpressionIsoDate();
virtual intrusive_ptr<const Value> evaluate(
const intrusive_ptr<Document> &pDocument) const;
virtual const char *getOpName() const;
virtual void addOperand(const intrusive_ptr<Expression> &pExpressio
n);
static intrusive_ptr<ExpressionNary> create();
private:
ExpressionIsoDate();
static const char argYear[];
static const char argMonth[];
static const char argDayOfMonth[];
static const char argHour[];
static const char argMinute[];
static const char argSecond[];
static const unsigned flagYear;
static const unsigned flagMonth;
static const unsigned flagDayOfMonth;
static const unsigned flagHour;
static const unsigned flagMinute;
static const unsigned flagSecond;
unsigned flag;
/**
Get a named long argument out of the given document.
@param pArgs the evaluated document with the named arguments in
it
@param pName the name of the argument
@param defaultValue the value to return if the argument isn't fo
und
@returns the value if found, otherwise zero
@throws uassert for non-whole numbers or non-numbers
*/
int getIntArg(
const intrusive_ptr<Document> &pArgs,
const char *pName, int defaultValue) const;
/**
Check that the named argument fits in an integer.
@params pName the name of the argument
@params value the long value of the argument
@returns the integer value
@throws uassert if the value is out of range
*/
int checkIntRange(const char *pName, long long value) const;
};
class ExpressionLiteral :
public ExpressionNary {
public:
// virtuals from ExpressionNary
virtual ~ExpressionLiteral();
virtual intrusive_ptr<const Value> evaluate(
const intrusive_ptr<Document> &pDocument) const;
virtual const char *getOpName() const;
virtual void addOperand(const intrusive_ptr<Expression> &pExpressio
n);
static intrusive_ptr<ExpressionNary> create();
private:
ExpressionLiteral();
};
class ExpressionMinute : class ExpressionMinute :
public ExpressionNary { public ExpressionNary {
public: public:
// virtuals from ExpressionNary // virtuals from ExpressionNary
virtual ~ExpressionMinute(); virtual ~ExpressionMinute();
virtual intrusive_ptr<const Value> evaluate( virtual intrusive_ptr<const Value> evaluate(
const intrusive_ptr<Document> &pDocument) const; const intrusive_ptr<Document> &pDocument) const;
virtual const char *getOpName() const; virtual const char *getOpName() const;
virtual void addOperand(const intrusive_ptr<Expression> &pExpressio n); virtual void addOperand(const intrusive_ptr<Expression> &pExpressio n);
skipping to change at line 895 skipping to change at line 790
const intrusive_ptr<Document> &pDocument) const; const intrusive_ptr<Document> &pDocument) const;
virtual const char *getOpName() const; virtual const char *getOpName() const;
virtual void addOperand(const intrusive_ptr<Expression> &pExpressio n); virtual void addOperand(const intrusive_ptr<Expression> &pExpressio n);
static intrusive_ptr<ExpressionNary> create(); static intrusive_ptr<ExpressionNary> create();
private: private:
ExpressionMonth(); ExpressionMonth();
}; };
class ExpressionNoOp :
public ExpressionNary {
public:
// virtuals from ExpressionNary
virtual ~ExpressionNoOp();
virtual intrusive_ptr<Expression> optimize();
virtual intrusive_ptr<const Value> evaluate(
const intrusive_ptr<Document> &pDocument) const;
virtual const char *getOpName() const;
virtual void addOperand(const intrusive_ptr<Expression> &pExpressio
n);
static intrusive_ptr<ExpressionNary> create();
private:
ExpressionNoOp();
};
class ExpressionNot : class ExpressionNot :
public ExpressionNary { public ExpressionNary {
public: public:
// virtuals from ExpressionNary // virtuals from ExpressionNary
virtual ~ExpressionNot(); virtual ~ExpressionNot();
virtual intrusive_ptr<const Value> evaluate( virtual intrusive_ptr<const Value> evaluate(
const intrusive_ptr<Document> &pDocument) const; const intrusive_ptr<Document> &pDocument) const;
virtual const char *getOpName() const; virtual const char *getOpName() const;
virtual void addOperand(const intrusive_ptr<Expression> &pExpressio n); virtual void addOperand(const intrusive_ptr<Expression> &pExpressio n);
skipping to change at line 934 skipping to change at line 812
private: private:
ExpressionNot(); ExpressionNot();
}; };
class ExpressionObject : class ExpressionObject :
public Expression { public Expression {
public: public:
// virtuals from Expression // virtuals from Expression
virtual ~ExpressionObject(); virtual ~ExpressionObject();
virtual intrusive_ptr<Expression> optimize(); virtual intrusive_ptr<Expression> optimize();
virtual void addDependencies( virtual bool isSimple();
const intrusive_ptr<DependencyTracker> &pTracker, virtual void addDependencies(set<string>& deps, vector<string>* pat
const DocumentSource *pSource) const; h=NULL) const;
virtual intrusive_ptr<const Value> evaluate( virtual intrusive_ptr<const Value> evaluate(
const intrusive_ptr<Document> &pDocument) const; const intrusive_ptr<Document> &pDocument) const;
virtual void addToBsonObj( virtual void addToBsonObj(
BSONObjBuilder *pBuilder, string fieldName, BSONObjBuilder *pBuilder, string fieldName,
bool requireExpression) const; bool requireExpression) const;
virtual void addToBsonArray(BSONArrayBuilder *pBuilder) const; virtual void addToBsonArray(BSONArrayBuilder *pBuilder) const;
/* /*
evaluate(), but return a Document instead of a Value-wrapped evaluate(), but return a Document instead of a Value-wrapped
Document. Document.
skipping to change at line 959 skipping to change at line 836
@returns the result document @returns the result document
*/ */
intrusive_ptr<Document> evaluateDocument( intrusive_ptr<Document> evaluateDocument(
const intrusive_ptr<Document> &pDocument) const; const intrusive_ptr<Document> &pDocument) const;
/* /*
evaluate(), but add the evaluated fields to a given document evaluate(), but add the evaluated fields to a given document
instead of creating a new one. instead of creating a new one.
@param pResult the Document to add the evaluated expressions to @param pResult the Document to add the evaluated expressions to
@param pDocument the input Document @param pDocument the input Document for this level
@param excludeId for exclusions, exclude the _id, if present @param rootDoc the root of the whole input document
*/ */
void addToDocument(const intrusive_ptr<Document> &pResult, void addToDocument(const intrusive_ptr<Document>& pResult,
const intrusive_ptr<Document> &pDocument, const intrusive_ptr<Document>& pDocument,
bool excludeId = false) const; const intrusive_ptr<Document>& rootDoc
) const;
/* // estimated number of fields that will be output
Estimate the number of fields that will result from evaluating size_t getSizeHint() const;
this over pDocument. Does not include _id. This is an estimate
(really an upper bound) because we can't account for undefined
fields without actually doing the evaluation. But this is still
useful as an argument to Document::create(), if you plan to use
addToDocument().
@param pDocument the input document
@returns estimated number of fields that will result
*/
size_t getSizeHint(const intrusive_ptr<Document> &pDocument) const;
/* /*
Create an empty expression. Until fields are added, this Create an empty expression. Until fields are added, this
will evaluate to an empty document (object). will evaluate to an empty document (object).
*/ */
static intrusive_ptr<ExpressionObject> create(); static intrusive_ptr<ExpressionObject> create();
/* /*
Add a field to the document expression. Add a field to the document expression.
@param fieldPath the path the evaluated expression will have in t he @param fieldPath the path the evaluated expression will have in t he
result Document result Document
@param pExpression the expression to evaluate obtain this field's @param pExpression the expression to evaluate obtain this field's
Value in the result Document Value in the result Document
*/ */
void addField(const string &fieldPath, void addField(const FieldPath &fieldPath,
const intrusive_ptr<Expression> &pExpression); const intrusive_ptr<Expression> &pExpression);
/* /*
Add a field path to the set of those to be included. Add a field path to the set of those to be included.
Note that including a nested field implies including everything o n Note that including a nested field implies including everything o n
the path leading down to it. the path leading down to it.
@param fieldPath the name of the field to be included @param fieldPath the name of the field to be included
*/ */
void includePath(const string &fieldPath); void includePath(const string &fieldPath);
/* /*
Add a field path to the set of those to be excluded.
Note that excluding a nested field implies including everything o
n
the path leading down to it (because you're stating you want to s
ee
all the other fields that aren't being excluded).
@param fieldName the name of the field to be excluded
*/
void excludePath(const string &fieldPath);
/**
Get an iterator that can be used to iterate over all the result
field names in this ExpressionObject.
@returns the (intrusive_ptr'ed) iterator
*/
Iterator<string> *getFieldIterator() const;
/*
Return the expression for a field.
@param fieldName the field name for the expression to return
@returns the expression used to compute the field, if it is prese
nt,
otherwise NULL.
*/
intrusive_ptr<Expression> getField(const string &fieldName) const;
/*
Get a count of the added fields. Get a count of the added fields.
@returns how many fields have been added @returns how many fields have been added
*/ */
size_t getFieldCount() const; size_t getFieldCount() const;
/* /*
Get a count of the exclusions.
@returns how many fields have been excluded.
*/
size_t getExclusionCount() const;
/*
Specialized BSON conversion that allows for writing out a Specialized BSON conversion that allows for writing out a
$project specification. This creates a standalone object, which must $project specification. This creates a standalone object, which must
be added to a containing object with a name be added to a containing object with a name
@param pBuilder where to write the object to @param pBuilder where to write the object to
@param requireExpression see Expression::addToBsonObj @param requireExpression see Expression::addToBsonObj
*/ */
void documentToBson(BSONObjBuilder *pBuilder, void documentToBson(BSONObjBuilder *pBuilder,
bool requireExpression) const; bool requireExpression) const;
skipping to change at line 1077 skipping to change at line 910
/** /**
Record a path. Record a path.
@param path the dotted path string @param path the dotted path string
@param include if true, the path is included; if false, the path @param include if true, the path is included; if false, the path
is excluded is excluded
*/ */
virtual void path(const string &path, bool include) = 0; virtual void path(const string &path, bool include) = 0;
}; };
/** void excludeId(bool b) { _excludeId = b; }
Emit the field paths that have been included or excluded. "Inclu
ded"
includes paths that are referenced in expressions for computed
fields.
@param pSink where to write the paths to
@param pvPath pointer to a vector of strings describing the path
on
descent; the top-level call should pass an empty vector
*/
void emitPaths(PathSink *pPathSink) const;
private: private:
ExpressionObject(); ExpressionObject();
void includePath( // mapping from fieldname to Expression to generate the value
const FieldPath *pPath, size_t pathi, size_t pathn, // NULL expression means include from source document
bool excludeLast); typedef map<string, intrusive_ptr<Expression> > ExpressionMap;
ExpressionMap _expressions;
bool excludePaths;
set<string> path;
/* these two vectors are maintained in parallel */
vector<string> vFieldName;
vector<intrusive_ptr<Expression> > vpExpression;
/* // this is used to maintain order for generated fields not in the s
Utility function used by documentToBson(). Emits inclusion ource document
and exclusion paths by recursively walking down the nested vector<string> _order;
ExpressionObject trees these have created.
@param pSink where to write the paths to bool _excludeId;
@param pvPath pointer to a vector of strings describing the path
on
descent; the top-level call should pass an empty vector
*/
void emitPaths(PathSink *pPathSink, vector<string> *pvPath) const;
/* /*
Utility object for collecting emitPaths() results in a BSON Utility object for collecting emitPaths() results in a BSON
object. object.
*/ */
class BuilderPathSink : class BuilderPathSink :
public PathSink { public PathSink {
public: public:
// virtuals from PathSink // virtuals from PathSink
virtual void path(const string &path, bool include); virtual void path(const string &path, bool include);
skipping to change at line 1313 skipping to change at line 1125
private: private:
ExpressionYear(); ExpressionYear();
}; };
} }
/* ======================= INLINED IMPLEMENTATIONS ======================== == */ /* ======================= INLINED IMPLEMENTATIONS ======================== == */
namespace mongo { namespace mongo {
inline bool Expression::ObjectCtx::unwindOk() const {
return ((options & UNWIND_OK) != 0);
}
inline bool Expression::ObjectCtx::unwindUsed() const {
return (unwindField.size() != 0);
}
inline int Expression::signum(int i) { inline int Expression::signum(int i) {
if (i < 0) if (i < 0)
return -1; return -1;
if (i > 0) if (i > 0)
return 1; return 1;
return 0; return 0;
} }
inline intrusive_ptr<const Value> ExpressionConstant::getValue() const { inline intrusive_ptr<const Value> ExpressionConstant::getValue() const {
return pValue; return pValue;
skipping to change at line 1343 skipping to change at line 1147
inline string ExpressionFieldPath::getFieldPath(bool fieldPrefix) const { inline string ExpressionFieldPath::getFieldPath(bool fieldPrefix) const {
return fieldPath.getPath(fieldPrefix); return fieldPath.getPath(fieldPrefix);
} }
inline void ExpressionFieldPath::writeFieldPath( inline void ExpressionFieldPath::writeFieldPath(
ostream &outStream, bool fieldPrefix) const { ostream &outStream, bool fieldPrefix) const {
return fieldPath.writePath(outStream, fieldPrefix); return fieldPath.writePath(outStream, fieldPrefix);
} }
inline size_t ExpressionObject::getFieldCount() const { inline size_t ExpressionObject::getFieldCount() const {
return vFieldName.size(); return _expressions.size();
} }
inline ExpressionObject::BuilderPathSink::BuilderPathSink( inline ExpressionObject::BuilderPathSink::BuilderPathSink(
BSONObjBuilder *pB): BSONObjBuilder *pB):
pBuilder(pB) { pBuilder(pB) {
} }
inline ExpressionObject::PathPusher::PathPusher( inline ExpressionObject::PathPusher::PathPusher(
vector<string> *pTheVPath, const string &s): vector<string> *pTheVPath, const string &s):
pvPath(pTheVPath) { pvPath(pTheVPath) {
 End of changes. 34 change blocks. 
255 lines changed or deleted 55 lines changed or added


 expression_context.h   expression_context.h 
skipping to change at line 19 skipping to change at line 19
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details. * GNU Affero General Public License for more details.
* *
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#pragma once #pragma once
#include "pch.h" #include "mongo/pch.h"
#include "util/intrusive_counter.h" #include "util/intrusive_counter.h"
namespace mongo { namespace mongo {
class InterruptStatus; class InterruptStatus;
class ExpressionContext : class ExpressionContext :
public IntrusiveCounterUnsigned { public IntrusiveCounterUnsigned {
public: public:
virtual ~ExpressionContext(); virtual ~ExpressionContext();
void setDoingMerge(bool b);
void setInShard(bool b); void setInShard(bool b);
void setInRouter(bool b); void setInRouter(bool b);
bool getDoingMerge() const;
bool getInShard() const; bool getInShard() const;
bool getInRouter() const; bool getInRouter() const;
/** /**
Used by a pipeline to check for interrupts so that killOp() work s. Used by a pipeline to check for interrupts so that killOp() work s.
@throws if the operation has been interrupted @throws if the operation has been interrupted
*/ */
void checkForInterrupt(); void checkForInterrupt();
ExpressionContext* clone();
static ExpressionContext *create(InterruptStatus *pStatus); static ExpressionContext *create(InterruptStatus *pStatus);
private: private:
ExpressionContext(InterruptStatus *pStatus); ExpressionContext(InterruptStatus *pStatus);
bool doingMerge;
bool inShard; bool inShard;
bool inRouter; bool inRouter;
unsigned intCheckCounter; // interrupt check counter unsigned intCheckCounter; // interrupt check counter
InterruptStatus *const pStatus; InterruptStatus *const pStatus;
}; };
} }
/* ======================= INLINED IMPLEMENTATIONS ======================== == */ /* ======================= INLINED IMPLEMENTATIONS ======================== == */
namespace mongo { namespace mongo {
inline void ExpressionContext::setDoingMerge(bool b) {
doingMerge = b;
}
inline void ExpressionContext::setInShard(bool b) { inline void ExpressionContext::setInShard(bool b) {
inShard = b; inShard = b;
} }
inline void ExpressionContext::setInRouter(bool b) { inline void ExpressionContext::setInRouter(bool b) {
inRouter = b; inRouter = b;
} }
inline bool ExpressionContext::getDoingMerge() const {
return doingMerge;
}
inline bool ExpressionContext::getInShard() const { inline bool ExpressionContext::getInShard() const {
return inShard; return inShard;
} }
inline bool ExpressionContext::getInRouter() const { inline bool ExpressionContext::getInRouter() const {
return inRouter; return inRouter;
} }
}; };
 End of changes. 7 change blocks. 
1 lines changed or deleted 14 lines changed or added


 extsort.h   extsort.h 
skipping to change at line 21 skipping to change at line 21
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details. * GNU Affero General Public License for more details.
* *
* You should have received a copy of the GNU Affero General Public Licen se * You should have received a copy of the GNU Affero General Public Licen se
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#pragma once #pragma once
#include "pch.h" #include "mongo/pch.h"
#include "mongo/db/index.h" #include "mongo/db/index.h"
#include "mongo/db/jsobj.h" #include "mongo/db/jsobj.h"
#include "mongo/db/namespace-inl.h" #include "mongo/db/namespace-inl.h"
#include "mongo/db/curop-inl.h" #include "mongo/db/curop-inl.h"
#include "mongo/util/array.h" #include "mongo/util/array.h"
#include "mongo/util/mmap.h"
namespace mongo { namespace mongo {
/** /**
for external (disk) sorting by BSONObj and attaching a value for external (disk) sorting by BSONObj and attaching a value
*/ */
class BSONObjExternalSorter : boost::noncopyable { class BSONObjExternalSorter : boost::noncopyable {
public: public:
BSONObjExternalSorter( IndexInterface &i, const BSONObj & order = B SONObj() , long maxFileSize = 1024 * 1024 * 100 ); BSONObjExternalSorter( IndexInterface &i, const BSONObj & order = B SONObj() , long maxFileSize = 1024 * 1024 * 100 );
~BSONObjExternalSorter(); ~BSONObjExternalSorter();
typedef pair<BSONObj,DiskLoc> Data; typedef pair<BSONObj,DiskLoc> Data;
/** @return the IndexInterface used to perform key comparisons. */
const IndexInterface& getIndexInterface() const { return _idxi; }
private: private:
static HLMutex _extSortMutex; static HLMutex _extSortMutex;
IndexInterface& _idxi; IndexInterface& _idxi;
static int _compare(IndexInterface& i, const Data& l, const Data& r , const Ordering& order); static int _compare(IndexInterface& i, const Data& l, const Data& r , const Ordering& order);
class MyCmp { class MyCmp {
public: public:
MyCmp( IndexInterface& i, BSONObj order = BSONObj() ) : _i(i), _order( Ordering::make(order) ) {} MyCmp( IndexInterface& i, BSONObj order = BSONObj() ) : _i(i), _order( Ordering::make(order) ) {}
skipping to change at line 69 skipping to change at line 70
static Ordering extSortOrder; static Ordering extSortOrder;
static int extSortComp( const void *lv, const void *rv ); static int extSortComp( const void *lv, const void *rv );
class FileIterator : boost::noncopyable { class FileIterator : boost::noncopyable {
public: public:
FileIterator( string file ); FileIterator( string file );
~FileIterator(); ~FileIterator();
bool more(); bool more();
Data next(); Data next();
private: private:
MemoryMappedFile _file; bool _read( char* buf, long long count );
char * _buf;
char * _end; int _file;
unsigned long long _length;
unsigned long long _readSoFar;
}; };
public: public:
typedef FastArray<Data> InMemory; typedef FastArray<Data> InMemory;
class Iterator : boost::noncopyable { class Iterator : boost::noncopyable {
public: public:
Iterator( BSONObjExternalSorter * sorter ); Iterator( BSONObjExternalSorter * sorter );
 End of changes. 4 change blocks. 
5 lines changed or deleted 8 lines changed or added


 field_path.h   field_path.h 
skipping to change at line 19 skipping to change at line 19
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details. * GNU Affero General Public License for more details.
* *
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#pragma once #pragma once
#include "pch.h" #include "mongo/pch.h"
namespace mongo { namespace mongo {
class FieldPath { class FieldPath {
public: public:
virtual ~FieldPath();
/** /**
Constructor. * Constructor.
*
@param fieldPath the dotted field path string * @param fieldPath the dotted field path string or non empty pre-s
plit vector.
* The constructed object will have getPathLength() > 0.
* Uassert if any component field names do not pass validation.
*/ */
FieldPath(const string &fieldPath); FieldPath(const string& fieldPath);
FieldPath(const vector<string>& fieldPath);
/**
Constructor.
*/
FieldPath();
/** /**
Get the number of path elements in the field path. Get the number of path elements in the field path.
@returns the number of path elements @returns the number of path elements
*/ */
size_t getPathLength() const; size_t getPathLength() const;
/** /**
Get a particular path element from the path. Get a particular path element from the path.
@param i the index of the path element @param i the zero based index of the path element.
@returns the path element @returns the path element
*/ */
string getFieldName(size_t i) const; string getFieldName(size_t i) const;
/** /**
Get the full path. Get the full path.
@param fieldPrefix whether or not to include the field prefix @param fieldPrefix whether or not to include the field prefix
@returns the complete field path @returns the complete field path
*/ */
skipping to change at line 71 skipping to change at line 68
/** /**
Write the full path. Write the full path.
@param outStream where to write the path to @param outStream where to write the path to
@param fieldPrefix whether or not to include the field prefix @param fieldPrefix whether or not to include the field prefix
*/ */
void writePath(ostream &outStream, bool fieldPrefix) const; void writePath(ostream &outStream, bool fieldPrefix) const;
/** /**
Assignment operator.
@param rRHS right hand side of the assignment
*/
FieldPath &operator=(const FieldPath &rRHS);
/**
Get the prefix string. Get the prefix string.
@returns the prefix string @returns the prefix string
*/ */
static const char *getPrefix(); static const char *getPrefix();
static const char prefix[]; static const char prefix[];
/**
* A FieldPath like this but missing the first element (useful for
recursion).
* Precondition getPathLength() > 1.
*/
FieldPath tail() const;
private: private:
/** Uassert if a field name does not pass validation. */
static void uassertValidFieldName(const string& fieldName);
/**
* Push a new field name to the back of the vector of names compris
ing the field path.
* Uassert if 'fieldName' does not pass validation.
*/
void pushFieldName(const string& fieldName);
vector<string> vFieldName; vector<string> vFieldName;
}; };
} }
/* ======================= INLINED IMPLEMENTATIONS ======================== == */ /* ======================= INLINED IMPLEMENTATIONS ======================== == */
namespace mongo { namespace mongo {
inline size_t FieldPath::getPathLength() const { inline size_t FieldPath::getPathLength() const {
return vFieldName.size(); return vFieldName.size();
} }
inline string FieldPath::getFieldName(size_t i) const { inline string FieldPath::getFieldName(size_t i) const {
verify(i < getPathLength());
return vFieldName[i]; return vFieldName[i];
} }
inline const char *FieldPath::getPrefix() { inline const char *FieldPath::getPrefix() {
return prefix; return prefix;
} }
} }
 End of changes. 9 change blocks. 
19 lines changed or deleted 28 lines changed or added


 file_allocator.h   file_allocator.h 
skipping to change at line 18 skipping to change at line 18
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or impli ed. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or impli ed.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include "pch.h" #include "mongo/pch.h"
#include <list> #include <list>
#include <boost/filesystem/path.hpp> #include <boost/filesystem/path.hpp>
#include <boost/thread/condition.hpp> #include <boost/thread/condition.hpp>
namespace mongo { namespace mongo {
/* /*
* Handles allocation of contiguous files on disk. Allocation may be * Handles allocation of contiguous files on disk. Allocation may be
* requested asynchronously or synchronously. * requested asynchronously or synchronously.
 End of changes. 1 change blocks. 
1 lines changed or deleted 1 lines changed or added


 gridfs.h   gridfs.h 
skipping to change at line 53 skipping to change at line 53
return _data["data"].binDataClean( len ); return _data["data"].binDataClean( len );
} }
private: private:
BSONObj _data; BSONObj _data;
friend class GridFS; friend class GridFS;
}; };
/** /**
GridFS is for storing large file-style objects in MongoDB. GridFS is for storing large file-style objects in MongoDB.
@see http://www.mongodb.org/display/DOCS/GridFS+Specification @see http://dochub.mongodb.org/core/gridfsspec
*/ */
class GridFS { class GridFS {
public: public:
/** /**
* @param client - db connection * @param client - db connection
* @param dbName - root database name * @param dbName - root database name
* @param prefix - if you want your data somewhere besides <dbname> .fs * @param prefix - if you want your data somewhere besides <dbname> .fs
*/ */
GridFS( DBClientBase& client , const string& dbName , const string& prefix="fs" ); GridFS( DBClientBase& client , const string& dbName , const string& prefix="fs" );
~GridFS(); ~GridFS();
 End of changes. 1 change blocks. 
1 lines changed or deleted 1 lines changed or added


 hasher.h   hasher.h 
skipping to change at line 24 skipping to change at line 24
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details. * GNU Affero General Public License for more details.
* *
* You should have received a copy of the GNU Affero General Public Licen se * You should have received a copy of the GNU Affero General Public Licen se
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#pragma once #pragma once
#include "pch.h" #include "mongo/pch.h"
#include "mongo/bson/bsonelement.h" #include "mongo/bson/bsonelement.h"
#include "mongo/util/md5.hpp" #include "mongo/util/md5.hpp"
namespace mongo { namespace mongo {
typedef int HashSeed; typedef int HashSeed;
typedef unsigned char HashDigest[16]; typedef unsigned char HashDigest[16];
class Hasher : private boost::noncopyable { class Hasher : private boost::noncopyable {
public: public:
 End of changes. 1 change blocks. 
1 lines changed or deleted 1 lines changed or added


 hashtab.h   hashtab.h 
skipping to change at line 25 skipping to change at line 25
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or impli ed. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or impli ed.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#pragma once #pragma once
#include "../pch.h" #include "mongo/pch.h"
#include <map> #include <map>
#include "../db/dur.h" #include "../db/dur.h"
namespace mongo { namespace mongo {
#pragma pack(1) #pragma pack(1)
/* you should define: /* you should define:
int Key::hash() return > 0 always. int Key::hash() return > 0 always.
 End of changes. 1 change blocks. 
1 lines changed or deleted 1 lines changed or added


 health.h   health.h 
skipping to change at line 35 skipping to change at line 35
struct HealthOptions { struct HealthOptions {
HealthOptions() : HealthOptions() :
heartbeatSleepMillis(2000), heartbeatSleepMillis(2000),
heartbeatTimeoutMillis( 10000 ), heartbeatTimeoutMillis( 10000 ),
heartbeatConnRetries(2) heartbeatConnRetries(2)
{ } { }
bool isDefault() const { return *this == HealthOptions(); } bool isDefault() const { return *this == HealthOptions(); }
// see http://www.mongodb.org/display/DOCS/Replica+Set+Internals // see http://dochub.mongodb.org/core/replicasetinternals
unsigned heartbeatSleepMillis; unsigned heartbeatSleepMillis;
unsigned heartbeatTimeoutMillis; unsigned heartbeatTimeoutMillis;
unsigned heartbeatConnRetries ; unsigned heartbeatConnRetries ;
void check() { void check() {
uassert(13112, "bad replset heartbeat option", heartbeatSleepMi llis >= 10); uassert(13112, "bad replset heartbeat option", heartbeatSleepMi llis >= 10);
uassert(13113, "bad replset heartbeat option", heartbeatTimeout Millis >= 10); uassert(13113, "bad replset heartbeat option", heartbeatTimeout Millis >= 10);
} }
bool operator==(const HealthOptions& r) const { bool operator==(const HealthOptions& r) const {
 End of changes. 1 change blocks. 
1 lines changed or deleted 1 lines changed or added


 hostandport.h   hostandport.h 
skipping to change at line 28 skipping to change at line 28
#pragma once #pragma once
#include "sock.h" #include "sock.h"
#include "../../db/cmdline.h" #include "../../db/cmdline.h"
#include "../mongoutils/str.h" #include "../mongoutils/str.h"
namespace mongo { namespace mongo {
using namespace mongoutils; using namespace mongoutils;
void dynHostResolve(string& name, int& port);
string dynHostMyName();
/** helper for manipulating host:port connection endpoints. /** helper for manipulating host:port connection endpoints.
*/ */
struct HostAndPort { struct HostAndPort {
HostAndPort() : _port(-1) { } HostAndPort() : _port(-1) { }
/** From a string hostname[:portnumber] or a #dynname /** From a string hostname[:portnumber]
Throws user assertion if bad config string or bad port #. Throws user assertion if bad config string or bad port #.
*/ */
HostAndPort(string s); HostAndPort(string s);
/** @param p port number. -1 is ok to use default. */ /** @param p port number. -1 is ok to use default. */
HostAndPort(string h, int p /*= -1*/) : _host(h), _port(p) { HostAndPort(string h, int p /*= -1*/) : _host(h), _port(p) {
verify( !str::startsWith(h, '#') ); verify( !str::startsWith(h, '#') );
} }
HostAndPort(const SockAddr& sock ) : _host( sock.getAddr() ) , _por t( sock.getPort() ) { } HostAndPort(const SockAddr& sock ) : _host( sock.getAddr() ) , _por t( sock.getPort() ) { }
skipping to change at line 76 skipping to change at line 73
/* returns true if the host/port combo identifies this process inst ance. */ /* returns true if the host/port combo identifies this process inst ance. */
bool isSelf() const; // defined in isself.cpp bool isSelf() const; // defined in isself.cpp
bool isLocalHost() const; bool isLocalHost() const;
/** /**
* @param includePort host:port if true, host otherwise * @param includePort host:port if true, host otherwise
*/ */
string toString( bool includePort=true ) const; string toString( bool includePort=true ) const;
// get the logical name if using a #dynhostname instead of resolvin
g to current actual name
string dynString() const;
string toStringLong() const;
operator string() const { return toString(); } operator string() const { return toString(); }
bool empty() const { bool empty() const {
return _dynName.empty() && _host.empty() && _port < 0; return _host.empty() && _port < 0;
} }
string host() const { string host() const {
if( !dyn() ) return _host;
return _host;
string h = _dynName;
int p;
dynHostResolve(h, p);
return h;
} }
int port() const { int port() const {
int p = -2; if (hasPort())
if( dyn() ) { return _port;
string h = _dynName; return CmdLine::DefaultDBPort;
dynHostResolve(h,p);
}
else {
p = _port;
}
return p >= 0 ? p : CmdLine::DefaultDBPort;
} }
bool hasPort() const { bool hasPort() const {
int p = -2; return _port >= 0;
if( dyn() ) {
string h = _dynName;
dynHostResolve(h,p);
}
else {
p = _port;
}
return p >= 0;
} }
void setPort( int port ) { void setPort( int port ) {
if( dyn() ) {
log() << "INFO skipping setPort() HostAndPort dyn()=true" <
< endl;
return;
}
_port = port; _port = port;
} }
private: private:
bool dyn() const { return !_dynName.empty(); }
void init(const char *); void init(const char *);
// invariant (except full obj assignment):
string _dynName; // when this is set, _host and _port aren't used,
rather, we look up the dyn info every time.
string _host; string _host;
int _port; // -1 indicates unspecified int _port; // -1 indicates unspecified
}; };
inline HostAndPort HostAndPort::me() { inline HostAndPort HostAndPort::me() {
{
string s = dynHostMyName();
if( !s.empty() )
return HostAndPort(s);
}
const char* ips = cmdLine.bind_ip.c_str(); const char* ips = cmdLine.bind_ip.c_str();
while(*ips) { while(*ips) {
string ip; string ip;
const char * comma = strchr(ips, ','); const char * comma = strchr(ips, ',');
if (comma) { if (comma) {
ip = string(ips, comma - ips); ip = string(ips, comma - ips);
ips = comma + 1; ips = comma + 1;
} }
else { else {
ip = string(ips); ip = string(ips);
skipping to change at line 163 skipping to change at line 124
return h; return h;
} }
} }
string h = getHostName(); string h = getHostName();
verify( !h.empty() ); verify( !h.empty() );
verify( h != "localhost" ); verify( h != "localhost" );
return HostAndPort(h, cmdLine.port); return HostAndPort(h, cmdLine.port);
} }
inline string HostAndPort::dynString() const {
return dyn() ? _dynName : toString();
}
inline string HostAndPort::toStringLong() const {
return _dynName + ':' + toString();
}
inline string HostAndPort::toString( bool includePort ) const { inline string HostAndPort::toString( bool includePort ) const {
string h = host(); string h = host();
int p = port(); int p = port();
if ( ! includePort ) if ( ! includePort )
return h; return h;
stringstream ss; stringstream ss;
ss << h; ss << h;
if ( p != -1 ) { if ( p != -1 ) {
skipping to change at line 208 skipping to change at line 161
return ( _host == "localhost" return ( _host == "localhost"
|| startsWith(_host.c_str(), "127.") || startsWith(_host.c_str(), "127.")
|| _host == "::1" || _host == "::1"
|| _host == "anonymous unix socket" || _host == "anonymous unix socket"
|| _host.c_str()[0] == '/' // unix socket || _host.c_str()[0] == '/' // unix socket
); );
} }
inline void HostAndPort::init(const char *p) { inline void HostAndPort::init(const char *p) {
massert(13110, "HostAndPort: host is empty", *p); massert(13110, "HostAndPort: host is empty", *p);
verify( *p != '#' );
verify( _dynName.empty() );
const char *colon = strrchr(p, ':'); const char *colon = strrchr(p, ':');
if( colon ) { if( colon ) {
int port = atoi(colon+1); int port = atoi(colon+1);
uassert(13095, "HostAndPort: bad port #", port > 0); uassert(13095, "HostAndPort: bad port #", port > 0);
_host = string(p,colon-p); _host = string(p,colon-p);
_port = port; _port = port;
} }
else { else {
// no port specified. // no port specified.
_host = p; _host = p;
_port = -1; _port = -1;
} }
} }
inline HostAndPort::HostAndPort(string s) { inline HostAndPort::HostAndPort(string s) {
const char *p = s.c_str(); init(s.c_str());
if( *p == '#' ) {
_dynName = s;
_port = -2;
_host = "invalid_hostname_dyn_in_use";
}
else {
init(p);
}
} }
} }
 End of changes. 14 change blocks. 
68 lines changed or deleted 8 lines changed or added


 html.h   html.h 
skipping to change at line 156 skipping to change at line 156
ss << "<a"; ss << "<a";
if( !href.empty() ) ss << " href=\"" << href << '"'; if( !href.empty() ) ss << " href=\"" << href << '"';
if( !title.empty() ) ss << " title=\"" << title << '"'; if( !title.empty() ) ss << " title=\"" << title << '"';
ss << '>'; ss << '>';
if( !contentHtml.empty() ) { if( !contentHtml.empty() ) {
ss << contentHtml << "</a>"; ss << contentHtml << "</a>";
} }
return ss.str(); return ss.str();
} }
/* escape for HTML display */
inline string escape(const string& data) {
string buffer;
buffer.reserve( data.size() );
for( size_t pos = 0; pos != data.size(); ++pos ) {
switch( data[pos] ) {
case '&':
buffer.append( "&amp;" );
break;
case '\"':
buffer.append( "&quot;" );
break;
case '\'':
buffer.append( "&apos;" );
break;
case '<':
buffer.append( "&lt;" );
break;
case '>':
buffer.append( "&gt;" );
break;
default:
buffer.append( 1, data[pos] );
break;
}
}
return buffer;
}
} }
} }
 End of changes. 1 change blocks. 
0 lines changed or deleted 29 lines changed or added


 httpclient.h   httpclient.h 
skipping to change at line 20 skipping to change at line 20
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or impli ed. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or impli ed.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#pragma once #pragma once
#include "../../pch.h" #include "mongo/pch.h"
#include "sock.h" #include "sock.h"
namespace mongo { namespace mongo {
class HttpClient : boost::noncopyable { class HttpClient : boost::noncopyable {
public: public:
typedef map<string,string> Headers; typedef map<string,string> Headers;
class Result { class Result {
 End of changes. 1 change blocks. 
1 lines changed or deleted 1 lines changed or added


 index.h   index.h 
skipping to change at line 21 skipping to change at line 21
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details. * GNU Affero General Public License for more details.
* *
* You should have received a copy of the GNU Affero General Public Licen se * You should have received a copy of the GNU Affero General Public Licen se
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#pragma once #pragma once
#include "pch.h" #include "mongo/pch.h"
#include <vector> #include <vector>
#include "mongo/db/diskloc.h" #include "mongo/db/diskloc.h"
#include "mongo/db/index_insertion_continuation.h" #include "mongo/db/index_insertion_continuation.h"
#include "mongo/db/indexkey.h" #include "mongo/db/indexkey.h"
#include "mongo/db/jsobj.h" #include "mongo/db/jsobj.h"
#include "mongo/db/key.h" #include "mongo/db/key.h"
#include "mongo/db/namespace.h" #include "mongo/db/namespace.h"
skipping to change at line 73 skipping to change at line 73
virtual void uassertIfDups(IndexDetails& idx, vector<BSONObj*>& add edKeys, DiskLoc head, virtual void uassertIfDups(IndexDetails& idx, vector<BSONObj*>& add edKeys, DiskLoc head,
DiskLoc self, const Ordering& ordering) = 0; DiskLoc self, const Ordering& ordering) = 0;
// these are for geo // these are for geo
virtual bool isUsed(DiskLoc thisLoc, int pos) = 0; virtual bool isUsed(DiskLoc thisLoc, int pos) = 0;
virtual void keyAt(DiskLoc thisLoc, int pos, BSONObj&, DiskLoc& rec ordLoc) = 0; virtual void keyAt(DiskLoc thisLoc, int pos, BSONObj&, DiskLoc& rec ordLoc) = 0;
virtual BSONObj keyAt(DiskLoc thisLoc, int pos) = 0; virtual BSONObj keyAt(DiskLoc thisLoc, int pos) = 0;
virtual DiskLoc locate(const IndexDetails &idx , const DiskLoc& thi sLoc, const BSONObj& key, const Ordering &order, virtual DiskLoc locate(const IndexDetails &idx , const DiskLoc& thi sLoc, const BSONObj& key, const Ordering &order,
int& pos, bool& found, const DiskLoc &record Loc, int direction=1) = 0; int& pos, bool& found, const DiskLoc &record Loc, int direction=1) = 0;
virtual DiskLoc advance(const DiskLoc& thisLoc, int& keyOfs, int di rection, const char *caller) = 0; virtual DiskLoc advance(const DiskLoc& thisLoc, int& keyOfs, int di rection, const char *caller) = 0;
/**
* @return a static IndexInterface consistent with index version De
faultIndexVersionNumber.
* An IndexInterface should generally not be retrieved via this fun
ction, but from the
* IndexDetails for an existing index.
*/
static IndexInterface& defaultVersion();
}; };
/* Details about a particular index. There is one of these effectively for each object in /* Details about a particular index. There is one of these effectively for each object in
system.namespaces (although this also includes the head pointer, whi ch is not in that system.namespaces (although this also includes the head pointer, whi ch is not in that
collection). collection).
** MemoryMapped Record ** (i.e., this is on disk data) ** MemoryMapped Record ** (i.e., this is on disk data)
*/ */
class IndexDetails { class IndexDetails {
public: public:
 End of changes. 2 change blocks. 
1 lines changed or deleted 10 lines changed or added


 index_update.h   index_update.h 
skipping to change at line 46 skipping to change at line 46
// done in two steps/phases to allow potential deferal of write lock po rtion in the future // done in two steps/phases to allow potential deferal of write lock po rtion in the future
void indexRecordUsingTwoSteps(const char *ns, NamespaceDetails *d, BSON Obj obj, void indexRecordUsingTwoSteps(const char *ns, NamespaceDetails *d, BSON Obj obj,
DiskLoc loc, bool shouldBeUnlocked ); DiskLoc loc, bool shouldBeUnlocked );
// Given an object, populate "inserter" with information necessary to u pdate indexes. // Given an object, populate "inserter" with information necessary to u pdate indexes.
void fetchIndexInserters(BSONObjSet & /*out*/keys, void fetchIndexInserters(BSONObjSet & /*out*/keys,
IndexInterface::IndexInserter &inserter, IndexInterface::IndexInserter &inserter,
NamespaceDetails *d, NamespaceDetails *d,
int idxNo, int idxNo,
const BSONObj& obj, const BSONObj& obj,
DiskLoc recordLoc); DiskLoc recordLoc,
const bool allowDups = false);
bool dropIndexes( NamespaceDetails *d, const char *ns, const char *name , string &errmsg, BSONObjBuilder &anObjBuilder, bool maydeleteIdIndex ); bool dropIndexes( NamespaceDetails *d, const char *ns, const char *name , string &errmsg, BSONObjBuilder &anObjBuilder, bool maydeleteIdIndex );
} }
 End of changes. 1 change blocks. 
1 lines changed or deleted 2 lines changed or added


 indexkey.h   indexkey.h 
skipping to change at line 21 skipping to change at line 21
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details. * GNU Affero General Public License for more details.
* *
* You should have received a copy of the GNU Affero General Public Licen se * You should have received a copy of the GNU Affero General Public Licen se
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#pragma once #pragma once
#include "../pch.h" #include "mongo/pch.h"
#include "diskloc.h" #include "diskloc.h"
#include "jsobj.h" #include "jsobj.h"
#include <map> #include <map>
namespace mongo { namespace mongo {
extern const int DefaultIndexVersionNumber; extern const int DefaultIndexVersionNumber;
const int ParallelArraysCode = 10088; const int ParallelArraysCode = 10088;
 End of changes. 1 change blocks. 
1 lines changed or deleted 1 lines changed or added


 interrupt_status.h   interrupt_status.h 
skipping to change at line 19 skipping to change at line 19
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details. * GNU Affero General Public License for more details.
* *
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#pragma once #pragma once
#include "pch.h" #include "mongo/pch.h"
namespace mongo { namespace mongo {
/** /**
Abstraction for checking on interrupt status. Abstraction for checking on interrupt status.
The killCurrentOp object (currently declared in curop.h, and defined The killCurrentOp object (currently declared in curop.h, and defined
in instance.cpp) can only be referenced within mongod. This abstrac tion in instance.cpp) can only be referenced within mongod. This abstrac tion
serves to isolate that so that code that runs in both mongod and mon gos serves to isolate that so that code that runs in both mongod and mon gos
can be linked without unresolved symbols. There is a concrete can be linked without unresolved symbols. There is a concrete
 End of changes. 1 change blocks. 
1 lines changed or deleted 1 lines changed or added


 interrupt_status_mongod.h   interrupt_status_mongod.h 
skipping to change at line 19 skipping to change at line 19
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details. * GNU Affero General Public License for more details.
* *
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#pragma once #pragma once
#include "pch.h" #include "mongo/pch.h"
#include "db/interrupt_status.h" #include "db/interrupt_status.h"
namespace mongo { namespace mongo {
class InterruptStatusMongod : class InterruptStatusMongod :
public InterruptStatus, public InterruptStatus,
boost::noncopyable { boost::noncopyable {
public: public:
// virtuals from InterruptStatus // virtuals from InterruptStatus
virtual void checkForInterrupt(); virtual void checkForInterrupt();
 End of changes. 1 change blocks. 
1 lines changed or deleted 1 lines changed or added


 interrupt_status_mongos.h   interrupt_status_mongos.h 
skipping to change at line 19 skipping to change at line 19
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details. * GNU Affero General Public License for more details.
* *
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#pragma once #pragma once
#include "pch.h" #include "mongo/pch.h"
#include "db/interrupt_status.h" #include "db/interrupt_status.h"
namespace mongo { namespace mongo {
class InterruptStatusMongos : class InterruptStatusMongos :
public InterruptStatus, public InterruptStatus,
boost::noncopyable { boost::noncopyable {
public: public:
// virtuals from InterruptStatus // virtuals from InterruptStatus
virtual void checkForInterrupt(); virtual void checkForInterrupt();
 End of changes. 1 change blocks. 
1 lines changed or deleted 1 lines changed or added


 introspect.h   introspect.h 
skipping to change at line 22 skipping to change at line 22
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details. * GNU Affero General Public License for more details.
* *
* You should have received a copy of the GNU Affero General Public Licen se * You should have received a copy of the GNU Affero General Public Licen se
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#pragma once #pragma once
#include "../pch.h" #include "mongo/pch.h"
#include "jsobj.h" #include "jsobj.h"
#include "pdfile.h" #include "pdfile.h"
namespace mongo { namespace mongo {
/* --- profiling -------------------------------------------- /* --- profiling --------------------------------------------
do when database->profile is set do when database->profile is set
*/ */
void profile( const Client& c , CurOp& currentOp ); void profile( const Client& c , CurOp& currentOp );
/**
* Get (or create) the profile collection
*
* @param db Database in which to create the profile collection
* @param force Always create the collection if it does not exist
* @return NamespaceDetails for the newly created collection, or NULL
on error
**/
NamespaceDetails* getOrCreateProfileCollection(Database *db, bool force
= false);
} // namespace mongo } // namespace mongo
 End of changes. 2 change blocks. 
1 lines changed or deleted 12 lines changed or added


 jsobj.h   jsobj.h 
skipping to change at line 31 skipping to change at line 31
BSONObj and its helpers BSONObj and its helpers
"BSON" stands for "binary JSON" -- ie a binary way to represent objects that would be "BSON" stands for "binary JSON" -- ie a binary way to represent objects that would be
represented in JSON (plus a few extensions useful for databases & other languages). represented in JSON (plus a few extensions useful for databases & other languages).
http://www.bsonspec.org/ http://www.bsonspec.org/
*/ */
#pragma once #pragma once
#include "../pch.h" #include "mongo/pch.h"
#include "../bson/util/builder.h" #include "../bson/util/builder.h"
#include "../util/optime.h" #include "../util/optime.h"
#include "../bson/bsontypes.h" #include "../bson/bsontypes.h"
#include "../bson/oid.h" #include "../bson/oid.h"
#include "../bson/bsonelement.h" #include "../bson/bsonelement.h"
#include "../bson/bsonobj.h" #include "../bson/bsonobj.h"
#include "../bson/bsonmisc.h" #include "../bson/bsonmisc.h"
#include "../bson/bsonobjbuilder.h" #include "../bson/bsonobjbuilder.h"
#include "../bson/bsonobjiterator.h" #include "../bson/bsonobjiterator.h"
#include "../bson/bson-inl.h" #include "../bson/bson-inl.h"
 End of changes. 1 change blocks. 
1 lines changed or deleted 1 lines changed or added


 listen.h   listen.h 
skipping to change at line 130 skipping to change at line 130
long long now = Listener::getElapsedTimeMillis(); long long now = Listener::getElapsedTimeMillis();
if ( now - _last > _ms ) { if ( now - _last > _ms ) {
_last = now; _last = now;
return true; return true;
} }
return false; return false;
} }
void resetLastTime() {
_last = Listener::getElapsedTimeMillis();
}
private: private:
const int _h; const int _h;
const int _ms; const int _ms;
unsigned long long _pings; unsigned long long _pings;
long long _last; long long _last;
}; };
 End of changes. 1 change blocks. 
0 lines changed or deleted 4 lines changed or added


 lockstat.h   lockstat.h 
skipping to change at line 34 skipping to change at line 34
namespace mongo { namespace mongo {
class BSONObj; class BSONObj;
class LockStat { class LockStat {
enum { N = 4 }; enum { N = 4 };
public: public:
void recordAcquireTimeMicros( char type , long long micros ); void recordAcquireTimeMicros( char type , long long micros );
void recordLockTimeMicros( char type , long long micros ); void recordLockTimeMicros( char type , long long micros );
void reset();
BSONObj report() const; BSONObj report() const;
void report( StringBuilder& builder ) const; void report( StringBuilder& builder ) const;
long long getTimeLocked( char type ) const { return timeLocked[mapN o(type)].load(); } long long getTimeLocked( char type ) const { return timeLocked[mapN o(type)].load(); }
private: private:
static void _append( BSONObjBuilder& builder, const AtomicInt64* da ta ); static void _append( BSONObjBuilder& builder, const AtomicInt64* da ta );
// RWrw // RWrw
// in micros // in micros
AtomicInt64 timeAcquiring[N]; AtomicInt64 timeAcquiring[N];
 End of changes. 1 change blocks. 
0 lines changed or deleted 2 lines changed or added


 lockstate.h   lockstate.h 
skipping to change at line 52 skipping to change at line 52
char threadState() const { return _threadState; } char threadState() const { return _threadState; }
bool isRW() const; // RW bool isRW() const; // RW
bool isW() const; // W bool isW() const; // W
bool hasAnyReadLock() const; // explicitly rR bool hasAnyReadLock() const; // explicitly rR
bool hasAnyWriteLock() const; // wWX bool hasAnyWriteLock() const; // wWX
bool isLocked( const StringData& ns ); // rwRW bool isLocked( const StringData& ns ); // rwRW
/** pending means we are currently trying to get a lock */ /** pending means we are currently trying to get a lock */
bool hasLockPending() const { return _lockPending; } bool hasLockPending() const { return _lockPending || _lockPendingPa rallelWriter; }
// ---- // ----
void lockedStart( char newState ); // RWrw void lockedStart( char newState ); // RWrw
void unlocked(); // _threadState = 0 void unlocked(); // _threadState = 0
/** /**
* you have to be locked already to call this * you have to be locked already to call this
* this is mostly for W_to_R or R_to_W * this is mostly for W_to_R or R_to_W
*/ */
skipping to change at line 83 skipping to change at line 83
Lock::ScopedLock* leaveScopedLock(); Lock::ScopedLock* leaveScopedLock();
void lockedNestable( Lock::Nestable what , int type ); void lockedNestable( Lock::Nestable what , int type );
void unlockedNestable(); void unlockedNestable();
void lockedOther( const string& db , int type , WrapperForRWLock* l ock ); void lockedOther( const string& db , int type , WrapperForRWLock* l ock );
void lockedOther( int type ); // "same lock as last time" case void lockedOther( int type ); // "same lock as last time" case
void unlockedOther(); void unlockedOther();
bool _batchWriter; bool _batchWriter;
LockStat* getRelevantLockStat(); LockStat* getRelevantLockStat();
void recordLockTime() { _scopedLk->recordTime(); }
void resetLockTime() { _scopedLk->resetTime(); }
private: private:
unsigned _recursive; // we allow recursively asking for a lock; we track that here unsigned _recursive; // we allow recursively asking for a lock; we track that here
// global lock related // global lock related
char _threadState; // 0, 'r', 'w', 'R', 'W' char _threadState; // 0, 'r', 'w', 'R', 'W'
// db level locking related // db level locking related
Lock::Nestable _whichNestable; Lock::Nestable _whichNestable;
int _nestableCount; // recursive lock count on local or admin db XXX - change name int _nestableCount; // recursive lock count on local or admin db XXX - change name
int _otherCount; // >0 means write lock, <0 read lo ck - XXX change name int _otherCount; // >0 means write lock, <0 read lo ck - XXX change name
string _otherName; // which database are we locking and working with (besides local/admin) string _otherName; // which database are we locking and working with (besides local/admin)
WrapperForRWLock* _otherLock; // so we don't have to check the map too often (the map has a mutex) WrapperForRWLock* _otherLock; // so we don't have to check the map too often (the map has a mutex)
// for temprelease // for temprelease
// for the nonrecursive case. otherwise there would be many // for the nonrecursive case. otherwise there would be many
// the first lock goes here, which is ok since we can't yield recur sive locks // the first lock goes here, which is ok since we can't yield recur sive locks
Lock::ScopedLock* _scopedLk; Lock::ScopedLock* _scopedLk;
bool _lockPending; bool _lockPending;
bool _lockPendingParallelWriter;
friend class Acquiring; friend class Acquiring;
friend class AcquiringParallelWriter;
}; };
class WrapperForRWLock : boost::noncopyable { class WrapperForRWLock : boost::noncopyable {
SimpleRWLock r; SimpleRWLock r;
public: public:
string name() const { return r.name; } string name() const { return r.name; }
LockStat stats; LockStat stats;
WrapperForRWLock(const char *name) : r(name) { } WrapperForRWLock(const char *name) : r(name) { }
void lock() { r.lock(); } void lock() { r.lock(); }
void lock_shared() { r.lock_shared(); } void lock_shared() { r.lock_shared(); }
skipping to change at line 130 skipping to change at line 135
class Acquiring { class Acquiring {
public: public:
Acquiring( Lock::ScopedLock* lock, LockState& ls ); Acquiring( Lock::ScopedLock* lock, LockState& ls );
~Acquiring(); ~Acquiring();
private: private:
Lock::ScopedLock* _lock; Lock::ScopedLock* _lock;
LockState& _ls; LockState& _ls;
}; };
class AcquiringParallelWriter {
public:
AcquiringParallelWriter( LockState& ls );
~AcquiringParallelWriter();
private:
LockState& _ls;
};
} }
 End of changes. 5 change blocks. 
1 lines changed or deleted 15 lines changed or added


 log.h   log.h 
skipping to change at line 74 skipping to change at line 74
return LOG_DEBUG; return LOG_DEBUG;
case LL_INFO: case LL_INFO:
return LOG_INFO; return LOG_INFO;
case LL_NOTICE: case LL_NOTICE:
return LOG_NOTICE; return LOG_NOTICE;
case LL_WARNING: case LL_WARNING:
return LOG_WARNING; return LOG_WARNING;
case LL_ERROR: case LL_ERROR:
return LOG_ERR; return LOG_ERR;
case LL_SEVERE: case LL_SEVERE:
return LOG_CRIT; return LOG_EMERG;
default: default:
return LL_INFO; return LL_INFO;
} }
} }
#endif #endif
class LabeledLevel { class LabeledLevel {
public: public:
LabeledLevel( int level ) : _level( level ) {} LabeledLevel( int level ) : _level( level ) {}
LabeledLevel( const char* label, int level ) : _label( label ), _le vel( level ) {} LabeledLevel( const char* label, int level ) : _label( label ), _le vel( level ) {}
skipping to change at line 251 skipping to change at line 251
static void setLogFile(FILE* f); static void setLogFile(FILE* f);
#ifndef _WIN32 #ifndef _WIN32
static void useSyslog(const char * name) { static void useSyslog(const char * name) {
std::cout << "using syslog ident: " << name << std::endl; std::cout << "using syslog ident: " << name << std::endl;
// openlog requires heap allocated non changing pointer // openlog requires heap allocated non changing pointer
// this should only be called once per pragram execution // this should only be called once per pragram execution
char * newName = (char *) malloc( strlen(name) + 1 ); char * newName = (char *) malloc( strlen(name) + 1 );
strcpy( newName , name); strcpy( newName , name);
openlog( newName , LOG_ODELAY , LOG_USER ); openlog( newName , LOG_PID | LOG_CONS | LOG_ODELAY , LOG_USER ) ;
isSyslog = true; isSyslog = true;
} }
#endif #endif
static int magicNumber() { return 1717; } static int magicNumber() { return 1717; }
static int getLogDesc() { static int getLogDesc() {
int fd = -1; int fd = -1;
if (logfile != NULL) if (logfile != NULL)
#if defined(_WIN32) #if defined(_WIN32)
skipping to change at line 446 skipping to change at line 446
struct LogIndentLevel { struct LogIndentLevel {
LogIndentLevel(){ LogIndentLevel(){
Logstream::get().indentInc(); Logstream::get().indentInc();
} }
~LogIndentLevel(){ ~LogIndentLevel(){
Logstream::get().indentDec(); Logstream::get().indentDec();
} }
}; };
extern Tee* const warnings; // Things put here go in serverStatus extern Tee* const warnings; // Things put here go in serverStatus
extern Tee* startupWarningsLog;
string errnoWithDescription(int errorcode = -1); string errnoWithDescription(int errorcode = -1);
void rawOut( const string &s ); void rawOut( const string &s );
/** /**
* Write the current context (backtrace), along with the optional "msg" . * Write the current context (backtrace), along with the optional "msg" .
*/ */
void logContext(const char *msg = NULL); void logContext(const char *msg = NULL);
} // namespace mongo } // namespace mongo
 End of changes. 3 change blocks. 
2 lines changed or deleted 3 lines changed or added


 lruishmap.h   lruishmap.h 
skipping to change at line 20 skipping to change at line 20
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or impli ed. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or impli ed.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#pragma once #pragma once
#include "../pch.h" #include "mongo/pch.h"
#include "../util/goodies.h" #include "../util/goodies.h"
namespace mongo { namespace mongo {
/* Your K object must define: /* Your K object must define:
int hash() - must always return > 0. int hash() - must always return > 0.
operator== operator==
*/ */
template <class K, class V, int MaxChain> template <class K, class V, int MaxChain>
 End of changes. 1 change blocks. 
1 lines changed or deleted 1 lines changed or added


 matcher.h   matcher.h 
skipping to change at line 264 skipping to change at line 264
BSONObj _constrainIndexKey; BSONObj _constrainIndexKey;
vector<ElementMatcher> _basics; vector<ElementMatcher> _basics;
bool _haveSize; bool _haveSize;
bool _all; bool _all;
bool _hasArray; bool _hasArray;
bool _haveNeg; bool _haveNeg;
/* $atomic - if true, a multi document operation (some removes, upd ates) /* $atomic - if true, a multi document operation (some removes, upd ates)
should be done atomically. in that case, we do not yi eld - should be done atomically. in that case, we do not yi eld -
i.e. we stay locked the whole time. i.e. we stay locked the whole time.
http://www.mongodb.org/display/DOCS/Removing[ http://dochub.mongodb.org/core/remove
*/ */
bool _atomic; bool _atomic;
vector<RegexMatcher> _regexs; vector<RegexMatcher> _regexs;
// so we delete the mem when we're done: // so we delete the mem when we're done:
vector< shared_ptr< BSONObjBuilder > > _builders; vector< shared_ptr< BSONObjBuilder > > _builders;
list< shared_ptr< Matcher > > _andMatchers; list< shared_ptr< Matcher > > _andMatchers;
list< shared_ptr< Matcher > > _orMatchers; list< shared_ptr< Matcher > > _orMatchers;
list< shared_ptr< Matcher > > _norMatchers; list< shared_ptr< Matcher > > _norMatchers;
 End of changes. 1 change blocks. 
1 lines changed or deleted 1 lines changed or added


 message.h   message.h 
skipping to change at line 88 skipping to change at line 88
default: default:
PRINT(op); PRINT(op);
verify(0); verify(0);
return ""; return "";
} }
} }
#pragma pack(1) #pragma pack(1)
/* see http://www.mongodb.org/display/DOCS/Mongo+Wire+Protocol /* see http://dochub.mongodb.org/core/mongowireprotocol
*/ */
struct MSGHEADER { struct MSGHEADER {
int messageLength; // total message size, including this int messageLength; // total message size, including this
int requestID; // identifier for this message int requestID; // identifier for this message
int responseTo; // requestID from the original request int responseTo; // requestID from the original request
// (used in reponses from db) // (used in reponses from db)
int opCode; int opCode;
}; };
#pragma pack() #pragma pack()
 End of changes. 1 change blocks. 
1 lines changed or deleted 1 lines changed or added


 message_port.h   message_port.h 
skipping to change at line 40 skipping to change at line 40
class AbstractMessagingPort : boost::noncopyable { class AbstractMessagingPort : boost::noncopyable {
public: public:
AbstractMessagingPort() : tag(0), _connectionId(0) {} AbstractMessagingPort() : tag(0), _connectionId(0) {}
virtual ~AbstractMessagingPort() { } virtual ~AbstractMessagingPort() { }
virtual void reply(Message& received, Message& response, MSGID resp onseTo) = 0; // like the reply below, but doesn't rely on received.data sti ll being available virtual void reply(Message& received, Message& response, MSGID resp onseTo) = 0; // like the reply below, but doesn't rely on received.data sti ll being available
virtual void reply(Message& received, Message& response) = 0; virtual void reply(Message& received, Message& response) = 0;
virtual HostAndPort remote() const = 0; virtual HostAndPort remote() const = 0;
virtual unsigned remotePort() const = 0; virtual unsigned remotePort() const = 0;
virtual void assertStillConnected() = 0;
long long connectionId() const { return _connectionId; } long long connectionId() const { return _connectionId; }
void setConnectionId( long long connectionId ); void setConnectionId( long long connectionId );
public: public:
// TODO make this private with some helpers // TODO make this private with some helpers
/* ports can be tagged with various classes. see closeAllSockets(t ag). defaults to 0. */ /* ports can be tagged with various classes. see closeAllSockets(t ag). defaults to 0. */
unsigned tag; unsigned tag;
private: private:
skipping to change at line 96 skipping to change at line 94
* Note: if you fail to call recv and someone else uses this port, * Note: if you fail to call recv and someone else uses this port,
* horrible things will happend * horrible things will happend
*/ */
bool recv( const Message& sent , Message& response ); bool recv( const Message& sent , Message& response );
void piggyBack( Message& toSend , int responseTo = -1 ); void piggyBack( Message& toSend , int responseTo = -1 );
unsigned remotePort() const { return psock->remotePort(); } unsigned remotePort() const { return psock->remotePort(); }
virtual HostAndPort remote() const; virtual HostAndPort remote() const;
void assertStillConnected();
boost::shared_ptr<Socket> psock; boost::shared_ptr<Socket> psock;
void send( const char * data , int len, const char *context ) { void send( const char * data , int len, const char *context ) {
psock->send( data, len, context ); psock->send( data, len, context );
} }
void send( const vector< pair< char *, int > > &data, const char *c ontext ) { void send( const vector< pair< char *, int > > &data, const char *c ontext ) {
psock->send( data, context ); psock->send( data, context );
} }
bool connect(SockAddr& farEnd) { bool connect(SockAddr& farEnd) {
return psock->connect( farEnd ); return psock->connect( farEnd );
 End of changes. 2 change blocks. 
4 lines changed or deleted 0 lines changed or added


 message_server.h   message_server.h 
skipping to change at line 25 skipping to change at line 25
* limitations under the License. * limitations under the License.
*/ */
/* /*
abstract database server abstract database server
async io core, worker thread system async io core, worker thread system
*/ */
#pragma once #pragma once
#include "../../pch.h" #include "mongo/pch.h"
namespace mongo { namespace mongo {
struct LastError; struct LastError;
class MessageHandler { class MessageHandler {
public: public:
virtual ~MessageHandler() {} virtual ~MessageHandler() {}
/** /**
 End of changes. 1 change blocks. 
1 lines changed or deleted 1 lines changed or added


 miniwebserver.h   miniwebserver.h 
skipping to change at line 20 skipping to change at line 20
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or impli ed. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or impli ed.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#pragma once #pragma once
#include "../../pch.h" #include "mongo/pch.h"
#include "message.h" #include "message.h"
#include "message_port.h" #include "message_port.h"
#include "listen.h" #include "listen.h"
#include "../../db/jsobj.h" #include "../../db/jsobj.h"
namespace mongo { namespace mongo {
class MiniWebServer : public Listener { class MiniWebServer : public Listener {
public: public:
MiniWebServer(const string& name, const string &ip, int _port); MiniWebServer(const string& name, const string &ip, int _port);
 End of changes. 1 change blocks. 
1 lines changed or deleted 1 lines changed or added


 module.h   module.h 
skipping to change at line 21 skipping to change at line 21
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details. * GNU Affero General Public License for more details.
* *
* You should have received a copy of the GNU Affero General Public Licen se * You should have received a copy of the GNU Affero General Public Licen se
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#pragma once #pragma once
#include "../pch.h" #include "mongo/pch.h"
#include <boost/program_options.hpp> #include <boost/program_options.hpp>
#include <list> #include <list>
namespace mongo { namespace mongo {
/** /**
* Module is the base class for adding modules to MongoDB * Module is the base class for adding modules to MongoDB
* modules allow adding hooks and features to mongo * modules allow adding hooks and features to mongo
* the idea is to add hooks into the main code for module support where needed * the idea is to add hooks into the main code for module support where needed
* some ideas are: monitoring, indexes, full text search * some ideas are: monitoring, indexes, full text search
 End of changes. 1 change blocks. 
1 lines changed or deleted 1 lines changed or added


 mr.h   mr.h 
skipping to change at line 20 skipping to change at line 20
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details. * GNU Affero General Public License for more details.
* *
* You should have received a copy of the GNU Affero General Public Lice nse * You should have received a copy of the GNU Affero General Public Lice nse
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#pragma once #pragma once
#include "pch.h" #include "mongo/pch.h"
namespace mongo { namespace mongo {
namespace mr { namespace mr {
typedef vector<BSONObj> BSONList; typedef vector<BSONObj> BSONList;
class State; class State;
// ------------ function interfaces ----------- // ------------ function interfaces -----------
 End of changes. 1 change blocks. 
1 lines changed or deleted 1 lines changed or added


 mutex.h   mutex.h 
skipping to change at line 31 skipping to change at line 31
#include "mongo/platform/windows_basic.h" #include "mongo/platform/windows_basic.h"
#endif #endif
#include <boost/noncopyable.hpp> #include <boost/noncopyable.hpp>
#include <boost/thread/mutex.hpp> #include <boost/thread/mutex.hpp>
#include <boost/thread/xtime.hpp> #include <boost/thread/xtime.hpp>
#include "mongo/util/assert_util.h" #include "mongo/util/assert_util.h"
#include "mongo/util/heapcheck.h" #include "mongo/util/heapcheck.h"
#include "mongo/util/concurrency/threadlocal.h" #include "mongo/util/concurrency/threadlocal.h"
#include "mongo/util/time_support.h"
#if defined(_DEBUG) #if defined(_DEBUG)
#include "mongo/util/concurrency/mutexdebugger.h" #include "mongo/util/concurrency/mutexdebugger.h"
#endif #endif
namespace mongo { namespace mongo {
inline boost::xtime incxtimemillis( long long s ) { inline boost::xtime incxtimemillis( long long s ) {
boost::xtime xt; boost::xtime xt;
boost::xtime_get(&xt, boost::TIME_UTC); boost::xtime_get(&xt, MONGO_BOOST_TIME_UTC);
xt.sec += (int)( s / 1000 ); xt.sec += (int)( s / 1000 );
xt.nsec += (int)(( s % 1000 ) * 1000000); xt.nsec += (int)(( s % 1000 ) * 1000000);
if ( xt.nsec >= 1000000000 ) { if ( xt.nsec >= 1000000000 ) {
xt.nsec -= 1000000000; xt.nsec -= 1000000000;
xt.sec++; xt.sec++;
} }
return xt; return xt;
} }
// If you create a local static instance of this class, that instance w ill be destroyed // If you create a local static instance of this class, that instance w ill be destroyed
 End of changes. 2 change blocks. 
1 lines changed or deleted 2 lines changed or added


 namespace.h   namespace.h 
skipping to change at line 21 skipping to change at line 21
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details. * GNU Affero General Public License for more details.
* *
* You should have received a copy of the GNU Affero General Public Licen se * You should have received a copy of the GNU Affero General Public Licen se
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#pragma once #pragma once
#include "pch.h" #include "mongo/pch.h"
#include <cstring> #include <cstring>
#include <string> #include <string>
namespace mongo { namespace mongo {
#pragma pack(1) #pragma pack(1)
class Namespace { class Namespace {
public: public:
explicit Namespace(const char *ns) { *this = ns; } explicit Namespace(const char *ns) { *this = ns; }
 End of changes. 1 change blocks. 
1 lines changed or deleted 1 lines changed or added


 namespace_details.h   namespace_details.h 
skipping to change at line 21 skipping to change at line 21
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details. * GNU Affero General Public License for more details.
* *
* You should have received a copy of the GNU Affero General Public Licen se * You should have received a copy of the GNU Affero General Public Licen se
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#pragma once #pragma once
#include "pch.h" #include "mongo/pch.h"
#include "mongo/db/d_concurrency.h" #include "mongo/db/d_concurrency.h"
#include "mongo/db/diskloc.h" #include "mongo/db/diskloc.h"
#include "mongo/db/index.h" #include "mongo/db/index.h"
#include "mongo/db/jsobj.h" #include "mongo/db/jsobj.h"
#include "mongo/db/mongommf.h" #include "mongo/db/mongommf.h"
#include "mongo/db/namespace.h" #include "mongo/db/namespace.h"
#include "mongo/db/queryoptimizercursor.h" #include "mongo/db/queryoptimizercursor.h"
#include "mongo/db/querypattern.h" #include "mongo/db/querypattern.h"
#include "mongo/util/hashtab.h" #include "mongo/util/hashtab.h"
 End of changes. 1 change blocks. 
1 lines changed or deleted 1 lines changed or added


 namespacestring.h   namespacestring.h 
skipping to change at line 101 skipping to change at line 101
* foo bar * foo bar
* foo.bar * foo.bar
* foo"bar * foo"bar
* *
* @param db - a possible database name * @param db - a possible database name
* @return if db is an allowed database name * @return if db is an allowed database name
*/ */
static bool validDBName( const string& db ) { static bool validDBName( const string& db ) {
if ( db.size() == 0 || db.size() > 64 ) if ( db.size() == 0 || db.size() > 64 )
return false; return false;
#ifdef _WIN32
// We prohibit all FAT32-disallowed characters on Windows
size_t good = strcspn( db.c_str() , "/\\. \"*<>:|?" ); size_t good = strcspn( db.c_str() , "/\\. \"*<>:|?" );
#else
// For non-Windows platforms we are much more lenient
size_t good = strcspn( db.c_str() , "/\\. \"" );
#endif
return good == db.size(); return good == db.size();
} }
/** /**
* samples: * samples:
* good: * good:
* foo.bar * foo.bar
* bad: * bad:
* foo. * foo.
* *
* @param dbcoll - a possible collection name of the form db.coll * @param dbcoll - a possible collection name of the form db.coll
* @return if db.coll is an allowed collection name * @return if db.coll is an allowed collection name
*/ */
static bool validCollectionName(const char* dbcoll){ static bool validCollectionName(const char* dbcoll){
const char *c = strchr( dbcoll, '.' ) + 1; const char *c = strchr( dbcoll, '.' );
return normal(dbcoll) && c && *c; return (c != NULL) && (c[1] != '\0') && normal(dbcoll);
} }
private: private:
void init(const char *ns) { void init(const char *ns) {
const char *p = strchr(ns, '.'); const char *p = strchr(ns, '.');
if( p == 0 ) return; if( p == 0 ) return;
db = string(ns, p - ns); db = string(ns, p - ns);
coll = p + 1; coll = p + 1;
} }
}; };
 End of changes. 3 change blocks. 
2 lines changed or deleted 8 lines changed or added


 oid.h   oid.h 
skipping to change at line 49 skipping to change at line 49
be stored big endian unlike the rest of BSON. This is because they are compared byte-by-byte and we want to ensure be stored big endian unlike the rest of BSON. This is because they are compared byte-by-byte and we want to ensure
a mostly increasing order. a mostly increasing order.
*/ */
class OID { class OID {
public: public:
OID() : a(0), b(0) { } OID() : a(0), b(0) { }
/** init from a 24 char hex string */ /** init from a 24 char hex string */
explicit OID(const std::string &s) { init(s); } explicit OID(const std::string &s) { init(s); }
/** init from a reference to a 12-byte array */
explicit OID(const unsigned char (&arr)[12]) {
memcpy(data, arr, 12);
}
/** initialize to 'null' */ /** initialize to 'null' */
void clear() { a = 0; b = 0; } void clear() { a = 0; b = 0; }
const unsigned char *getData() const { return data; } const unsigned char *getData() const { return data; }
bool operator==(const OID& r) const { return a==r.a && b==r.b; } bool operator==(const OID& r) const { return a==r.a && b==r.b; }
bool operator!=(const OID& r) const { return a!=r.a || b!=r.b; } bool operator!=(const OID& r) const { return a!=r.a || b!=r.b; }
int compare( const OID& other ) const { return memcmp( data , other .data , 12 ); } int compare( const OID& other ) const { return memcmp( data , other .data , 12 ); }
bool operator<( const OID& other ) const { return compare( other ) < 0; } bool operator<( const OID& other ) const { return compare( other ) < 0; }
bool operator<=( const OID& other ) const { return compare( other ) <= 0; } bool operator<=( const OID& other ) const { return compare( other ) <= 0; }
 End of changes. 1 change blocks. 
0 lines changed or deleted 5 lines changed or added


 oplog.h   oplog.h 
skipping to change at line 147 skipping to change at line 147
string hn; string hn;
public: public:
Sync(const string& hostname) : hn(hostname) {} Sync(const string& hostname) : hn(hostname) {}
virtual ~Sync() {} virtual ~Sync() {}
virtual BSONObj getMissingDoc(const BSONObj& o); virtual BSONObj getMissingDoc(const BSONObj& o);
/** /**
* If applyOperation_inlock should be called again after an update fails. * If applyOperation_inlock should be called again after an update fails.
*/ */
virtual bool shouldRetry(const BSONObj& o); virtual bool shouldRetry(const BSONObj& o);
void setHostname(const string& hostname);
}; };
void pretouchOperation(const BSONObj& op); void pretouchOperation(const BSONObj& op);
void pretouchN(vector<BSONObj>&, unsigned a, unsigned b); void pretouchN(vector<BSONObj>&, unsigned a, unsigned b);
/** /**
* take an op and apply locally * take an op and apply locally
* used for applying from an oplog * used for applying from an oplog
* @param fromRepl really from replication or for testing/internal/comm and/etc... * @param fromRepl really from replication or for testing/internal/comm and/etc...
* Returns if the op was an update that could not be applied (true on f ailure) * Returns if the op was an update that could not be applied (true on f ailure)
*/ */
bool applyOperation_inlock(const BSONObj& op , bool fromRepl = true ); bool applyOperation_inlock(const BSONObj& op, bool fromRepl = true, boo l convertUpdateToUpsert = false);
} }
 End of changes. 2 change blocks. 
1 lines changed or deleted 2 lines changed or added


 pipeline.h   pipeline.h 
skipping to change at line 19 skipping to change at line 19
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details. * GNU Affero General Public License for more details.
* *
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#pragma once #pragma once
#include "pch.h" #include "mongo/pch.h"
#include "db/commands.h"
#include "db/jsobj.h"
#include "util/intrusive_counter.h" #include "util/intrusive_counter.h"
#include "util/timer.h" #include "util/timer.h"
namespace mongo { namespace mongo {
class BSONObj; class BSONObj;
class BSONObjBuilder; class BSONObjBuilder;
class BSONArrayBuilder;
class DocumentSource; class DocumentSource;
class DocumentSourceProject; class DocumentSourceProject;
class Expression; class Expression;
class ExpressionContext; class ExpressionContext;
class ExpressionNary; class ExpressionNary;
struct OpDesc; // local private struct struct OpDesc; // local private struct
/** mongodb "commands" (sent via db.$cmd.findOne(...)) /** mongodb "commands" (sent via db.$cmd.findOne(...))
subclass to make a command. define a singleton object for it. subclass to make a command. define a singleton object for it.
*/ */
 End of changes. 3 change blocks. 
3 lines changed or deleted 2 lines changed or added


 pipeline_d.h   pipeline_d.h 
skipping to change at line 19 skipping to change at line 19
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details. * GNU Affero General Public License for more details.
* *
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#pragma once #pragma once
#include "pch.h" #include "mongo/pch.h"
namespace mongo { namespace mongo {
class DocumentSourceCursor; class DocumentSourceCursor;
class Pipeline; class Pipeline;
/* /*
PipelineD is an extension of the Pipeline class, but with additional PipelineD is an extension of the Pipeline class, but with additional
material that references symbols that are not available in mongos, material that references symbols that are not available in mongos,
where the remainder of the Pipeline class also functions. PipelineD where the remainder of the Pipeline class also functions. PipelineD
is a friend of Pipeline so that it can have equal access to Pipeline' s is a friend of Pipeline so that it can have equal access to Pipeline' s
 End of changes. 1 change blocks. 
1 lines changed or deleted 1 lines changed or added


 projection.h   projection.h 
skipping to change at line 20 skipping to change at line 20
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or impli ed. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or impli ed.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#pragma once #pragma once
#include "pch.h" #include "mongo/pch.h"
#include "jsobj.h" #include "jsobj.h"
namespace mongo { namespace mongo {
// fwd decls // fwd decls
class Matcher; class Matcher;
class MatchDetails; class MatchDetails;
/** /**
* given a document and a projection specification * given a document and a projection specification
 End of changes. 1 change blocks. 
1 lines changed or deleted 1 lines changed or added


 query.h   query.h 
skipping to change at line 21 skipping to change at line 21
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details. * GNU Affero General Public License for more details.
* *
* You should have received a copy of the GNU Affero General Public Licen se * You should have received a copy of the GNU Affero General Public Licen se
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#pragma once #pragma once
#include "../../pch.h" #include "mongo/pch.h"
#include "../../util/net/message.h" #include "../../util/net/message.h"
#include "../dbmessage.h" #include "../dbmessage.h"
#include "../jsobj.h" #include "../jsobj.h"
#include "../diskloc.h" #include "../diskloc.h"
#include "../explain.h" #include "../explain.h"
#include "../../s/d_chunk_manager.h" #include "../../s/d_chunk_manager.h"
// struct QueryOptions, QueryResult, QueryResultFlags in: // struct QueryOptions, QueryResult, QueryResultFlags in:
namespace mongo { namespace mongo {
 End of changes. 1 change blocks. 
1 lines changed or deleted 1 lines changed or added


 queryutil.h   queryutil.h 
skipping to change at line 79 skipping to change at line 79
const BSONObj& getFilter() const { return _filter; } const BSONObj& getFilter() const { return _filter; }
Projection* getFields() const { return _fields.get(); } Projection* getFields() const { return _fields.get(); }
shared_ptr<Projection> getFieldPtr() const { return _fields; } shared_ptr<Projection> getFieldPtr() const { return _fields; }
int getSkip() const { return _ntoskip; } int getSkip() const { return _ntoskip; }
int getNumToReturn() const { return _ntoreturn; } int getNumToReturn() const { return _ntoreturn; }
bool wantMore() const { return _wantMore; } bool wantMore() const { return _wantMore; }
int getOptions() const { return _options; } int getOptions() const { return _options; }
bool hasOption( int x ) const { return ( x & _options ) != 0; } bool hasOption( int x ) const { return ( x & _options ) != 0; }
bool hasReadPref() const { return _hasReadPref; }
bool isExplain() const { return _explain; } bool isExplain() const { return _explain; }
bool isSnapshot() const { return _snapshot; } bool isSnapshot() const { return _snapshot; }
bool returnKey() const { return _returnKey; } bool returnKey() const { return _returnKey; }
bool showDiskLoc() const { return _showDiskLoc; } bool showDiskLoc() const { return _showDiskLoc; }
const BSONObj& getMin() const { return _min; } const BSONObj& getMin() const { return _min; }
const BSONObj& getMax() const { return _max; } const BSONObj& getMax() const { return _max; }
const BSONObj& getOrder() const { return _order; } const BSONObj& getOrder() const { return _order; }
const BSONObj& getHint() const { return _hint; } const BSONObj& getHint() const { return _hint; }
skipping to change at line 153 skipping to change at line 154
if ( e.isABSONObj() ) { if ( e.isABSONObj() ) {
_filter = e.embeddedObject(); _filter = e.embeddedObject();
_initTop( q ); _initTop( q );
} }
else { else {
_filter = q; _filter = q;
} }
_filter = _filter.getOwned(); _filter = _filter.getOwned();
_hasReadPref = q.hasField("$readPreference");
} }
void _reset() { void _reset() {
_wantMore = true; _wantMore = true;
_explain = false; _explain = false;
_snapshot = false; _snapshot = false;
_returnKey = false; _returnKey = false;
_showDiskLoc = false; _showDiskLoc = false;
_maxScan = 0; _maxScan = 0;
} }
skipping to change at line 234 skipping to change at line 237
int _ntoreturn; int _ntoreturn;
BSONObj _filter; BSONObj _filter;
BSONObj _order; BSONObj _order;
const int _options; const int _options;
shared_ptr< Projection > _fields; shared_ptr< Projection > _fields;
bool _wantMore; bool _wantMore;
bool _explain; bool _explain;
bool _snapshot; bool _snapshot;
bool _returnKey; bool _returnKey;
bool _showDiskLoc; bool _showDiskLoc;
bool _hasReadPref;
BSONObj _min; BSONObj _min;
BSONObj _max; BSONObj _max;
BSONObj _hint; BSONObj _hint;
int _maxScan; int _maxScan;
}; };
/** /**
* One side of an interval of BSONElements, defined by a value and a bo olean indicating if the * One side of an interval of BSONElements, defined by a value and a bo olean indicating if the
* interval includes the value. * interval includes the value.
*/ */
skipping to change at line 516 skipping to change at line 520
void init( bool optimize ); void init( bool optimize );
void appendQueries( const FieldRangeSet &other ); void appendQueries( const FieldRangeSet &other );
void makeEmpty(); void makeEmpty();
/** /**
* Query parsing routines. * Query parsing routines.
* TODO integrate these with an external query parser shared by the matcher. SERVER-1009 * TODO integrate these with an external query parser shared by the matcher. SERVER-1009
*/ */
void handleMatchField( const BSONElement& matchElement, bool optimi ze ); void handleMatchField( const BSONElement& matchElement, bool optimi ze );
void handleConjunctionClauses( const BSONObj& clauses, bool optimiz e );
void handleOp( const char* matchFieldName, const BSONElement& op, b ool isNot, void handleOp( const char* matchFieldName, const BSONElement& op, b ool isNot,
bool optimize ); bool optimize );
void handleNotOp( const char* matchFieldName, const BSONElement& no tOp, bool optimize ); void handleNotOp( const char* matchFieldName, const BSONElement& no tOp, bool optimize );
void handleElemMatch( const char* matchFieldName, const BSONElement & elemMatch, bool isNot, void handleElemMatch( const char* matchFieldName, const BSONElement & elemMatch, bool isNot,
bool optimize ); bool optimize );
/** Must be called when a match element is skipped or modified to g enerate a FieldRange. */ /** Must be called when a match element is skipped or modified to g enerate a FieldRange. */
void adjustMatchField(); void adjustMatchField();
void intersectMatchField( const char *fieldName, const BSONElement &matchElement, void intersectMatchField( const char *fieldName, const BSONElement &matchElement,
bool isNot, bool optimize ); bool isNot, bool optimize );
 End of changes. 4 change blocks. 
0 lines changed or deleted 5 lines changed or added


 queue.h   queue.h 
skipping to change at line 20 skipping to change at line 20
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or impli ed. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or impli ed.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#pragma once #pragma once
#include "pch.h" #include "mongo/pch.h"
#include <limits> #include <limits>
#include <queue> #include <queue>
#include "mongo/util/timer.h" #include "mongo/util/timer.h"
namespace mongo { namespace mongo {
template <typename T> template <typename T>
size_t _getSizeDefault(const T& t) { size_t _getSizeDefault(const T& t) {
skipping to change at line 123 skipping to change at line 123
/** /**
* blocks waiting for an object until maxSecondsToWait passes * blocks waiting for an object until maxSecondsToWait passes
* if got one, return true and set in t * if got one, return true and set in t
* otherwise return false and t won't be changed * otherwise return false and t won't be changed
*/ */
bool blockingPop( T& t , int maxSecondsToWait ) { bool blockingPop( T& t , int maxSecondsToWait ) {
Timer timer; Timer timer;
boost::xtime xt; boost::xtime xt;
boost::xtime_get(&xt, boost::TIME_UTC); boost::xtime_get(&xt, MONGO_BOOST_TIME_UTC);
xt.sec += maxSecondsToWait; xt.sec += maxSecondsToWait;
scoped_lock l( _lock ); scoped_lock l( _lock );
while( _queue.empty() ) { while( _queue.empty() ) {
if ( ! _cvNoLongerEmpty.timed_wait( l.boost() , xt ) ) if ( ! _cvNoLongerEmpty.timed_wait( l.boost() , xt ) )
return false; return false;
} }
t = _queue.front(); t = _queue.front();
_queue.pop(); _queue.pop();
skipping to change at line 145 skipping to change at line 145
_cvNoLongerFull.notify_one(); _cvNoLongerFull.notify_one();
return true; return true;
} }
// Obviously, this should only be used when you have // Obviously, this should only be used when you have
// only one consumer // only one consumer
bool blockingPeek(T& t, int maxSecondsToWait) { bool blockingPeek(T& t, int maxSecondsToWait) {
Timer timer; Timer timer;
boost::xtime xt; boost::xtime xt;
boost::xtime_get(&xt, boost::TIME_UTC); boost::xtime_get(&xt, MONGO_BOOST_TIME_UTC);
xt.sec += maxSecondsToWait; xt.sec += maxSecondsToWait;
scoped_lock l( _lock ); scoped_lock l( _lock );
while( _queue.empty() ) { while( _queue.empty() ) {
if ( ! _cvNoLongerEmpty.timed_wait( l.boost() , xt ) ) if ( ! _cvNoLongerEmpty.timed_wait( l.boost() , xt ) )
return false; return false;
} }
t = _queue.front(); t = _queue.front();
return true; return true;
 End of changes. 3 change blocks. 
3 lines changed or deleted 3 lines changed or added


 repl_block.h   repl_block.h 
skipping to change at line 21 skipping to change at line 21
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details. * GNU Affero General Public License for more details.
* *
* You should have received a copy of the GNU Affero General Public Licen se * You should have received a copy of the GNU Affero General Public Licen se
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#pragma once #pragma once
#include "../pch.h" #include "mongo/pch.h"
#include "client.h" #include "client.h"
#include "curop.h" #include "curop.h"
/** /**
local.slaves - current location for all slaves local.slaves - current location for all slaves
*/ */
namespace mongo { namespace mongo {
void updateSlaveLocation( CurOp& curop, const char * oplog_ns , OpTime lastOp ); void updateSlaveLocation( CurOp& curop, const char * oplog_ns , OpTime lastOp );
/** @return true if op has made it to w servers */ /** @return true if op has made it to w servers */
bool opReplicatedEnough( OpTime op , int w ); bool opReplicatedEnough( OpTime op , int w );
bool opReplicatedEnough( OpTime op , BSONElement w ); bool opReplicatedEnough( OpTime op , BSONElement w );
bool waitForReplication( OpTime op , int w , int maxSecondsToWait );
void resetSlaveCache(); void resetSlaveCache();
unsigned getSlaveCount(); unsigned getSlaveCount();
} }
 End of changes. 2 change blocks. 
1 lines changed or deleted 3 lines changed or added


 request.h   request.h 
skipping to change at line 20 skipping to change at line 20
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details. * GNU Affero General Public License for more details.
* *
* You should have received a copy of the GNU Affero General Public Lice nse * You should have received a copy of the GNU Affero General Public Lice nse
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#pragma once #pragma once
#include "../pch.h" #include "mongo/pch.h"
#include "../util/net/message.h" #include "../util/net/message.h"
#include "../db/dbmessage.h" #include "../db/dbmessage.h"
#include "config.h" #include "config.h"
#include "util.h" #include "util.h"
namespace mongo { namespace mongo {
class OpCounters; class OpCounters;
class ClientInfo; class ClientInfo;
 End of changes. 1 change blocks. 
1 lines changed or deleted 1 lines changed or added


 rs.h   rs.h 
skipping to change at line 518 skipping to change at line 518
void syncFixUp(HowToFixUp& h, OplogReader& r); void syncFixUp(HowToFixUp& h, OplogReader& r);
// keep a list of hosts that we've tried recently that didn't work // keep a list of hosts that we've tried recently that didn't work
map<string,time_t> _veto; map<string,time_t> _veto;
// persistent pool of worker threads for writing ops to the databas es // persistent pool of worker threads for writing ops to the databas es
threadpool::ThreadPool _writerPool; threadpool::ThreadPool _writerPool;
// persistent pool of worker threads for prefetching // persistent pool of worker threads for prefetching
threadpool::ThreadPool _prefetcherPool; threadpool::ThreadPool _prefetcherPool;
public: public:
// Allow index prefetching to be turned on/off
enum IndexPrefetchConfig {
PREFETCH_NONE=0, PREFETCH_ID_ONLY=1, PREFETCH_ALL=2
};
void setIndexPrefetchConfig(const IndexPrefetchConfig cfg) {
_indexPrefetchConfig = cfg;
}
IndexPrefetchConfig getIndexPrefetchConfig() {
return _indexPrefetchConfig;
}
static const int replWriterThreadCount; static const int replWriterThreadCount;
static const int replPrefetcherThreadCount; static const int replPrefetcherThreadCount;
threadpool::ThreadPool& getPrefetchPool() { return _prefetcherPool; } threadpool::ThreadPool& getPrefetchPool() { return _prefetcherPool; }
threadpool::ThreadPool& getWriterPool() { return _writerPool; } threadpool::ThreadPool& getWriterPool() { return _writerPool; }
const ReplSetConfig::MemberCfg& myConfig() const { return _config; } const ReplSetConfig::MemberCfg& myConfig() const { return _config; }
bool tryToGoLiveAsASecondary(OpTime&); // readlocks bool tryToGoLiveAsASecondary(OpTime&); // readlocks
void syncRollback(OplogReader& r); void syncRollback(OplogReader& r);
void syncThread(); void syncThread();
const OpTime lastOtherOpTime() const; const OpTime lastOtherOpTime() const;
private:
IndexPrefetchConfig _indexPrefetchConfig;
}; };
class ReplSet : public ReplSetImpl { class ReplSet : public ReplSetImpl {
public: public:
ReplSet(); ReplSet();
ReplSet(ReplSetCmdline& replSetCmdline); ReplSet(ReplSetCmdline& replSetCmdline);
virtual ~ReplSet() {} virtual ~ReplSet() {}
// for the replSetStepDown command // for the replSetStepDown command
bool stepDown(int secs) { return _stepDown(secs); } bool stepDown(int secs) { return _stepDown(secs); }
 End of changes. 2 change blocks. 
0 lines changed or deleted 15 lines changed or added


 rs_sync.h   rs_sync.h 
skipping to change at line 40 skipping to change at line 40
class BackgroundSyncInterface; class BackgroundSyncInterface;
/** /**
* "Normal" replica set syncing * "Normal" replica set syncing
*/ */
class SyncTail : public Sync { class SyncTail : public Sync {
typedef void (*MultiSyncApplyFunc)(const std::vector<BSONObj>& ops, SyncTail* st); typedef void (*MultiSyncApplyFunc)(const std::vector<BSONObj>& ops, SyncTail* st);
public: public:
SyncTail(BackgroundSyncInterface *q); SyncTail(BackgroundSyncInterface *q);
virtual ~SyncTail(); virtual ~SyncTail();
virtual bool syncApply(const BSONObj &o); virtual bool syncApply(const BSONObj &o, bool convertUpdateToUpsert = false);
void oplogApplication(); void oplogApplication();
bool peek(BSONObj* obj); bool peek(BSONObj* obj);
class OpQueue {
public:
OpQueue() : _size(0) {}
size_t getSize() { return _size; }
std::deque<BSONObj>& getDeque() { return _deque; }
void push_back(BSONObj& op) {
_deque.push_back(op);
_size += op.objsize();
}
bool empty() {
return _deque.empty();
}
private:
std::deque<BSONObj> _deque;
size_t _size;
};
// returns true if we should continue waiting for BSONObjs, false i f we should // returns true if we should continue waiting for BSONObjs, false i f we should
// stop waiting and apply the queue we have. Only returns false if !ops.empty(). // stop waiting and apply the queue we have. Only returns false if !ops.empty().
bool tryPopAndWaitForMore(std::deque<BSONObj>* ops); bool tryPopAndWaitForMore(OpQueue* ops);
// After ops have been written to db, call this // After ops have been written to db, call this
// to update local oplog.rs, as well as notify the primary // to update local oplog.rs, as well as notify the primary
// that we have applied the ops. // that we have applied the ops.
// Ops are removed from the deque. // Ops are removed from the deque.
void applyOpsToOplog(std::deque<BSONObj>* ops); void applyOpsToOplog(std::deque<BSONObj>* ops);
protected: protected:
static const unsigned int replBatchSize = 128; static const unsigned int replBatchSizeBytes = 1024 * 1024 * 256 ;
// Prefetch and write a deque of operations, using the supplied fun ction. // Prefetch and write a deque of operations, using the supplied fun ction.
// Initial Sync and Sync Tail each use a different function. // Initial Sync and Sync Tail each use a different function.
void multiApply(std::deque<BSONObj>& ops, MultiSyncApplyFunc applyF unc); void multiApply(std::deque<BSONObj>& ops, MultiSyncApplyFunc applyF unc);
private: private:
BackgroundSyncInterface* _networkQueue; BackgroundSyncInterface* _networkQueue;
// Doles out all the work to the reader pool threads and waits for them to complete // Doles out all the work to the reader pool threads and waits for them to complete
void prefetchOps(const std::deque<BSONObj>& ops); void prefetchOps(const std::deque<BSONObj>& ops);
 End of changes. 4 change blocks. 
3 lines changed or deleted 20 lines changed or added


 shard.h   shard.h 
skipping to change at line 21 skipping to change at line 21
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details. * GNU Affero General Public License for more details.
* *
* You should have received a copy of the GNU Affero General Public Licen se * You should have received a copy of the GNU Affero General Public Licen se
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#pragma once #pragma once
#include "pch.h" #include "mongo/pch.h"
#include "mongo/client/connpool.h" #include "mongo/client/connpool.h"
namespace mongo { namespace mongo {
class ShardConnection; class ShardConnection;
class ShardStatus; class ShardStatus;
/* /*
* A "shard" one partition of the overall database (and a replica set t ypically). * A "shard" one partition of the overall database (and a replica set t ypically).
 End of changes. 1 change blocks. 
1 lines changed or deleted 1 lines changed or added


 snapshots.h   snapshots.h 
skipping to change at line 20 skipping to change at line 20
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details. * GNU Affero General Public License for more details.
* *
* You should have received a copy of the GNU Affero General Public Licen se * You should have received a copy of the GNU Affero General Public Licen se
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#pragma once #pragma once
#include "../../pch.h" #include "mongo/pch.h"
#include "../jsobj.h" #include "../jsobj.h"
#include "top.h" #include "top.h"
#include "../../util/background.h" #include "../../util/background.h"
/** /**
handles snapshotting performance metrics and other such things handles snapshotting performance metrics and other such things
*/ */
namespace mongo { namespace mongo {
class SnapshotThread; class SnapshotThread;
 End of changes. 1 change blocks. 
1 lines changed or deleted 1 lines changed or added


 sock.h   sock.h 
skipping to change at line 20 skipping to change at line 20
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or impli ed. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or impli ed.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#pragma once #pragma once
#include "../../pch.h" #include "mongo/pch.h"
#include <stdio.h> #include <stdio.h>
#ifndef _WIN32 #ifndef _WIN32
#include <sys/socket.h> #include <sys/socket.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <sys/un.h> #include <sys/un.h>
#include <errno.h> #include <errno.h>
skipping to change at line 136 skipping to change at line 136
string getHostNameCached(); string getHostNameCached();
/** /**
* thrown by Socket and SockAddr * thrown by Socket and SockAddr
*/ */
class SocketException : public DBException { class SocketException : public DBException {
public: public:
const enum Type { CLOSED , RECV_ERROR , SEND_ERROR, RECV_TIMEOUT, S END_TIMEOUT, FAILED_STATE, CONNECT_ERROR } _type; const enum Type { CLOSED , RECV_ERROR , SEND_ERROR, RECV_TIMEOUT, S END_TIMEOUT, FAILED_STATE, CONNECT_ERROR } _type;
SocketException( Type t , string server , int code = 9001 , string extra="" ) SocketException( Type t , string server , int code = 9001 , string extra="" )
: DBException( "socket exception" , code ) , _type(t) , _server : DBException( (string)"socket exception [" + _getStringType(
(server), _extra(extra){ } t ) + "] for " + server, code ),
_type(t),
_server(server),
_extra(extra)
{}
virtual ~SocketException() throw() {} virtual ~SocketException() throw() {}
bool shouldPrint() const { return _type != CLOSED; } bool shouldPrint() const { return _type != CLOSED; }
virtual string toString() const; virtual string toString() const;
private: private:
// TODO: Allow exceptions better control over their messages
static string _getStringType( Type t ){
switch (t) {
case CLOSED: return "CLOSED";
case RECV_ERROR: return "RECV_ERROR";
case SEND_ERROR: return "SEND_ERROR";
case RECV_TIMEOUT: return "RECV_TIMEOUT";
case SEND_TIMEOUT: return "SEND_TIMEOUT";
case FAILED_STATE: return "FAILED_STATE";
case CONNECT_ERROR: return "CONNECT_ERROR";
default: return "UNKNOWN"; // should never happe
n
}
}
string _server; string _server;
string _extra; string _extra;
}; };
#ifdef MONGO_SSL #ifdef MONGO_SSL
class SSLManager : boost::noncopyable { class SSLManager : boost::noncopyable {
public: public:
SSLManager( bool client ); SSLManager( bool client );
void setupPEM( const string& keyFile , const string& password ); /** @return true if was successful, otherwise false */
bool setupPEM( const string& keyFile , const string& password );
void setupPubPriv( const string& privateKeyFile , const string& pub licKeyFile ); void setupPubPriv( const string& privateKeyFile , const string& pub licKeyFile );
/** /**
* creates an SSL context to be used for this file descriptor * creates an SSL context to be used for this file descriptor
* caller should delete * caller should delete
*/ */
SSL * secure( int fd ); SSL * secure( int fd );
static int password_cb( char *buf,int num, int rwflag,void *userdat a ); static int password_cb( char *buf,int num, int rwflag,void *userdat a );
skipping to change at line 213 skipping to change at line 234
SockAddr remoteAddr() const { return _remote; } SockAddr remoteAddr() const { return _remote; }
string remoteString() const { return _remote.toString(); } string remoteString() const { return _remote.toString(); }
unsigned remotePort() const { return _remote.getPort(); } unsigned remotePort() const { return _remote.getPort(); }
void clearCounters() { _bytesIn = 0; _bytesOut = 0; } void clearCounters() { _bytesIn = 0; _bytesOut = 0; }
long long getBytesIn() const { return _bytesIn; } long long getBytesIn() const { return _bytesIn; }
long long getBytesOut() const { return _bytesOut; } long long getBytesOut() const { return _bytesOut; }
void setTimeout( double secs ); void setTimeout( double secs );
bool stillConnected();
#ifdef MONGO_SSL #ifdef MONGO_SSL
/** secures inline */ /** secures inline */
void secure( SSLManager * ssl ); void secure( SSLManager * ssl );
void secureAccepted( SSLManager * ssl ); void secureAccepted( SSLManager * ssl );
#endif #endif
/** /**
* call this after a fork for server sockets * call this after a fork for server sockets
*/ */
 End of changes. 5 change blocks. 
6 lines changed or deleted 26 lines changed or added


 stacktrace.h   stacktrace.h 
// Copyright 2009. 10gen, Inc. // Copyright 2009. 10gen, Inc.
/** /**
* Tools for working with in-process stack traces. * Tools for working with in-process stack traces.
*/ */
#pragma once #pragma once
#include <iostream> #include <iostream>
#include "mongo/platform/basic.h"
namespace mongo { namespace mongo {
// Print stack trace information to "os", default to std::cout. // Print stack trace information to "os", default to std::cout.
void printStackTrace(std::ostream &os=std::cout); void printStackTrace(std::ostream &os=std::cout);
#if defined(_WIN32)
// Print stack trace (using a specified stack context) to "os", default
to std::cout.
void printWindowsStackTrace(CONTEXT &context, std::ostream &os=std::cou
t);
#endif
} // namespace mongo } // namespace mongo
 End of changes. 2 change blocks. 
0 lines changed or deleted 9 lines changed or added


 stat_util.h   stat_util.h 
skipping to change at line 21 skipping to change at line 21
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details. * GNU Affero General Public License for more details.
* *
* You should have received a copy of the GNU Affero General Public Lice nse * You should have received a copy of the GNU Affero General Public Lice nse
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#pragma once #pragma once
#include "../pch.h" #include "mongo/pch.h"
#include "../db/jsobj.h" #include "../db/jsobj.h"
namespace mongo { namespace mongo {
struct NamespaceInfo { struct NamespaceInfo {
string ns; string ns;
// these need to be in millis // these need to be in millis
long long read; long long read;
long long write; long long write;
 End of changes. 1 change blocks. 
1 lines changed or deleted 1 lines changed or added


 stats.h   stats.h 
skipping to change at line 21 skipping to change at line 21
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details. * GNU Affero General Public License for more details.
* *
* You should have received a copy of the GNU Affero General Public Lice nse * You should have received a copy of the GNU Affero General Public Lice nse
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#pragma once #pragma once
#include "../pch.h" #include "mongo/pch.h"
#include "../db/stats/counters.h" #include "../db/stats/counters.h"
namespace mongo { namespace mongo {
extern OpCounters opsNonSharded; extern OpCounters opsNonSharded;
extern OpCounters opsSharded; extern OpCounters opsSharded;
extern GenericCounter shardedCursorTypes; extern GenericCounter shardedCursorTypes;
} }
 End of changes. 1 change blocks. 
1 lines changed or deleted 1 lines changed or added


 str.h   str.h 
skipping to change at line 109 skipping to change at line 109
/** find string x, and return rest of string thereafter, or "" if n ot found */ /** find string x, and return rest of string thereafter, or "" if n ot found */
inline const char * after(const char *s, const char *x) { inline const char * after(const char *s, const char *x) {
const char *p = strstr(s, x); const char *p = strstr(s, x);
return (p != 0) ? p+strlen(x) : ""; return (p != 0) ? p+strlen(x) : "";
} }
inline string after(string s, string x) { inline string after(string s, string x) {
const char *p = strstr(s.c_str(), x.c_str()); const char *p = strstr(s.c_str(), x.c_str());
return (p != 0) ? string(p+x.size()) : ""; return (p != 0) ? string(p+x.size()) : "";
} }
/** @return true if s contains x */ /** @return true if s contains x
* These should not be used with strings containing NUL bytes
*/
inline bool contains(string s, string x) { inline bool contains(string s, string x) {
return strstr(s.c_str(), x.c_str()) != 0; return strstr(s.c_str(), x.c_str()) != 0;
} }
inline bool contains(string s, char x) { inline bool contains(string s, char x) {
verify(x != '\0'); // this expects c-strings so don't use when looking for NUL bytes
return strchr(s.c_str(), x) != 0; return strchr(s.c_str(), x) != 0;
} }
/** @return everything before the character x, else entire string * / /** @return everything before the character x, else entire string * /
inline string before(const string& s, char x) { inline string before(const string& s, char x) {
const char *p = strchr(s.c_str(), x); const char *p = strchr(s.c_str(), x);
return (p != 0) ? s.substr(0, p-s.c_str()) : s; return (p != 0) ? s.substr(0, p-s.c_str()) : s;
} }
/** @return everything before the string x, else entire string */ /** @return everything before the string x, else entire string */
 End of changes. 2 change blocks. 
1 lines changed or deleted 4 lines changed or added


 strategy.h   strategy.h 
skipping to change at line 20 skipping to change at line 20
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details. * GNU Affero General Public License for more details.
* *
* You should have received a copy of the GNU Affero General Public Lice nse * You should have received a copy of the GNU Affero General Public Lice nse
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#pragma once #pragma once
#include "../pch.h" #include "mongo/pch.h"
#include "chunk.h" #include "chunk.h"
#include "request.h" #include "request.h"
namespace mongo { namespace mongo {
class Strategy { class Strategy {
public: public:
Strategy() {} Strategy() {}
virtual ~Strategy() {} virtual ~Strategy() {}
virtual void queryOp( Request& r ) = 0; virtual void queryOp( Request& r ) = 0;
 End of changes. 1 change blocks. 
1 lines changed or deleted 1 lines changed or added


 string_writer.h   string_writer.h 
skipping to change at line 19 skipping to change at line 19
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details. * GNU Affero General Public License for more details.
* *
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#pragma once #pragma once
#include "pch.h" #include "mongo/pch.h"
namespace mongo { namespace mongo {
class StringWriter { class StringWriter {
public: public:
virtual ~StringWriter() {}; virtual ~StringWriter() {};
virtual void writeString(stringstream &ss) const = 0; virtual void writeString(stringstream &ss) const = 0;
}; };
} }
 End of changes. 1 change blocks. 
1 lines changed or deleted 1 lines changed or added


 stringdata.h   stringdata.h 
skipping to change at line 41 skipping to change at line 41
* *
* Note that the object StringData wraps around must be alive while the StringData * Note that the object StringData wraps around must be alive while the StringData
* is. * is.
*/ */
class StringData { class StringData {
public: public:
/** Construct a StringData, for the case where the length of /** Construct a StringData, for the case where the length of
* string is not known. 'c' must be a pointer to a null-terminated string. * string is not known. 'c' must be a pointer to a null-terminated string.
*/ */
StringData( const char* c ) StringData( const char* c )
: _data(c), _size((unsigned) strlen(c)) {} : _data(c), _size(string::npos){}
/** Construct a StringData explicitly, for the case where the lengt h of the string /** Construct a StringData explicitly, for the case where the lengt h of the string
* is already known. 'c' must be a pointer to a null-terminated str ing, and strlenOfc * is already known. 'c' must be a pointer to a null-terminated str ing, and strlenOfc
* must be the length that strlen(c) would return, a.k.a the index of the * must be the length that strlen(c) would return, a.k.a the index of the
* terminator in c. * terminator in c.
*/ */
StringData( const char* c, unsigned len ) StringData( const char* c, size_t len )
: _data(c), _size(len) {} : _data(c), _size(len) {}
/** Construct a StringData, for the case of a string. */ /** Construct a StringData, for the case of a string. */
StringData( const std::string& s ) StringData( const std::string& s )
: _data(s.c_str()), _size((unsigned) s.size()) {} : _data(s.c_str()), _size(s.size()) {}
// Construct a StringData explicitly, for the case of a literal who se size is // Construct a StringData explicitly, for the case of a literal who se size is
// known at compile time. // known at compile time.
struct LiteralTag {}; struct LiteralTag {};
template<size_t N> template<size_t N>
StringData( const char (&val)[N], LiteralTag ) StringData( const char (&val)[N], LiteralTag )
: _data(&val[0]), _size(N-1) {} : _data(&val[0]), _size(N-1) {}
// accessors // accessors
const char* data() const { return _data; } const char* data() const { return _data; }
unsigned size() const { return _size; } size_t size() const {
if ( _size == string::npos )
_size = strlen( _data );
return _size;
}
private: private:
const char* const _data; // is always null terminated const char* const _data; // is always null terminated
const unsigned _size; // 'size' does not include the null termi nator mutable size_t _size; // 'size' does not include the null terminat or
}; };
} // namespace mongo } // namespace mongo
 End of changes. 5 change blocks. 
5 lines changed or deleted 9 lines changed or added


 threadlocal.h   threadlocal.h 
skipping to change at line 21 skipping to change at line 21
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details. * GNU Affero General Public License for more details.
* *
* You should have received a copy of the GNU Affero General Public Licen se * You should have received a copy of the GNU Affero General Public Licen se
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "mongo/client/undef_macros.h" #include "mongo/client/undef_macros.h"
#include <boost/thread/tss.hpp> #include <boost/thread/tss.hpp>
#include <boost/bind.hpp>
#include "mongo/client/redef_macros.h" #include "mongo/client/redef_macros.h"
namespace mongo { namespace mongo {
using boost::thread_specific_ptr; using boost::thread_specific_ptr;
/* thread local "value" rather than a pointer /* thread local "value" rather than a pointer
good for things which have copy constructors (and the copy construct or is fast enough) good for things which have copy constructors (and the copy construct or is fast enough)
e.g. e.g.
ThreadLocalValue<int> myint; ThreadLocalValue<int> myint;
skipping to change at line 118 skipping to change at line 119
# define TSP_DEFINE(T,p) \ # define TSP_DEFINE(T,p) \
__thread T* _ ## p; \ __thread T* _ ## p; \
template<> void TSP<T>::reset(T* v) { \ template<> void TSP<T>::reset(T* v) { \
tsp.reset(v); \ tsp.reset(v); \
_ ## p = v; \ _ ## p = v; \
} \ } \
TSP<T> p; TSP<T> p;
# endif # endif
#elif defined(__APPLE__)
template< class T>
struct TSP {
pthread_key_t _key;
public:
TSP() {
verify( pthread_key_create( &_key, TSP::dodelete ) == 0 );
}
~TSP() {
pthread_key_delete( _key );
}
static void dodelete( void* x ) {
T* t = reinterpret_cast<T*>(x);
delete t;
}
T* get() const {
return reinterpret_cast<T*>( pthread_getspecific( _key ) );
}
void reset(T* v) {
T* old = get();
delete old;
verify( pthread_setspecific( _key, v ) == 0 );
}
T* getMake() {
T *t = get();
if( t == 0 ) {
t = new T();
reset( t );
}
return t;
}
};
# define TSP_DECLARE(T,p) extern TSP<T> p;
# define TSP_DEFINE(T,p) TSP<T> p;
#else #else
template< class T > template< class T >
struct TSP { struct TSP {
thread_specific_ptr<T> tsp; thread_specific_ptr<T> tsp;
public: public:
T* get() const { return tsp.get(); } T* get() const { return tsp.get(); }
void reset(T* v) { tsp.reset(v); } void reset(T* v) { tsp.reset(v); }
T* getMake() { T* getMake() {
T *t = get(); T *t = get();
 End of changes. 2 change blocks. 
0 lines changed or deleted 43 lines changed or added


 time_support.h   time_support.h 
skipping to change at line 22 skipping to change at line 22
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or impli ed. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or impli ed.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#pragma once #pragma once
#include <ctime> #include <ctime>
#include <string> #include <string>
#include <boost/thread/xtime.hpp>
#include <boost/date_time/posix_time/posix_time.hpp> #include <boost/date_time/posix_time/posix_time.hpp>
#include "mongo/bson/util/misc.h" // Date_t #include "mongo/bson/util/misc.h" // Date_t
namespace mongo { namespace mongo {
void time_t_to_Struct(time_t t, struct tm * buf , bool local = false ); void time_t_to_Struct(time_t t, struct tm * buf , bool local = false );
// uses ISO 8601 dates without trailing Z // uses ISO 8601 dates without trailing Z
// colonsOk should be false when creating filenames // colonsOk should be false when creating filenames
skipping to change at line 45 skipping to change at line 46
boost::gregorian::date currentDate(); boost::gregorian::date currentDate();
// parses time of day in "hh:mm" format assuming 'hh' is 00-23 // parses time of day in "hh:mm" format assuming 'hh' is 00-23
bool toPointInTime( const std::string& str , boost::posix_time::ptime* timeOfDay ); bool toPointInTime( const std::string& str , boost::posix_time::ptime* timeOfDay );
void sleepsecs(int s); void sleepsecs(int s);
void sleepmillis(long long ms); void sleepmillis(long long ms);
void sleepmicros(long long micros); void sleepmicros(long long micros);
class Backoff {
public:
Backoff( int maxSleepMillis, int resetAfter ) :
_maxSleepMillis( maxSleepMillis ),
_resetAfterMillis( maxSleepMillis + resetAfter ), // Don't rese
t < the max sleep
_lastSleepMillis( 0 ),
_lastErrorTimeMillis( 0 )
{}
void nextSleepMillis();
private:
// Parameters
int _maxSleepMillis;
int _resetAfterMillis;
// Last sleep information
int _lastSleepMillis;
unsigned long long _lastErrorTimeMillis;
};
// DO NOT TOUCH except for testing // DO NOT TOUCH except for testing
void jsTimeVirtualSkew( long long skew ); void jsTimeVirtualSkew( long long skew );
void jsTimeVirtualThreadSkew( long long skew ); void jsTimeVirtualThreadSkew( long long skew );
long long getJSTimeVirtualThreadSkew(); long long getJSTimeVirtualThreadSkew();
/** Date_t is milliseconds since epoch */ /** Date_t is milliseconds since epoch */
Date_t jsTime(); Date_t jsTime();
/** warning this will wrap */ /** warning this will wrap */
unsigned curTimeMicros(); unsigned curTimeMicros();
unsigned long long curTimeMicros64(); unsigned long long curTimeMicros64();
unsigned long long curTimeMillis64(); unsigned long long curTimeMillis64();
// these are so that if you use one of them compilation will fail // these are so that if you use one of them compilation will fail
char *asctime(const struct tm *tm); char *asctime(const struct tm *tm);
char *ctime(const time_t *timep); char *ctime(const time_t *timep);
struct tm *gmtime(const time_t *timep); struct tm *gmtime(const time_t *timep);
struct tm *localtime(const time_t *timep); struct tm *localtime(const time_t *timep);
#if defined(MONGO_BOOST_TIME_UTC_HACK) || (BOOST_VERSION >= 105000)
#define MONGO_BOOST_TIME_UTC boost::TIME_UTC_
#else
#define MONGO_BOOST_TIME_UTC boost::TIME_UTC
#endif
} // namespace mongo } // namespace mongo
 End of changes. 3 change blocks. 
0 lines changed or deleted 31 lines changed or added


 top.h   top.h 
skipping to change at line 67 skipping to change at line 67
UsageData getmore; UsageData getmore;
UsageData insert; UsageData insert;
UsageData update; UsageData update;
UsageData remove; UsageData remove;
UsageData commands; UsageData commands;
}; };
typedef map<string,CollectionData> UsageMap; typedef map<string,CollectionData> UsageMap;
public: public:
void record( const string& ns , int op , int lockType , long long m icros , bool command ); void record( const StringData& ns , int op , int lockType , long lo ng micros , bool command );
void append( BSONObjBuilder& b ); void append( BSONObjBuilder& b );
void cloneMap(UsageMap& out) const; void cloneMap(UsageMap& out) const;
CollectionData getGlobalData() const { return _global; } CollectionData getGlobalData() const { return _global; }
void collectionDropped( const string& ns ); void collectionDropped( const string& ns );
public: // static stuff public: // static stuff
static Top global; static Top global;
private: private:
void _appendToUsageMap( BSONObjBuilder& b , const UsageMap& map ) c onst; void _appendToUsageMap( BSONObjBuilder& b , const UsageMap& map ) c onst;
void _appendStatsEntry( BSONObjBuilder& b , const char * statsName , const UsageData& map ) const; void _appendStatsEntry( BSONObjBuilder& b , const char * statsName , const UsageData& map ) const;
void _record( CollectionData& c , int op , int lockType , long long micros , bool command ); void _record( CollectionData& c , int op , int lockType , long long micros , bool command );
mutable mongo::mutex _lock; mutable SimpleMutex _lock;
CollectionData _global; CollectionData _global;
UsageMap _usage; UsageMap _usage;
string _lastDropped; string _lastDropped;
}; };
} // namespace mongo } // namespace mongo
 End of changes. 2 change blocks. 
2 lines changed or deleted 2 lines changed or added


 trace.h   trace.h 
skipping to change at line 19 skipping to change at line 19
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details. * GNU Affero General Public License for more details.
* *
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#pragma once #pragma once
#include "pch.h" #include "mongo/pch.h"
#include <boost/unordered_map.hpp> #include <boost/unordered_map.hpp>
#include "util/concurrency/rwlock.h" #include "util/concurrency/rwlock.h"
namespace mongo { namespace mongo {
class Trace : class Trace :
public boost::noncopyable { public boost::noncopyable {
public: public:
 End of changes. 1 change blocks. 
1 lines changed or deleted 1 lines changed or added


 unittest.h   unittest.h 
skipping to change at line 112 skipping to change at line 112
private: \ private: \
virtual void _doTest(); \ virtual void _doTest(); \
\ \
static const RegistrationAgent<_TEST_TYPE_NAME(CASE_NAME, TEST_NAME ) > _agent; \ static const RegistrationAgent<_TEST_TYPE_NAME(CASE_NAME, TEST_NAME ) > _agent; \
}; \ }; \
const ::mongo::unittest::Test::RegistrationAgent<_TEST_TYPE_NAME(CASE_N AME, TEST_NAME) > \ const ::mongo::unittest::Test::RegistrationAgent<_TEST_TYPE_NAME(CASE_N AME, TEST_NAME) > \
_TEST_TYPE_NAME(CASE_NAME, TEST_NAME)::_agent(#CASE_NAME, #TEST _NAME); \ _TEST_TYPE_NAME(CASE_NAME, TEST_NAME)::_agent(#CASE_NAME, #TEST _NAME); \
void _TEST_TYPE_NAME(CASE_NAME, TEST_NAME)::_doTest() void _TEST_TYPE_NAME(CASE_NAME, TEST_NAME)::_doTest()
/** /**
* Construct a single test named TEST_NAME that has access to a common clas
s (a "fixture")
* named "FIXTURE_NAME".
*
* Usage:
*
* class FixtureClass : public mongo::unittest::Test {
* protected:
* int myVar;
* void setUp() { myVar = 10; }
* };
*
* TEST(FixtureClass, TestThatUsesFixture) {
* ASSERT_EQUALS(10, myVar);
* }
*/
#define TEST_F(FIXTURE_NAME, TEST_NAME) \
class _TEST_TYPE_NAME(FIXTURE_NAME, TEST_NAME) : public FIXTURE_NAME {
\
private: \
virtual void _doTest(); \
\
static const RegistrationAgent<_TEST_TYPE_NAME(FIXTURE_NAME, TEST_N
AME) > _agent; \
}; \
const ::mongo::unittest::Test::RegistrationAgent<_TEST_TYPE_NAME(FIXTUR
E_NAME, TEST_NAME) > \
_TEST_TYPE_NAME(FIXTURE_NAME, TEST_NAME)::_agent(#FIXTURE_NAME,
#TEST_NAME); \
void _TEST_TYPE_NAME(FIXTURE_NAME, TEST_NAME)::_doTest()
/**
* Macro to construct a type name for a test, from its "CASE_NAME" and "TES T_NAME". * Macro to construct a type name for a test, from its "CASE_NAME" and "TES T_NAME".
* Do not use directly in test code. * Do not use directly in test code.
*/ */
#define _TEST_TYPE_NAME(CASE_NAME, TEST_NAME) \ #define _TEST_TYPE_NAME(CASE_NAME, TEST_NAME) \
UnitTest__##CASE_NAME##__##TEST_NAME UnitTest__##CASE_NAME##__##TEST_NAME
namespace mongo { namespace mongo {
namespace unittest { namespace unittest {
skipping to change at line 150 skipping to change at line 177
std::string getName() const { return _name; } std::string getName() const { return _name; }
private: private:
std::string _name; std::string _name;
TestFunction _fn; TestFunction _fn;
}; };
/** /**
* Base type for unit test fixtures. Also, the default fixture typ e used * Base type for unit test fixtures. Also, the default fixture typ e used
* by the TEST() macro. * by the TEST() macro.
*
* TODO(schwerin): Implement a TEST_F macro that allows testers to
specify
* different subclasses of Test to be used as the test fixture. Th
ese subclasses
* could then provide per-test set-up and tear-down code by overrid
ing the
* setUp and tearDown methods.
*/ */
class Test : private boost::noncopyable { class Test : private boost::noncopyable {
public: public:
Test(); Test();
virtual ~Test(); virtual ~Test();
void run(); void run();
protected: protected:
/** /**
* Registration agent for adding tests to suites, used by TEST macro. * Registration agent for adding tests to suites, used by TEST macro.
*/ */
template <typename T> template <typename T>
class RegistrationAgent : private boost::noncopyable { class RegistrationAgent : private boost::noncopyable {
public: public:
RegistrationAgent(const std::string& suiteName, const std:: string& testName); RegistrationAgent(const std::string& suiteName, const std:: string& testName);
}; };
/**
* This exception class is used to exercise the testing framewo
rk itself. If a test
* case throws it, the framework would not consider it an error
.
*/
class FixtureExceptionForTesting : public std::exception {
};
private: private:
/** /**
* Called on the test object before running the test. * Called on the test object before running the test.
*/ */
virtual void setUp(); virtual void setUp();
/** /**
* Called on the test object after running the test. * Called on the test object after running the test.
*/ */
virtual void tearDown(); virtual void tearDown();
 End of changes. 3 change blocks. 
8 lines changed or deleted 41 lines changed or added


 update.h   update.h 
skipping to change at line 19 skipping to change at line 19
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details. * GNU Affero General Public License for more details.
* *
* You should have received a copy of the GNU Affero General Public Lice nse * You should have received a copy of the GNU Affero General Public Lice nse
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "pch.h" #include "mongo/pch.h"
#include "mongo/db/jsobj.h" #include "mongo/db/jsobj.h"
#include "mongo/db/curop.h" #include "mongo/db/curop.h"
#include "mongo/db/queryoptimizercursor.h" #include "mongo/db/queryoptimizercursor.h"
namespace mongo { namespace mongo {
// ---------- public ------------- // ---------- public -------------
struct UpdateResult { struct UpdateResult {
 End of changes. 1 change blocks. 
1 lines changed or deleted 1 lines changed or added


 update_internal.h   update_internal.h 
skipping to change at line 19 skipping to change at line 19
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details. * GNU Affero General Public License for more details.
* *
* You should have received a copy of the GNU Affero General Public Lice nse * You should have received a copy of the GNU Affero General Public Lice nse
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "pch.h" #include "mongo/pch.h"
#include "mongo/bson/bson_builder_base.h" #include "mongo/bson/bson_builder_base.h"
#include "mongo/db/jsobj.h" #include "mongo/db/jsobj.h"
#include "mongo/db/jsobjmanipulator.h" #include "mongo/db/jsobjmanipulator.h"
#include "mongo/db/matcher.h" #include "mongo/db/matcher.h"
#include "mongo/util/embedded_builder.h" #include "mongo/util/embedded_builder.h"
#include "mongo/util/stringutils.h" #include "mongo/util/stringutils.h"
namespace mongo { namespace mongo {
 End of changes. 1 change blocks. 
1 lines changed or deleted 1 lines changed or added


 v8_db.h   v8_db.h 
skipping to change at line 48 skipping to change at line 48
// Mongo members // Mongo members
v8::Handle<v8::Value> mongoConsLocal(V8Scope* scope, const v8::Argument s& args); v8::Handle<v8::Value> mongoConsLocal(V8Scope* scope, const v8::Argument s& args);
v8::Handle<v8::Value> mongoConsExternal(V8Scope* scope, const v8::Argum ents& args); v8::Handle<v8::Value> mongoConsExternal(V8Scope* scope, const v8::Argum ents& args);
v8::Handle<v8::Value> mongoFind(V8Scope* scope, const v8::Arguments& ar gs); v8::Handle<v8::Value> mongoFind(V8Scope* scope, const v8::Arguments& ar gs);
v8::Handle<v8::Value> mongoInsert(V8Scope* scope, const v8::Arguments& args); v8::Handle<v8::Value> mongoInsert(V8Scope* scope, const v8::Arguments& args);
v8::Handle<v8::Value> mongoRemove(V8Scope* scope, const v8::Arguments& args); v8::Handle<v8::Value> mongoRemove(V8Scope* scope, const v8::Arguments& args);
v8::Handle<v8::Value> mongoUpdate(V8Scope* scope, const v8::Arguments& args); v8::Handle<v8::Value> mongoUpdate(V8Scope* scope, const v8::Arguments& args);
v8::Handle<v8::Value> mongoAuth(V8Scope* scope, const v8::Arguments& ar gs); v8::Handle<v8::Value> mongoAuth(V8Scope* scope, const v8::Arguments& ar gs);
v8::Handle<v8::Value> mongoLogout(V8Scope* scope, const v8::Arguments& args);
v8::Handle<v8::Value> internalCursorCons(V8Scope* scope, const v8::Argu ments& args); v8::Handle<v8::Value> internalCursorCons(V8Scope* scope, const v8::Argu ments& args);
v8::Handle<v8::Value> internalCursorNext(V8Scope* scope, const v8::Argu ments& args); v8::Handle<v8::Value> internalCursorNext(V8Scope* scope, const v8::Argu ments& args);
v8::Handle<v8::Value> internalCursorHasNext(V8Scope* scope, const v8::A rguments& args); v8::Handle<v8::Value> internalCursorHasNext(V8Scope* scope, const v8::A rguments& args);
v8::Handle<v8::Value> internalCursorObjsLeftInBatch(V8Scope* scope, con st v8::Arguments& args); v8::Handle<v8::Value> internalCursorObjsLeftInBatch(V8Scope* scope, con st v8::Arguments& args);
v8::Handle<v8::Value> internalCursorReadOnly(V8Scope* scope, const v8:: Arguments& args); v8::Handle<v8::Value> internalCursorReadOnly(V8Scope* scope, const v8:: Arguments& args);
// DB members // DB members
v8::Handle<v8::Value> dbInit(V8Scope* scope, const v8::Arguments& args) ; v8::Handle<v8::Value> dbInit(V8Scope* scope, const v8::Arguments& args) ;
 End of changes. 1 change blocks. 
0 lines changed or deleted 1 lines changed or added


 value.h   value.h 
skipping to change at line 19 skipping to change at line 19
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details. * GNU Affero General Public License for more details.
* *
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#pragma once #pragma once
#include "pch.h" #include "mongo/pch.h"
#include "bson/bsontypes.h" #include "bson/bsontypes.h"
#include "bson/oid.h" #include "bson/oid.h"
#include "util/intrusive_counter.h" #include "util/intrusive_counter.h"
#include "util/optime.h"
namespace mongo { namespace mongo {
class BSONElement; class BSONElement;
class Builder; class Builder;
class Document; class Document;
class Value; class Value;
class ValueIterator : class ValueIterator :
public IntrusiveCounterUnsigned { public IntrusiveCounterUnsigned {
public: public:
skipping to change at line 82 skipping to change at line 83
For commonly used values, consider using one of the singleton For commonly used values, consider using one of the singleton
instances defined below. instances defined below.
@param value the value @param value the value
@returns a Value with the given value @returns a Value with the given value
*/ */
static intrusive_ptr<const Value> createInt(int value); static intrusive_ptr<const Value> createInt(int value);
/* /*
Construct a long or interger-valued Value.
Used when preforming arithmetic operations with int where the res
ult may be too large
and need to be stored as long. The Value will be an int if value
fits, otherwise it
will be a long.
@param value the value
@returns a Value with the given value
*/
static intrusive_ptr<const Value> createIntOrLong(long long value);
/*
Construct an long(long)-valued Value. Construct an long(long)-valued Value.
For commonly used values, consider using one of the singleton For commonly used values, consider using one of the singleton
instances defined below. instances defined below.
@param value the value @param value the value
@returns a Value with the given value @returns a Value with the given value
*/ */
static intrusive_ptr<const Value> createLong(long long value); static intrusive_ptr<const Value> createLong(long long value);
skipping to change at line 114 skipping to change at line 126
@returns a Value with the given value @returns a Value with the given value
*/ */
static intrusive_ptr<const Value> createString(const string &value) ; static intrusive_ptr<const Value> createString(const string &value) ;
/* /*
Construct a date-valued Value. Construct a date-valued Value.
@param value the value @param value the value
@returns a Value with the given value @returns a Value with the given value
*/ */
static intrusive_ptr<const Value> createDate(const Date_t &value); static intrusive_ptr<const Value> createDate(const long long &value
);
static intrusive_ptr<const Value> createTimestamp(const OpTime& val
ue);
/* /*
Construct a document-valued Value. Construct a document-valued Value.
@param value the value @param value the value
@returns a Value with the given value @returns a Value with the given value
*/ */
static intrusive_ptr<const Value> createDocument( static intrusive_ptr<const Value> createDocument(
const intrusive_ptr<Document> &pDocument); const intrusive_ptr<Document> &pDocument);
skipping to change at line 155 skipping to change at line 169
@returns the Value's value; asserts if the requested value type i s @returns the Value's value; asserts if the requested value type i s
incorrect. incorrect.
*/ */
double getDouble() const; double getDouble() const;
string getString() const; string getString() const;
intrusive_ptr<Document> getDocument() const; intrusive_ptr<Document> getDocument() const;
intrusive_ptr<ValueIterator> getArray() const; intrusive_ptr<ValueIterator> getArray() const;
OID getOid() const; OID getOid() const;
bool getBool() const; bool getBool() const;
Date_t getDate() const; long long getDate() const;
OpTime getTimestamp() const;
string getRegex() const; string getRegex() const;
string getSymbol() const; string getSymbol() const;
int getInt() const; int getInt() const;
unsigned long long getTimestamp() const;
long long getLong() const; long long getLong() const;
/* /*
Get the length of an array value. Get the length of an array value.
@returns the length of the array, if this is array-valued; otherw ise @returns the length of the array, if this is array-valued; otherw ise
throws an error throws an error
*/ */
size_t getArrayLength() const; size_t getArrayLength() const;
skipping to change at line 193 skipping to change at line 207
Get references to singleton instances of commonly used field valu es. Get references to singleton instances of commonly used field valu es.
*/ */
static intrusive_ptr<const Value> getUndefined(); static intrusive_ptr<const Value> getUndefined();
static intrusive_ptr<const Value> getNull(); static intrusive_ptr<const Value> getNull();
static intrusive_ptr<const Value> getTrue(); static intrusive_ptr<const Value> getTrue();
static intrusive_ptr<const Value> getFalse(); static intrusive_ptr<const Value> getFalse();
static intrusive_ptr<const Value> getMinusOne(); static intrusive_ptr<const Value> getMinusOne();
static intrusive_ptr<const Value> getZero(); static intrusive_ptr<const Value> getZero();
static intrusive_ptr<const Value> getOne(); static intrusive_ptr<const Value> getOne();
/* /**
Coerce (cast) a value to a native bool, using JSON rules. * Coerce (cast) a value to a native bool using BSONElement::trueVa
lue() rules, but with
@returns the bool value * some types unsupported. SERVER-6120
*/ * @return the bool value
*/
bool coerceToBool() const; bool coerceToBool() const;
/* /*
Coerce (cast) a value to a Boolean Value, using JSON rules.
@returns the Boolean Value value
*/
intrusive_ptr<const Value> coerceToBoolean() const;
/*
Coerce (cast) a value to an int, using JSON rules. Coerce (cast) a value to an int, using JSON rules.
@returns the int value @returns the int value
*/ */
int coerceToInt() const; int coerceToInt() const;
/* /*
Coerce (cast) a value to a long long, using JSON rules. Coerce (cast) a value to a long long, using JSON rules.
@returns the long value @returns the long value
skipping to change at line 233 skipping to change at line 240
@returns the double value @returns the double value
*/ */
double coerceToDouble() const; double coerceToDouble() const;
/* /*
Coerce (cast) a value to a date, using JSON rules. Coerce (cast) a value to a date, using JSON rules.
@returns the date value @returns the date value
*/ */
Date_t coerceToDate() const; long long coerceToDate() const;
time_t coerceToTimeT() const;
tm coerceToTm() const; // broken-out time struct (see man gmtime)
OpTime coerceToTimestamp() const;
/* /*
Coerce (cast) a value to a string, using JSON rules. Coerce (cast) a value to a string, using JSON rules.
@returns the date value @returns the date value
*/ */
string coerceToString() const; string coerceToString() const;
/* /*
Compare two Values. Compare two Values.
skipping to change at line 306 skipping to change at line 317
Value(BSONType type); // creates an empty (unitialized value) of ty pe Value(BSONType type); // creates an empty (unitialized value) of ty pe
// mostly useful for Undefi ned // mostly useful for Undefi ned
Value(bool boolValue); Value(bool boolValue);
Value(int intValue); Value(int intValue);
private: private:
Value(BSONElement *pBsonElement); Value(BSONElement *pBsonElement);
Value(long long longValue); Value(long long longValue);
Value(double doubleValue); Value(double doubleValue);
Value(const Date_t &dateValue); Value(const OpTime& timestampValue);
Value(const string &stringValue); Value(const string &stringValue);
Value(const intrusive_ptr<Document> &pDocument); Value(const intrusive_ptr<Document> &pDocument);
Value(const vector<intrusive_ptr<const Value> > &vpValue); Value(const vector<intrusive_ptr<const Value> > &vpValue);
void addToBson(Builder *pBuilder) const; void addToBson(Builder *pBuilder) const;
BSONType type; BSONType type;
/* store value in one of these */ // store values that don't need a ctor/dtor in one of these
union { union {
double doubleValue; double doubleValue;
bool boolValue; bool boolValue;
int intValue; int intValue;
unsigned long long timestampValue;
long long longValue; long long longValue;
ReplTime timestampValue;
unsigned char oidValue[12];
// The member below is redundant, but useful for clarity and se
archability.
long long dateValue;
};
} simple; // values that don't need a ctor/dtor
OID oidValue;
Date_t dateValue;
string stringValue; // String, Regex, Symbol string stringValue; // String, Regex, Symbol
intrusive_ptr<Document> pDocumentValue; intrusive_ptr<Document> pDocumentValue;
vector<intrusive_ptr<const Value> > vpValue; // for arrays vector<intrusive_ptr<const Value> > vpValue; // for arrays
/* /*
These are often used as the result of boolean or comparison These are often used as the result of boolean or comparison
expressions. expressions.
These are obtained via public static getters defined above. These are obtained via public static getters defined above.
*/ */
 End of changes. 14 change blocks. 
23 lines changed or deleted 41 lines changed or added


 writeback_listener.h   writeback_listener.h 
skipping to change at line 21 skipping to change at line 21
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details. * GNU Affero General Public License for more details.
* *
* You should have received a copy of the GNU Affero General Public Licen se * You should have received a copy of the GNU Affero General Public Licen se
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#pragma once #pragma once
#include "../pch.h" #include "mongo/pch.h"
#include "../client/connpool.h" #include "../client/connpool.h"
#include "../util/background.h" #include "../util/background.h"
#include "../db/client.h" #include "../db/client.h"
namespace mongo { namespace mongo {
/* /*
* The writeback listener takes back write attempts that were made agai nst a wrong shard. * The writeback listener takes back write attempts that were made agai nst a wrong shard.
* (Wrong here in the sense that the target chunk moved before this mon gos had a chance to * (Wrong here in the sense that the target chunk moved before this mon gos had a chance to
 End of changes. 1 change blocks. 
1 lines changed or deleted 1 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/