counters.h   counters.h 
// Copyright 2012 the V8 project authors. All rights reserved. // counters.h
// Redistribution and use in source and binary forms, with or without /*
// modification, are permitted provided that the following conditions are * Copyright (C) 2010 10gen Inc.
// met: *
// * This program is free software: you can redistribute it and/or modify
// * Redistributions of source code must retain the above copyright * it under the terms of the GNU Affero General Public License, version
// notice, this list of conditions and the following disclaimer. 3,
// * Redistributions in binary form must reproduce the above * as published by the Free Software Foundation.
// copyright notice, this list of conditions and the following *
// disclaimer in the documentation and/or other materials provided * This program is distributed in the hope that it will be useful,
// with the distribution. * but WITHOUT ANY WARRANTY; without even the implied warranty of
// * Neither the name of Google Inc. nor the names of its * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// contributors may be used to endorse or promote products derived * GNU Affero General Public License for more details.
// from this software without specific prior written permission. *
// * You should have received a copy of the GNU Affero General Public Lice
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS nse
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * along with this program. If not, see <http://www.gnu.org/licenses/>.
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR */
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, #pragma once
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, #include "mongo/pch.h"
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY #include "../jsobj.h"
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT #include "../../util/net/message.h"
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE #include "../../util/processinfo.h"
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "../../util/concurrency/spin_lock.h"
#include "mongo/db/pdfile.h"
#ifndef V8_COUNTERS_H_
#define V8_COUNTERS_H_ namespace mongo {
#include "../include/v8.h" /**
#include "allocation.h" * for storing operation counters
* note: not thread safe. ok with that for speed
namespace v8 { */
namespace internal { class OpCounters {
public:
// StatsCounters is an interface for plugging into external
// counters for monitoring. Counters can be looked up and OpCounters();
// manipulated by name. void incInsertInWriteLock(int n) { _insert.x += n; }
void gotInsert() { _insert++; }
class StatsTable { void gotQuery() { _query++; }
public: void gotUpdate() { _update++; }
// Register an application-defined function where void gotDelete() { _delete++; }
// counters can be looked up. void gotGetMore() { _getmore++; }
void SetCounterFunction(CounterLookupCallback f) { void gotCommand() { _command++; }
lookup_function_ = f;
} void gotOp( int op , bool isCommand );
// Register an application-defined function to create BSONObj getObj() const;
// a histogram for passing to the AddHistogramSample function
void SetCreateHistogramFunction(CreateHistogramCallback f) { // thse are used by snmp, and other things, do not remove
create_histogram_function_ = f; const AtomicUInt * getInsert() const { return &_insert; }
} const AtomicUInt * getQuery() const { return &_query; }
const AtomicUInt * getUpdate() const { return &_update; }
// Register an application-defined function to add a sample const AtomicUInt * getDelete() const { return &_delete; }
// to a histogram created with CreateHistogram function const AtomicUInt * getGetMore() const { return &_getmore; }
void SetAddHistogramSampleFunction(AddHistogramSampleCallback f) { const AtomicUInt * getCommand() const { return &_command; }
add_histogram_sample_function_ = f;
} private:
void _checkWrap();
bool HasCounterFunction() const {
return lookup_function_ != NULL; // todo: there will be a lot of cache line contention on these. ne
} ed to do something
// else eventually.
// Lookup the location of a counter by name. If the lookup AtomicUInt _insert;
// is successful, returns a non-NULL pointer for writing the AtomicUInt _query;
// value of the counter. Each thread calling this function AtomicUInt _update;
// may receive a different location to store it's counter. AtomicUInt _delete;
// The return value must not be cached and re-used across AtomicUInt _getmore;
// threads, although a single thread is free to cache it. AtomicUInt _command;
int* FindLocation(const char* name) { };
if (!lookup_function_) return NULL;
return lookup_function_(name); extern OpCounters globalOpCounters;
} extern OpCounters replOpCounters;
// Create a histogram by name. If the create is successful, class NetworkCounter {
// returns a non-NULL pointer for use with AddHistogramSample public:
// function. min and max define the expected minimum and maximum NetworkCounter() : _bytesIn(0), _bytesOut(0), _requests(0), _overfl
// sample values. buckets is the maximum number of buckets ows(0) {}
// that the samples will be grouped into. void hit( long long bytesIn , long long bytesOut );
void* CreateHistogram(const char* name, void append( BSONObjBuilder& b );
int min, private:
int max, long long _bytesIn;
size_t buckets) { long long _bytesOut;
if (!create_histogram_function_) return NULL; long long _requests;
return create_histogram_function_(name, min, max, buckets);
}
// Add a sample to a histogram created with the CreateHistogram
// function.
void AddHistogramSample(void* histogram, int sample) {
if (!add_histogram_sample_function_) return;
return add_histogram_sample_function_(histogram, sample);
}
private:
StatsTable();
CounterLookupCallback lookup_function_;
CreateHistogramCallback create_histogram_function_;
AddHistogramSampleCallback add_histogram_sample_function_;
friend class Isolate;
DISALLOW_COPY_AND_ASSIGN(StatsTable);
};
// StatsCounters are dynamically created values which can be tracked in
// the StatsTable. They are designed to be lightweight to create and
// easy to use.
//
// Internally, a counter represents a value in a row of a StatsTable.
// The row has a 32bit value for each process/thread in the table and also
// a name (stored in the table metadata). Since the storage location can b
e
// thread-specific, this class cannot be shared across threads.
//
// This class is designed to be POD initialized. It will be registered wit
h
// the counter system on first use. For example:
// StatsCounter c = { "c:myctr", NULL, false };
struct StatsCounter {
const char* name_;
int* ptr_;
bool lookup_done_;
// Sets the counter to a specific value.
void Set(int value) {
int* loc = GetPtr();
if (loc) *loc = value;
}
// Increments the counter.
void Increment() {
int* loc = GetPtr();
if (loc) (*loc)++;
}
void Increment(int value) {
int* loc = GetPtr();
if (loc)
(*loc) += value;
}
// Decrements the counter.
void Decrement() {
int* loc = GetPtr();
if (loc) (*loc)--;
}
void Decrement(int value) {
int* loc = GetPtr();
if (loc) (*loc) -= value;
}
// Is this counter enabled?
// Returns false if table is full.
bool Enabled() {
return GetPtr() != NULL;
}
// Get the internal pointer to the counter. This is used
// by the code generator to emit code that manipulates a
// given counter without calling the runtime system.
int* GetInternalPointer() {
int* loc = GetPtr();
ASSERT(loc != NULL);
return loc;
}
protected:
// Returns the cached address of this counter location.
int* GetPtr() {
if (lookup_done_) return ptr_;
lookup_done_ = true;
ptr_ = FindLocationInStatsTable();
return ptr_;
}
private:
int* FindLocationInStatsTable() const;
};
// StatsCounterTimer t = { { L"t:foo", NULL, false }, 0, 0 };
struct StatsCounterTimer {
StatsCounter counter_;
int64_t start_time_;
int64_t stop_time_;
// Start the timer.
void Start();
// Stop the timer and record the results.
void Stop();
// Returns true if the timer is running.
bool Running() {
return counter_.Enabled() && start_time_ != 0 && stop_time_ == 0;
}
};
// A Histogram represents a dynamically created histogram in the StatsTable
.
//
// This class is designed to be POD initialized. It will be registered wit
h
// the histogram system on first use. For example:
// Histogram h = { "myhist", 0, 10000, 50, NULL, false };
struct Histogram {
const char* name_;
int min_;
int max_;
int num_buckets_;
void* histogram_;
bool lookup_done_;
// Add a single sample to this histogram.
void AddSample(int sample);
// Returns true if this histogram is enabled.
bool Enabled() {
return GetHistogram() != NULL;
}
protected:
// Returns the handle to the histogram.
void* GetHistogram() {
if (!lookup_done_) {
lookup_done_ = true;
histogram_ = CreateHistogram();
}
return histogram_;
}
private:
void* CreateHistogram() const;
};
// A HistogramTimer allows distributions of results to be created
// HistogramTimer t = { {L"foo", 0, 10000, 50, NULL, false}, 0, 0 };
struct HistogramTimer {
Histogram histogram_;
int64_t start_time_;
int64_t stop_time_;
// Start the timer.
void Start();
// Stop the timer and record the results.
void Stop();
// Returns true if the timer is running.
bool Running() {
return histogram_.Enabled() && (start_time_ != 0) && (stop_time_ == 0);
}
};
// Helper class for scoping a HistogramTimer.
class HistogramTimerScope BASE_EMBEDDED {
public:
explicit HistogramTimerScope(HistogramTimer* timer) :
timer_(timer) {
timer_->Start();
}
~HistogramTimerScope() {
timer_->Stop();
}
private:
HistogramTimer* timer_;
};
} } // namespace v8::internal long long _overflows;
#endif // V8_COUNTERS_H_ SpinLock _lock;
};
extern NetworkCounter networkCounter;
}
 End of changes. 3 change blocks. 
