counters.h   counters.h 
// counters.h // Copyright 2012 the V8 project authors. All rights reserved.
/* // Redistribution and use in source and binary forms, with or without
* Copyright (C) 2010 10gen Inc. // modification, are permitted provided that the following conditions are
* // met:
* This program is free software: you can redistribute it and/or modify //
* it under the terms of the GNU Affero General Public License, version // * Redistributions of source code must retain the above copyright
3, // notice, this list of conditions and the following disclaimer.
* as published by the Free Software Foundation. // * Redistributions in binary form must reproduce the above
* // copyright notice, this list of conditions and the following
* This program is distributed in the hope that it will be useful, // disclaimer in the documentation and/or other materials provided
* but WITHOUT ANY WARRANTY; without even the implied warranty of // with the distribution.
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // * Neither the name of Google Inc. nor the names of its
* GNU Affero General Public License for more details. // contributors may be used to endorse or promote products derived
* // from this software without specific prior written permission.
* You should have received a copy of the GNU Affero General Public Lice //
nse // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* along with this program. If not, see <http://www.gnu.org/licenses/>. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
*/ // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
#pragma once // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
#include "mongo/pch.h" // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
#include "../jsobj.h" // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
#include "../../util/net/message.h" // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
#include "../../util/processinfo.h" // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
#include "../../util/concurrency/spin_lock.h" // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "mongo/db/pdfile.h"
#ifndef V8_COUNTERS_H_
namespace mongo { #define V8_COUNTERS_H_
/** #include "../include/v8.h"
* for storing operation counters #include "allocation.h"
* note: not thread safe. ok with that for speed
*/ namespace v8 {
class OpCounters { namespace internal {
public:
// StatsCounters is an interface for plugging into external
OpCounters(); // counters for monitoring. Counters can be looked up and
void incInsertInWriteLock(int n) { _insert.x += n; } // manipulated by name.
void gotInsert() { _insert++; }
void gotQuery() { _query++; } class StatsTable {
void gotUpdate() { _update++; } public:
void gotDelete() { _delete++; } // Register an application-defined function where
void gotGetMore() { _getmore++; } // counters can be looked up.
void gotCommand() { _command++; } void SetCounterFunction(CounterLookupCallback f) {
lookup_function_ = f;
void gotOp( int op , bool isCommand ); }
BSONObj getObj() const; // Register an application-defined function to create
// a histogram for passing to the AddHistogramSample function
// thse are used by snmp, and other things, do not remove void SetCreateHistogramFunction(CreateHistogramCallback f) {
const AtomicUInt * getInsert() const { return &_insert; } create_histogram_function_ = f;
const AtomicUInt * getQuery() const { return &_query; } }
const AtomicUInt * getUpdate() const { return &_update; }
const AtomicUInt * getDelete() const { return &_delete; } // Register an application-defined function to add a sample
const AtomicUInt * getGetMore() const { return &_getmore; } // to a histogram created with CreateHistogram function
const AtomicUInt * getCommand() const { return &_command; } void SetAddHistogramSampleFunction(AddHistogramSampleCallback f) {
add_histogram_sample_function_ = f;
private: }
void _checkWrap();
bool HasCounterFunction() const {
// todo: there will be a lot of cache line contention on these. ne return lookup_function_ != NULL;
ed to do something }
// else eventually.
AtomicUInt _insert; // Lookup the location of a counter by name. If the lookup
AtomicUInt _query; // is successful, returns a non-NULL pointer for writing the
AtomicUInt _update; // value of the counter. Each thread calling this function
AtomicUInt _delete; // may receive a different location to store it's counter.
AtomicUInt _getmore; // The return value must not be cached and re-used across
AtomicUInt _command; // threads, although a single thread is free to cache it.
}; int* FindLocation(const char* name) {
if (!lookup_function_) return NULL;
extern OpCounters globalOpCounters; return lookup_function_(name);
extern OpCounters replOpCounters; }
class NetworkCounter { // Create a histogram by name. If the create is successful,
public: // returns a non-NULL pointer for use with AddHistogramSample
NetworkCounter() : _bytesIn(0), _bytesOut(0), _requests(0), _overfl // function. min and max define the expected minimum and maximum
ows(0) {} // sample values. buckets is the maximum number of buckets
void hit( long long bytesIn , long long bytesOut ); // that the samples will be grouped into.
void append( BSONObjBuilder& b ); void* CreateHistogram(const char* name,
private: int min,
long long _bytesIn; int max,
long long _bytesOut; size_t buckets) {
long long _requests; if (!create_histogram_function_) return NULL;
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_;
};
long long _overflows; } } // namespace v8::internal
SpinLock _lock; #endif // V8_COUNTERS_H_
};
extern NetworkCounter networkCounter;
}
 End of changes. 3 change blocks. 
