| compiler.h | | compiler.h | |
|
| // Copyright 2012 the V8 project authors. All rights reserved. | | // @file mongo/platform/compiler.h | |
| // Redistribution and use in source and binary forms, with or without | | | |
| // modification, are permitted provided that the following conditions are | | | |
| // met: | | | |
| // | | | |
| // * Redistributions of source code must retain the above copyright | | | |
| // notice, this list of conditions and the following disclaimer. | | | |
| // * Redistributions in binary form must reproduce the above | | | |
| // copyright notice, this list of conditions and the following | | | |
| // disclaimer in the documentation and/or other materials provided | | | |
| // with the distribution. | | | |
| // * Neither the name of Google Inc. nor the names of its | | | |
| // contributors may be used to endorse or promote products derived | | | |
| // from this software without specific prior written permission. | | | |
| // | | | |
| // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | | | |
| // "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 | | | |
| // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | | | |
| // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | | | |
| // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | | | |
| // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | | | |
| // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | | | |
| // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | | | |
| // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | | | |
| | | | |
|
| #ifndef V8_COMPILER_H_ | | /* | |
| #define V8_COMPILER_H_ | | * Copyright 2012 10gen Inc. | |
| | | * | |
| #include "allocation.h" | | * Licensed under the Apache License, Version 2.0 (the "License"); | |
| #include "ast.h" | | * you may not use this file except in compliance with the License. | |
| #include "zone.h" | | * You may obtain a copy of the License at | |
| | | * | |
| namespace v8 { | | * http://www.apache.org/licenses/LICENSE-2.0 | |
| namespace internal { | | * | |
| | | * Unless required by applicable law or agreed to in writing, software | |
| class ScriptDataImpl; | | * distributed under the License is distributed on an "AS IS" BASIS, | |
| | | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| // CompilationInfo encapsulates some information known at compile time. It | | * See the License for the specific language governing permissions and | |
| // is constructed based on the resources available at compile-time. | | * limitations under the License. | |
| class CompilationInfo { | | */ | |
| public: | | | |
| CompilationInfo(Handle<Script> script, Zone* zone); | | #pragma once | |
| CompilationInfo(Handle<SharedFunctionInfo> shared_info, Zone* zone); | | | |
| CompilationInfo(Handle<JSFunction> closure, Zone* zone); | | /** | |
| | | * Include "mongo/platform/compiler.h" to get compiler-specific macro defin | |
| virtual ~CompilationInfo(); | | itions and utilities. | |
| | | */ | |
| Isolate* isolate() { | | | |
| ASSERT(Isolate::Current() == isolate_); | | #if defined(_MSC_VER) | |
| return isolate_; | | #include "mongo/platform/compiler_msvc.h" | |
| } | | #elif defined(__GNUC__) | |
| Zone* zone() { | | #include "mongo/platform/compiler_gcc.h" | |
| return zone_; | | #else | |
| } | | #error "Unsupported compiler family" | |
| bool is_lazy() const { return IsLazy::decode(flags_); } | | | |
| bool is_eval() const { return IsEval::decode(flags_); } | | | |
| bool is_global() const { return IsGlobal::decode(flags_); } | | | |
| bool is_classic_mode() const { return language_mode() == CLASSIC_MODE; } | | | |
| bool is_extended_mode() const { return language_mode() == EXTENDED_MODE; | | | |
| } | | | |
| LanguageMode language_mode() const { | | | |
| return LanguageModeField::decode(flags_); | | | |
| } | | | |
| bool is_in_loop() const { return IsInLoop::decode(flags_); } | | | |
| FunctionLiteral* function() const { return function_; } | | | |
| Scope* scope() const { return scope_; } | | | |
| Scope* global_scope() const { return global_scope_; } | | | |
| Handle<Code> code() const { return code_; } | | | |
| Handle<JSFunction> closure() const { return closure_; } | | | |
| Handle<SharedFunctionInfo> shared_info() const { return shared_info_; } | | | |
| Handle<Script> script() const { return script_; } | | | |
| v8::Extension* extension() const { return extension_; } | | | |
| ScriptDataImpl* pre_parse_data() const { return pre_parse_data_; } | | | |
| Handle<Context> calling_context() const { return calling_context_; } | | | |
| int osr_ast_id() const { return osr_ast_id_; } | | | |
| | | | |
| void MarkAsEval() { | | | |
| ASSERT(!is_lazy()); | | | |
| flags_ |= IsEval::encode(true); | | | |
| } | | | |
| void MarkAsGlobal() { | | | |
| ASSERT(!is_lazy()); | | | |
| flags_ |= IsGlobal::encode(true); | | | |
| } | | | |
| void SetLanguageMode(LanguageMode language_mode) { | | | |
| ASSERT(this->language_mode() == CLASSIC_MODE || | | | |
| this->language_mode() == language_mode || | | | |
| language_mode == EXTENDED_MODE); | | | |
| flags_ = LanguageModeField::update(flags_, language_mode); | | | |
| } | | | |
| void MarkAsInLoop() { | | | |
| ASSERT(is_lazy()); | | | |
| flags_ |= IsInLoop::encode(true); | | | |
| } | | | |
| void MarkAsNative() { | | | |
| flags_ |= IsNative::encode(true); | | | |
| } | | | |
| bool is_native() const { | | | |
| return IsNative::decode(flags_); | | | |
| } | | | |
| void SetFunction(FunctionLiteral* literal) { | | | |
| ASSERT(function_ == NULL); | | | |
| function_ = literal; | | | |
| } | | | |
| void SetScope(Scope* scope) { | | | |
| ASSERT(scope_ == NULL); | | | |
| scope_ = scope; | | | |
| } | | | |
| void SetGlobalScope(Scope* global_scope) { | | | |
| ASSERT(global_scope_ == NULL); | | | |
| global_scope_ = global_scope; | | | |
| } | | | |
| void SetCode(Handle<Code> code) { code_ = code; } | | | |
| void SetExtension(v8::Extension* extension) { | | | |
| ASSERT(!is_lazy()); | | | |
| extension_ = extension; | | | |
| } | | | |
| void SetPreParseData(ScriptDataImpl* pre_parse_data) { | | | |
| ASSERT(!is_lazy()); | | | |
| pre_parse_data_ = pre_parse_data; | | | |
| } | | | |
| void SetCallingContext(Handle<Context> context) { | | | |
| ASSERT(is_eval()); | | | |
| calling_context_ = context; | | | |
| } | | | |
| void SetOsrAstId(int osr_ast_id) { | | | |
| ASSERT(IsOptimizing()); | | | |
| osr_ast_id_ = osr_ast_id; | | | |
| } | | | |
| void MarkCompilingForDebugging(Handle<Code> current_code) { | | | |
| ASSERT(mode_ != OPTIMIZE); | | | |
| ASSERT(current_code->kind() == Code::FUNCTION); | | | |
| flags_ |= IsCompilingForDebugging::encode(true); | | | |
| if (current_code->is_compiled_optimizable()) { | | | |
| EnableDeoptimizationSupport(); | | | |
| } else { | | | |
| mode_ = CompilationInfo::NONOPT; | | | |
| } | | | |
| } | | | |
| bool IsCompilingForDebugging() { | | | |
| return IsCompilingForDebugging::decode(flags_); | | | |
| } | | | |
| | | | |
| bool has_global_object() const { | | | |
| return !closure().is_null() && (closure()->context()->global() != NULL) | | | |
| ; | | | |
| } | | | |
| | | | |
| GlobalObject* global_object() const { | | | |
| return has_global_object() ? closure()->context()->global() : NULL; | | | |
| } | | | |
| | | | |
| // Accessors for the different compilation modes. | | | |
| bool IsOptimizing() const { return mode_ == OPTIMIZE; } | | | |
| bool IsOptimizable() const { return mode_ == BASE; } | | | |
| void SetOptimizing(int osr_ast_id) { | | | |
| SetMode(OPTIMIZE); | | | |
| osr_ast_id_ = osr_ast_id; | | | |
| } | | | |
| void DisableOptimization(); | | | |
| | | | |
| // Deoptimization support. | | | |
| bool HasDeoptimizationSupport() const { | | | |
| return SupportsDeoptimization::decode(flags_); | | | |
| } | | | |
| void EnableDeoptimizationSupport() { | | | |
| ASSERT(IsOptimizable()); | | | |
| flags_ |= SupportsDeoptimization::encode(true); | | | |
| } | | | |
| | | | |
| // Determines whether or not to insert a self-optimization header. | | | |
| bool ShouldSelfOptimize(); | | | |
| | | | |
| // Disable all optimization attempts of this info for the rest of the | | | |
| // current compilation pipeline. | | | |
| void AbortOptimization(); | | | |
| | | | |
| void set_deferred_handles(DeferredHandles* deferred_handles) { | | | |
| ASSERT(deferred_handles_ == NULL); | | | |
| deferred_handles_ = deferred_handles; | | | |
| } | | | |
| | | | |
| void SaveHandles() { | | | |
| SaveHandle(&closure_); | | | |
| SaveHandle(&shared_info_); | | | |
| SaveHandle(&calling_context_); | | | |
| SaveHandle(&script_); | | | |
| } | | | |
| | | | |
| private: | | | |
| Isolate* isolate_; | | | |
| | | | |
| // Compilation mode. | | | |
| // BASE is generated by the full codegen, optionally prepared for bailout | | | |
| s. | | | |
| // OPTIMIZE is optimized code generated by the Hydrogen-based backend. | | | |
| // NONOPT is generated by the full codegen and is not prepared for | | | |
| // recompilation/bailouts. These functions are never recompiled. | | | |
| enum Mode { | | | |
| BASE, | | | |
| OPTIMIZE, | | | |
| NONOPT | | | |
| }; | | | |
| | | | |
| void Initialize(Mode mode) { | | | |
| mode_ = V8::UseCrankshaft() ? mode : NONOPT; | | | |
| ASSERT(!script_.is_null()); | | | |
| if (script_->type()->value() == Script::TYPE_NATIVE) { | | | |
| MarkAsNative(); | | | |
| } | | | |
| if (!shared_info_.is_null()) { | | | |
| ASSERT(language_mode() == CLASSIC_MODE); | | | |
| SetLanguageMode(shared_info_->language_mode()); | | | |
| } | | | |
| } | | | |
| | | | |
| void SetMode(Mode mode) { | | | |
| ASSERT(V8::UseCrankshaft()); | | | |
| mode_ = mode; | | | |
| } | | | |
| | | | |
| // Flags using template class BitField<type, start, length>. All are | | | |
| // false by default. | | | |
| // | | | |
| // Compilation is either eager or lazy. | | | |
| class IsLazy: public BitField<bool, 0, 1> {}; | | | |
| // Flags that can be set for eager compilation. | | | |
| class IsEval: public BitField<bool, 1, 1> {}; | | | |
| class IsGlobal: public BitField<bool, 2, 1> {}; | | | |
| // Flags that can be set for lazy compilation. | | | |
| class IsInLoop: public BitField<bool, 3, 1> {}; | | | |
| // Strict mode - used in eager compilation. | | | |
| class LanguageModeField: public BitField<LanguageMode, 4, 2> {}; | | | |
| // Is this a function from our natives. | | | |
| class IsNative: public BitField<bool, 6, 1> {}; | | | |
| // Is this code being compiled with support for deoptimization.. | | | |
| class SupportsDeoptimization: public BitField<bool, 7, 1> {}; | | | |
| // If compiling for debugging produce just full code matching the | | | |
| // initial mode setting. | | | |
| class IsCompilingForDebugging: public BitField<bool, 8, 1> {}; | | | |
| | | | |
| unsigned flags_; | | | |
| | | | |
| // Fields filled in by the compilation pipeline. | | | |
| // AST filled in by the parser. | | | |
| FunctionLiteral* function_; | | | |
| // The scope of the function literal as a convenience. Set to indicate | | | |
| // that scopes have been analyzed. | | | |
| Scope* scope_; | | | |
| // The global scope provided as a convenience. | | | |
| Scope* global_scope_; | | | |
| // The compiled code. | | | |
| Handle<Code> code_; | | | |
| | | | |
| // Possible initial inputs to the compilation process. | | | |
| Handle<JSFunction> closure_; | | | |
| Handle<SharedFunctionInfo> shared_info_; | | | |
| Handle<Script> script_; | | | |
| | | | |
| // Fields possibly needed for eager compilation, NULL by default. | | | |
| v8::Extension* extension_; | | | |
| ScriptDataImpl* pre_parse_data_; | | | |
| | | | |
| // The context of the caller is needed for eval code, and will be a null | | | |
| // handle otherwise. | | | |
| Handle<Context> calling_context_; | | | |
| | | | |
| // Compilation mode flag and whether deoptimization is allowed. | | | |
| Mode mode_; | | | |
| int osr_ast_id_; | | | |
| | | | |
| // The zone from which the compilation pipeline working on this | | | |
| // CompilationInfo allocates. | | | |
| Zone* zone_; | | | |
| | | | |
| DeferredHandles* deferred_handles_; | | | |
| | | | |
| template<typename T> | | | |
| void SaveHandle(Handle<T> *object) { | | | |
| if (!object->is_null()) { | | | |
| Handle<T> handle(*(*object)); | | | |
| *object = handle; | | | |
| } | | | |
| } | | | |
| | | | |
| DISALLOW_COPY_AND_ASSIGN(CompilationInfo); | | | |
| }; | | | |
| | | | |
| // Exactly like a CompilationInfo, except also creates and enters a | | | |
| // Zone on construction and deallocates it on exit. | | | |
| class CompilationInfoWithZone: public CompilationInfo { | | | |
| public: | | | |
| explicit CompilationInfoWithZone(Handle<Script> script) | | | |
| : CompilationInfo(script, &zone_), | | | |
| zone_(script->GetIsolate()), | | | |
| zone_scope_(&zone_, DELETE_ON_EXIT) {} | | | |
| explicit CompilationInfoWithZone(Handle<SharedFunctionInfo> shared_info) | | | |
| : CompilationInfo(shared_info, &zone_), | | | |
| zone_(shared_info->GetIsolate()), | | | |
| zone_scope_(&zone_, DELETE_ON_EXIT) {} | | | |
| explicit CompilationInfoWithZone(Handle<JSFunction> closure) | | | |
| : CompilationInfo(closure, &zone_), | | | |
| zone_(closure->GetIsolate()), | | | |
| zone_scope_(&zone_, DELETE_ON_EXIT) {} | | | |
| | | | |
| private: | | | |
| Zone zone_; | | | |
| ZoneScope zone_scope_; | | | |
| }; | | | |
| | | | |
| // A wrapper around a CompilationInfo that detaches the Handles from | | | |
| // the underlying DeferredHandleScope and stores them in info_ on | | | |
| // destruction. | | | |
| class CompilationHandleScope BASE_EMBEDDED { | | | |
| public: | | | |
| explicit CompilationHandleScope(CompilationInfo* info) | | | |
| : deferred_(info->isolate()), info_(info) {} | | | |
| ~CompilationHandleScope() { | | | |
| info_->set_deferred_handles(deferred_.Detach()); | | | |
| } | | | |
| | | | |
| private: | | | |
| DeferredHandleScope deferred_; | | | |
| CompilationInfo* info_; | | | |
| }; | | | |
| | | | |
| class HGraph; | | | |
| class HGraphBuilder; | | | |
| class LChunk; | | | |
| | | | |
| // A helper class that calls the three compilation phases in | | | |
| // Crankshaft and keeps track of its state. The three phases | | | |
| // CreateGraph, OptimizeGraph and GenerateAndInstallCode can either | | | |
| // fail, bail-out to the full code generator or succeed. Apart from | | | |
| // their return value, the status of the phase last run can be checked | | | |
| // using last_status(). | | | |
| class OptimizingCompiler: public ZoneObject { | | | |
| public: | | | |
| explicit OptimizingCompiler(CompilationInfo* info) | | | |
| : info_(info), | | | |
| oracle_(NULL), | | | |
| graph_builder_(NULL), | | | |
| graph_(NULL), | | | |
| chunk_(NULL), | | | |
| time_taken_to_create_graph_(0), | | | |
| time_taken_to_optimize_(0), | | | |
| time_taken_to_codegen_(0), | | | |
| last_status_(FAILED) { } | | | |
| | | | |
| enum Status { | | | |
| FAILED, BAILED_OUT, SUCCEEDED | | | |
| }; | | | |
| | | | |
| MUST_USE_RESULT Status CreateGraph(); | | | |
| MUST_USE_RESULT Status OptimizeGraph(); | | | |
| MUST_USE_RESULT Status GenerateAndInstallCode(); | | | |
| | | | |
| Status last_status() const { return last_status_; } | | | |
| CompilationInfo* info() const { return info_; } | | | |
| | | | |
| MUST_USE_RESULT Status AbortOptimization() { | | | |
| info_->AbortOptimization(); | | | |
| info_->shared_info()->DisableOptimization(); | | | |
| return SetLastStatus(BAILED_OUT); | | | |
| } | | | |
| | | | |
| private: | | | |
| CompilationInfo* info_; | | | |
| TypeFeedbackOracle* oracle_; | | | |
| HGraphBuilder* graph_builder_; | | | |
| HGraph* graph_; | | | |
| LChunk* chunk_; | | | |
| int64_t time_taken_to_create_graph_; | | | |
| int64_t time_taken_to_optimize_; | | | |
| int64_t time_taken_to_codegen_; | | | |
| Status last_status_; | | | |
| | | | |
| MUST_USE_RESULT Status SetLastStatus(Status status) { | | | |
| last_status_ = status; | | | |
| return last_status_; | | | |
| } | | | |
| void RecordOptimizationStats(); | | | |
| | | | |
| struct Timer { | | | |
| Timer(OptimizingCompiler* compiler, int64_t* location) | | | |
| : compiler_(compiler), | | | |
| start_(OS::Ticks()), | | | |
| location_(location) { } | | | |
| | | | |
| ~Timer() { | | | |
| *location_ += (OS::Ticks() - start_); | | | |
| } | | | |
| | | | |
| OptimizingCompiler* compiler_; | | | |
| int64_t start_; | | | |
| int64_t* location_; | | | |
| }; | | | |
| }; | | | |
| | | | |
| // The V8 compiler | | | |
| // | | | |
| // General strategy: Source code is translated into an anonymous function w | | | |
| /o | | | |
| // parameters which then can be executed. If the source code contains other | | | |
| // functions, they will be compiled and allocated as part of the compilatio | | | |
| n | | | |
| // of the source code. | | | |
| | | | |
| // Please note this interface returns shared function infos. This means yo | | | |
| u | | | |
| // need to call Factory::NewFunctionFromSharedFunctionInfo before you have | | | |
| a | | | |
| // real function with a context. | | | |
| | | | |
| class Compiler : public AllStatic { | | | |
| public: | | | |
| // Default maximum number of function optimization attempts before we | | | |
| // give up. | | | |
| static const int kDefaultMaxOptCount = 10; | | | |
| | | | |
| static const int kMaxInliningLevels = 3; | | | |
| | | | |
| // Call count before primitive functions trigger their own optimization. | | | |
| static const int kCallsUntilPrimitiveOpt = 200; | | | |
| | | | |
| // All routines return a SharedFunctionInfo. | | | |
| // If an error occurs an exception is raised and the return handle | | | |
| // contains NULL. | | | |
| | | | |
| // Compile a String source within a context. | | | |
| static Handle<SharedFunctionInfo> Compile(Handle<String> source, | | | |
| Handle<Object> script_name, | | | |
| int line_offset, | | | |
| int column_offset, | | | |
| v8::Extension* extension, | | | |
| ScriptDataImpl* pre_data, | | | |
| Handle<Object> script_data, | | | |
| NativesFlag is_natives_code); | | | |
| | | | |
| // Compile a String source within a context for Eval. | | | |
| static Handle<SharedFunctionInfo> CompileEval(Handle<String> source, | | | |
| Handle<Context> context, | | | |
| bool is_global, | | | |
| LanguageMode language_mode, | | | |
| int scope_position); | | | |
| | | | |
| // Compile from function info (used for lazy compilation). Returns true o | | | |
| n | | | |
| // success and false if the compilation resulted in a stack overflow. | | | |
| static bool CompileLazy(CompilationInfo* info); | | | |
| | | | |
| static void RecompileParallel(Handle<JSFunction> function); | | | |
| | | | |
| // Compile a shared function info object (the function is possibly lazily | | | |
| // compiled). | | | |
| static Handle<SharedFunctionInfo> BuildFunctionInfo(FunctionLiteral* node | | | |
| , | | | |
| Handle<Script> script | | | |
| ); | | | |
| | | | |
| // Set the function info for a newly compiled function. | | | |
| static void SetFunctionInfo(Handle<SharedFunctionInfo> function_info, | | | |
| FunctionLiteral* lit, | | | |
| bool is_toplevel, | | | |
| Handle<Script> script); | | | |
| | | | |
| static void InstallOptimizedCode(OptimizingCompiler* info); | | | |
| | | | |
| #ifdef ENABLE_DEBUGGER_SUPPORT | | | |
| static bool MakeCodeForLiveEdit(CompilationInfo* info); | | | |
| #endif | | #endif | |
|
| | | | |
| static void RecordFunctionCompilation(Logger::LogEventsAndTags tag, | | | |
| CompilationInfo* info, | | | |
| Handle<SharedFunctionInfo> shared); | | | |
| }; | | | |
| | | | |
| } } // namespace v8::internal | | | |
| | | | |
| #endif // V8_COMPILER_H_ | | | |
| | | | |
End of changes. 3 change blocks. |
| 471 lines changed or deleted | | 30 lines changed or added | |
|
| dbclient_rs.h | | dbclient_rs.h | |
| | | | |
| skipping to change at line 209 | | skipping to change at line 209 | |
| | | | |
| /** | | /** | |
| * checks all sets for current master and new secondaries | | * checks all sets for current master and new secondaries | |
| * usually only called from a BackgroundJob | | * usually only called from a BackgroundJob | |
| */ | | */ | |
| static void checkAll( bool checkAllSecondaries ); | | static void checkAll( bool checkAllSecondaries ); | |
| | | | |
| /** | | /** | |
| * Removes the ReplicaSetMonitor for the given set name from _sets,
which will delete it. | | * Removes the ReplicaSetMonitor for the given set name from _sets,
which will delete it. | |
| * If clearSeedCache is true, then the cached seed string for this
Replica Set will be removed | | * If clearSeedCache is true, then the cached seed string for this
Replica Set will be removed | |
|
| * from _setServers. | | * from _seedServers. | |
| */ | | */ | |
| static void remove( const string& name, bool clearSeedCache = false
); | | static void remove( const string& name, bool clearSeedCache = false
); | |
| | | | |
| static int getMaxFailedChecks() { return _maxFailedChecks; }; | | static int getMaxFailedChecks() { return _maxFailedChecks; }; | |
| static void setMaxFailedChecks(int numChecks) { _maxFailedChecks =
numChecks; }; | | static void setMaxFailedChecks(int numChecks) { _maxFailedChecks =
numChecks; }; | |
| | | | |
| /** | | /** | |
| * this is called whenever the config of any replica set changes | | * this is called whenever the config of any replica set changes | |
| * currently only 1 globally | | * currently only 1 globally | |
| * asserts if one already exists | | * asserts if one already exists | |
| | | | |
| skipping to change at line 336 | | skipping to change at line 336 | |
| * @param verbose | | * @param verbose | |
| * @param nodesOffset - offset into _nodes array, -1 for not in it | | * @param nodesOffset - offset into _nodes array, -1 for not in it | |
| * | | * | |
| * @return true if the connection is good or false if invariant | | * @return true if the connection is good or false if invariant | |
| * is broken | | * is broken | |
| */ | | */ | |
| bool _checkConnection( DBClientConnection* conn, string& maybePrima
ry, | | bool _checkConnection( DBClientConnection* conn, string& maybePrima
ry, | |
| bool verbose, int nodesOffset ); | | bool verbose, int nodesOffset ); | |
| | | | |
| /** | | /** | |
|
| * Save the seed list for the current set into the _setServers map | | * Save the seed list for the current set into the _seedServers map | |
| * Should only be called if you're already holding _setsLock and th
is | | * Should only be called if you're already holding _setsLock and th
is | |
| * monitor's _lock. | | * monitor's _lock. | |
| */ | | */ | |
| void _cacheServerAddresses_inlock(); | | void _cacheServerAddresses_inlock(); | |
| | | | |
| string _getServerAddress_inlock() const; | | string _getServerAddress_inlock() const; | |
| | | | |
| NodeDiff _getHostDiff_inlock( const BSONObj& hostList ); | | NodeDiff _getHostDiff_inlock( const BSONObj& hostList ); | |
| bool _shouldChangeHosts( const BSONObj& hostList, bool inlock ); | | bool _shouldChangeHosts( const BSONObj& hostList, bool inlock ); | |
| | | | |
| | | | |
| skipping to change at line 400 | | skipping to change at line 400 | |
| 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, only used by th
e deprecated getSlave | | 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 | | // last host returned by _selectNode, used for round robin selectio
n | |
| HostAndPort _lastReadPrefHost; | | 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 _seedServers and _sets | |
| static map<string,ReplicaSetMonitorPtr> _sets; // set name to Monit | | | |
| or | | // set name to seed list. | |
| static map<string,vector<HostAndPort> > _seedServers; // set name t | | // Used to rebuild the monitor if it is cleaned up but then the set | |
| o seed list. Used to rebuild the monitor if it is cleaned up but then the s | | is accessed again. | |
| et is accessed again. | | static map<string, vector<HostAndPort> > _seedServers; | |
| | | static map<string, ReplicaSetMonitorPtr> _sets; // set name to Moni | |
| | | tor | |
| | | | |
| 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 674 | | skipping to change at line 677 | |
| * destroying the returned iterator. | | * destroying the returned iterator. | |
| */ | | */ | |
| BSONObjIterator* getIterator() const; | | BSONObjIterator* getIterator() const; | |
| | | | |
| /** | | /** | |
| * @returns true if the other TagSet has the same tag set specifica
tion with | | * @returns true if the other TagSet has the same tag set specifica
tion with | |
| * this tag set, disregarding where the current iterator is poi
nting to. | | * this tag set, disregarding where the current iterator is poi
nting to. | |
| */ | | */ | |
| bool equals(const TagSet& other) const; | | bool equals(const TagSet& other) const; | |
| | | | |
|
| | | const BSONArray& getTagBSON() const; | |
| | | | |
| private: | | private: | |
| /** | | /** | |
| * This is purposely undefined as the semantics for assignment can
be | | * This is purposely undefined as the semantics for assignment can
be | |
| * confusing. This is because BSONArrayIteratorSorted shouldn't be | | * confusing. This is because BSONArrayIteratorSorted shouldn't be | |
| * copied (because of how it manages internal buffer). | | * copied (because of how it manages internal buffer). | |
| */ | | */ | |
| TagSet& operator=(const TagSet& other); | | TagSet& operator=(const TagSet& other); | |
| BSONObj _currentTag; | | BSONObj _currentTag; | |
| bool _isExhausted; | | bool _isExhausted; | |
| | | | |
| | | | |
| skipping to change at line 705 | | skipping to change at line 710 | |
| * position). | | * position). | |
| */ | | */ | |
| ReadPreferenceSetting(ReadPreference pref, const TagSet& tag): | | ReadPreferenceSetting(ReadPreference pref, const TagSet& tag): | |
| pref(pref), tags(tag) { | | pref(pref), tags(tag) { | |
| } | | } | |
| | | | |
| inline bool equals(const ReadPreferenceSetting& other) const { | | inline bool equals(const ReadPreferenceSetting& other) const { | |
| return pref == other.pref && tags.equals(other.tags); | | return pref == other.pref && tags.equals(other.tags); | |
| } | | } | |
| | | | |
|
| | | BSONObj toBSON() const; | |
| | | | |
| const ReadPreference pref; | | const ReadPreference pref; | |
| TagSet tags; | | TagSet tags; | |
| }; | | }; | |
| } | | } | |
| | | | |
End of changes. 5 change blocks. |
| 8 lines changed or deleted | | 14 lines changed or added | |
|