273 lines changed or deleted 86 lines changed or added


 dbclient_rs.h   dbclient_rs.h 
skipping to change at line 521 skipping to change at line 521
string getServerAddress() const; string getServerAddress() const;
virtual ConnectionString::ConnectionType type() const { return Conn ectionString::SET; } virtual ConnectionString::ConnectionType type() const { return Conn ectionString::SET; }
virtual bool lazySupported() const { return true; } virtual bool lazySupported() const { return true; }
// ---- 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 ); }
/**
* Authenticate using supplied credentials. Authenticates against
the primary node, fails
* if node is down.
* Credentials are cached for future connections.
*
* See DBClientWithCommands::auth() for more details.
*
* This is the default authentication mode for DBClientReplicaSet
connections.
*/
void authPrimary(const BSONObj& params);
/**
* Same as above, but authorizes access to a particular database.
*
* See DBClientWithCommands::auth() for more details.
*/
bool authPrimary(const string &dbname,
const string &username,
const string &password_text,
string& errmsg,
bool digestPassword);
/**
* Authenticate using supplied credentials. Prefers authentication
against the primary
* node, will fall back to a secondary and retry if the primary nod
e is down but
* secondaries are still available.
* Credentials are cached for future connections.
*
* See DBClientWithCommands::auth() for more details.
*/
void authAny(const BSONObj& params);
/**
* Same as above, but authorizes access to a particular database.
*
* See DBClientWithCommands::auth() for more details.
*/
bool authAny( const string &dbname,
const string &username,
const string &password_text,
string& errmsg,
bool digestPassword );
/*
* Returns whether a query or command can be sent to secondaries ba
sed on the query object
* and options.
*
* @param ns the namespace of the query.
* @param queryObj the query object to check.
* @param queryOptions the query options
*
* @return true if the query/cmd could potentially be sent to a sec
ondary, false otherwise
*/
static bool isSecondaryQuery( const string& ns,
const BSONObj& queryObj,
int queryOptions );
protected: protected:
/** Authorize. Authorizes all nodes as needed
*/
virtual void _auth(const BSONObj& params); virtual void _auth(const BSONObj& params);
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 * @return back the passed cursor
* @throws DBException if the directed node cannot accept the query because it * @throws DBException if the directed node cannot accept the query because it
skipping to change at line 608 skipping to change at line 664
// not sure if/how we should handle // not sure if/how we should handle
std::map<string, BSONObj> _auths; // dbName -> auth parameters std::map<string, BSONObj> _auths; // dbName -> auth parameters
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 LazyState() :
se ), _retries( 0 ) {} _lastClient( NULL ), _lastOp( -1 ), _isSecondaryQuery( fals
e ), _retries( 0 ) {
}
DBClientConnection* _lastClient; DBClientConnection* _lastClient;
int _lastOp; int _lastOp;
bool _slaveOk; bool _isSecondaryQuery;
int _retries; int _retries;
} _lazyState; } _lazyState;
}; };
/** /**
* A simple object for representing the list of tags. The initial state will * 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. * have a valid current tag as long as the list is not empty.
*/ */
 End of changes. 4 change blocks. 