86 lines changed or deleted 273 lines changed or added


 distlock.h   distlock.h 
skipping to change at line 60 skipping to change at line 60
* Indicates an error in retrieving time values from remote servers. * Indicates an error in retrieving time values from remote servers.
*/ */
class TimeNotFoundException : public LockException { class TimeNotFoundException : public LockException {
public: public:
TimeNotFoundException( const char * msg , int code ) : LockExceptio n( msg, code ) {} TimeNotFoundException( const char * msg , int code ) : LockExceptio n( msg, code ) {}
TimeNotFoundException( const string& msg, int code ) : LockExceptio n( msg, code ) {} TimeNotFoundException( const string& msg, int code ) : LockExceptio n( msg, code ) {}
virtual ~TimeNotFoundException() throw() { } virtual ~TimeNotFoundException() throw() { }
}; };
/** /**
* The distributed lock is a configdb backed way of synchronizing syste * The distributed lock is a configdb backed way of synchronizing syste
m-wide tasks. A task must be identified by a m-wide tasks. A task
* unique name across the system (e.g., "balancer"). A lock is taken by * must be identified by a unique name across the system (e.g., "balanc
writing a document in the configdb's locks er"). A lock is taken
* collection with that name. * by writing a document in the configdb's locks collection with that n
ame.
* *
* To be maintained, each taken lock needs to be revalidated ("pinged") * To be maintained, each taken lock needs to be revalidated ("pinged")
within a pre-established amount of time. This within a
* class does this maintenance automatically once a DistributedLock obj * pre-established amount of time. This class does this maintenance aut
ect was constructed. omatically once a
* DistributedLock object was constructed. The ping procedure records t
he local time to
* the ping document, but that time is untrusted and is only used as a
point of reference
* of whether the ping was refreshed or not. Ultimately, the clock a co
nfigdb is the source
* of truth when determining whether a ping is still fresh or not. This
is achieved by
* (1) remembering the ping document time along with config server time
when unable to
* take a lock, and (2) ensuring all config servers report similar time
s and have similar
* time rates (the difference in times must start and stay small).
*/ */
class DistributedLock { class DistributedLock {
public: public:
static LabeledLevel logLvl; static LabeledLevel logLvl;
struct PingData { struct PingData {
PingData( const string& _id , Date_t _lastPing , Date_t _remote , OID _ts ) PingData( const string& _id , Date_t _lastPing , Date_t _remote , OID _ts )
: id(_id), lastPing(_lastPing), remote(_remote), ts(_ts){ : id(_id), lastPing(_lastPing), remote(_remote), ts(_ts){
skipping to change at line 150 skipping to change at line 157
Date_t getRemoteTime(); Date_t getRemoteTime();
bool isRemoteTimeSkewed(); bool isRemoteTimeSkewed();
const string& getProcessId(); const string& getProcessId();
const ConnectionString& getRemoteConnection(); const ConnectionString& getRemoteConnection();
/** /**
* Check the skew between a cluster of servers * Checks the skew among a cluster of servers and returns true if t
he min and max clock
* times among the servers are within maxClockSkew.
*/ */
static bool checkSkew( const ConnectionString& cluster, unsigned sk static bool checkSkew( const ConnectionString& cluster,
ewChecks = NUM_LOCK_SKEW_CHECKS, unsigned long long maxClockSkew = MAX_LOCK unsigned skewChecks = NUM_LOCK_SKEW_CHECKS,
_CLOCK_SKEW, unsigned long long maxNetSkew = MAX_LOCK_NET_SKEW ); unsigned long long maxClockSkew = MAX_LOCK_C
LOCK_SKEW,
unsigned long long maxNetSkew = MAX_LOCK_NET
_SKEW );
/** /**
* Get the remote time from a server or cluster * Get the remote time from a server or cluster
*/ */
static Date_t remoteTime( const ConnectionString& cluster, unsigned long long maxNetSkew = MAX_LOCK_NET_SKEW ); static Date_t remoteTime( const ConnectionString& cluster, unsigned long long maxNetSkew = MAX_LOCK_NET_SKEW );
static bool killPinger( DistributedLock& lock ); static bool killPinger( DistributedLock& lock );
/** /**
* Namespace for lock pings * Namespace for lock pings
 End of changes. 4 change blocks. 
13 lines changed or deleted 32 lines changed or added


 namespace_details.h   namespace_details.h 
skipping to change at line 406 skipping to change at line 406
return 5; return 5;
return (int) (stats.datasize / stats.nrecords); return (int) (stats.datasize / stats.nrecords);
} }
NamespaceDetails *writingWithoutExtra() { NamespaceDetails *writingWithoutExtra() {
return ( NamespaceDetails* ) getDur().writingPtr( this, sizeof( NamespaceDetails ) ); return ( NamespaceDetails* ) getDur().writingPtr( this, sizeof( NamespaceDetails ) );
} }
/** Make all linked Extra objects writeable as well */ /** Make all linked Extra objects writeable as well */
NamespaceDetails *writingWithExtra(); NamespaceDetails *writingWithExtra();
void onLoad( const Namespace& k );
private: private:
DiskLoc _alloc(const char *ns, int len); DiskLoc _alloc(const char *ns, int len);
void maybeComplain( const char *ns, int len ) const; void maybeComplain( const char *ns, int len ) const;
DiskLoc __stdAlloc(int len, bool willBeAt); DiskLoc __stdAlloc(int len, bool willBeAt);
void compact(); // combine adjacent deleted records void compact(); // combine adjacent deleted records
friend class NamespaceIndex; friend class NamespaceIndex;
struct ExtraOld { struct ExtraOld {
// note we could use this field for more chaining later, so don 't waste it: // note we could use this field for more chaining later, so don 't waste it:
unsigned long long reserved1; unsigned long long reserved1;
IndexDetails details[NIndexesExtra]; IndexDetails details[NIndexesExtra];
 End of changes. 1 change blocks. 
0 lines changed or deleted 1 lines changed or added


 namespacestring.h   namespacestring.h 
skipping to change at line 49 skipping to change at line 49
string db; string db;
string coll; // note collection names can have periods in them for organizing purposes (e.g. "system.indexes") string coll; // note collection names can have periods in them for organizing purposes (e.g. "system.indexes")
NamespaceString( const char * ns ) { init(ns); } NamespaceString( const char * ns ) { init(ns); }
NamespaceString( const string& ns ) { init(ns.c_str()); } NamespaceString( const string& ns ) { init(ns.c_str()); }
string ns() const { return db + '.' + coll; } string ns() const { return db + '.' + coll; }
bool isSystem() const { return strncmp(coll.c_str(), "system.", 7) == 0; } bool isSystem() const { return strncmp(coll.c_str(), "system.", 7) == 0; }
bool isCommand() const { return coll == "$cmd"; } bool isCommand() const { return coll == "$cmd"; }
bool isSystemDotIndexes() const { return strncmp(coll.c_str(), "sys tem.indexes", 14) == 0; }
/** /**
* @return true if the namespace is valid. Special namespaces for i nternal use are considered as valid. * @return true if the namespace is valid. Special namespaces for i nternal use are considered as valid.
*/ */
bool isValid() const { bool isValid() const {
return validDBName( db ) && !coll.empty(); return validDBName( db ) && !coll.empty();
} }
operator string() const { return ns(); } operator string() const { return ns(); }
 End of changes. 1 change blocks. 
0 lines changed or deleted 1 lines changed or added


 processinfo.h   processinfo.h 
skipping to change at line 95 skipping to change at line 95
* Get the CPU architecture (e.g. x86, x86_64) * Get the CPU architecture (e.g. x86, x86_64)
*/ */
const string& getArch() const { return sysInfo().cpuArch; } const string& getArch() const { return sysInfo().cpuArch; }
/** /**
* Determine if NUMA is enabled (interleaved) for this process * Determine if NUMA is enabled (interleaved) for this process
*/ */
bool hasNumaEnabled() const { return sysInfo().hasNuma; } bool hasNumaEnabled() const { return sysInfo().hasNuma; }
/** /**
* Determine if file zeroing is necessary for newly allocated data
files.
*/
static bool isDataFileZeroingNeeded() { return systemInfo->fileZero
Needed; }
/**
* Get extra system stats * Get extra system stats
*/ */
void appendSystemDetails( BSONObjBuilder& details ) const { void appendSystemDetails( BSONObjBuilder& details ) const {
details.append( StringData("extra"), sysInfo()._extraStats.copy () ); details.append( StringData("extra"), sysInfo()._extraStats.copy () );
} }
/** /**
* Append platform-specific data to obj * Append platform-specific data to obj
*/ */
void getExtraInfo( BSONObjBuilder& info ); void getExtraInfo( BSONObjBuilder& info );
skipping to change at line 148 skipping to change at line 153
string osType; string osType;
string osName; string osName;
string osVersion; string osVersion;
unsigned addrSize; unsigned addrSize;
unsigned long long memSize; unsigned long long memSize;
unsigned numCores; unsigned numCores;
unsigned long long pageSize; unsigned long long pageSize;
string cpuArch; string cpuArch;
bool hasNuma; bool hasNuma;
BSONObj _extraStats; BSONObj _extraStats;
// This is an OS specific value, which determines whether files
should be zero-filled
// at allocation time in order to avoid Microsoft KB 2731284.
//
bool fileZeroNeeded;
SystemInfo() : SystemInfo() :
addrSize( 0 ), addrSize( 0 ),
memSize( 0 ), memSize( 0 ),
numCores( 0 ), numCores( 0 ),
pageSize( 0 ), pageSize( 0 ),
hasNuma( false ) { hasNuma( false ),
fileZeroNeeded (false) {
// populate SystemInfo during construction // populate SystemInfo during construction
collectSystemInfo(); collectSystemInfo();
} }
private: private:
/** Collect host system info */ /** Collect host system info */
void collectSystemInfo(); void collectSystemInfo();
}; };
pid_t _pid; pid_t _pid;
static mongo::mutex _sysInfoLock; static mongo::mutex _sysInfoLock;
 End of changes. 3 change blocks. 
1 lines changed or deleted 16 lines changed or added


 spaces-inl.h   spaces-inl.h 
skipping to change at line 152 skipping to change at line 152
#endif #endif
// ------------------------------------------------------------------------ -- // ------------------------------------------------------------------------ --
// PagedSpace // PagedSpace
Page* Page::Initialize(Heap* heap, Page* Page::Initialize(Heap* heap,
MemoryChunk* chunk, MemoryChunk* chunk,
Executability executable, Executability executable,
PagedSpace* owner) { PagedSpace* owner) {
Page* page = reinterpret_cast<Page*>(chunk); Page* page = reinterpret_cast<Page*>(chunk);
ASSERT(chunk->size() <= static_cast<size_t>(kPageSize)); ASSERT(page->area_size() <= kNonCodeObjectAreaSize);
ASSERT(chunk->owner() == owner); ASSERT(chunk->owner() == owner);
owner->IncreaseCapacity(page->area_size()); owner->IncreaseCapacity(page->area_size());
owner->Free(page->area_start(), page->area_size()); owner->Free(page->area_start(), page->area_size());
heap->incremental_marking()->SetOldSpacePageFlags(chunk); heap->incremental_marking()->SetOldSpacePageFlags(chunk);
return page; return page;
} }
bool PagedSpace::Contains(Address addr) { bool PagedSpace::Contains(Address addr) {
 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/