5 lines changed or deleted 69 lines changed or added


 error_codes.h   error_codes.h 
skipping to change at line 60 skipping to change at line 60
InvalidLength = 16, InvalidLength = 16,
ProtocolError = 17, ProtocolError = 17,
AuthenticationFailed = 18, AuthenticationFailed = 18,
CannotReuseObject = 19, CannotReuseObject = 19,
IllegalOperation = 20, IllegalOperation = 20,
EmptyArrayOperation = 21, EmptyArrayOperation = 21,
InvalidBSON = 22, InvalidBSON = 22,
AlreadyInitialized = 23, AlreadyInitialized = 23,
LockTimeout = 24, LockTimeout = 24,
RemoteValidationError = 25, RemoteValidationError = 25,
NodeNotFound = 74,
MaxError MaxError
}; };
static const char* errorString(Error err); static const char* errorString(Error err);
/** /**
* Parse an Error from its "name". Returns UnknownError if "name" is unrecognized. * Parse an Error from its "name". Returns UnknownError if "name" is unrecognized.
* *
* NOTE: Also returns UnknownError for the string "UnknownError". * NOTE: Also returns UnknownError for the string "UnknownError".
*/ */
 End of changes. 1 change blocks. 
0 lines changed or deleted 1 lines changed or added


 shard.h   shard.h 
skipping to change at line 293 skipping to change at line 293
_finishedInit = true; _finishedInit = true;
} }
bool ok() const { return _conn > 0; } bool ok() const { return _conn > 0; }
/** /**
this just passes through excpet it checks for stale configs this just passes through excpet it checks for stale configs
*/ */
bool runCommand( const string& db , const BSONObj& cmd , BSONObj& r es ); bool runCommand( const string& db , const BSONObj& cmd , BSONObj& r es );
// Whether or not we release connections from the thread-local cach e after a read
static bool releaseConnectionsAfterResponse; static bool releaseConnectionsAfterResponse;
// Controls whether we throw on initially failing to set a version
static bool ignoreInitialVersionFailure;
/** checks all of my thread local connections for the version of th is ns */ /** checks all of my thread local connections for the version of th is ns */
static void checkMyConnectionVersions( const string & ns ); static void checkMyConnectionVersions( const string & ns );
/** /**
* Returns all the current sharded connections to the pool. * Returns all the current sharded connections to the pool.
* Note: This is *dangerous* if we have GLE state. * Note: This is *dangerous* if we have GLE state.
*/ */
static void releaseMyConnections(); static void releaseMyConnections();
/** /**
 End of changes. 2 change blocks. 
0 lines changed or deleted 4 lines changed or added


 spaces.h   spaces.h 
skipping to change at line 320 skipping to change at line 320
MemoryChunk* next_chunk() const { return next_chunk_; } MemoryChunk* next_chunk() const { return next_chunk_; }
MemoryChunk* prev_chunk() const { return prev_chunk_; } MemoryChunk* prev_chunk() const { return prev_chunk_; }
void set_next_chunk(MemoryChunk* next) { next_chunk_ = next; } void set_next_chunk(MemoryChunk* next) { next_chunk_ = next; }
void set_prev_chunk(MemoryChunk* prev) { prev_chunk_ = prev; } void set_prev_chunk(MemoryChunk* prev) { prev_chunk_ = prev; }
Space* owner() const { Space* owner() const {
if ((reinterpret_cast<intptr_t>(owner_) & kFailureTagMask) == if ((reinterpret_cast<intptr_t>(owner_) & kFailureTagMask) ==
kFailureTag) { kFailureTag) {
return reinterpret_cast<Space*>(owner_ - kFailureTag); return reinterpret_cast<Space*>(reinterpret_cast<intptr_t>(owner_) -
kFailureTag);
} else { } else {
return NULL; return NULL;
} }
} }
void set_owner(Space* space) { void set_owner(Space* space) {
ASSERT((reinterpret_cast<intptr_t>(space) & kFailureTagMask) == 0); ASSERT((reinterpret_cast<intptr_t>(space) & kFailureTagMask) == 0);
owner_ = reinterpret_cast<Address>(space) + kFailureTag; owner_ = reinterpret_cast<Address>(space) + kFailureTag;
ASSERT((reinterpret_cast<intptr_t>(owner_) & kFailureTagMask) == ASSERT((reinterpret_cast<intptr_t>(owner_) & kFailureTagMask) ==
kFailureTag); kFailureTag);
 End of changes. 1 change blocks. 
1 lines changed or deleted 2 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/