From 7645618fd3914cb8a20561625913c20d49504a49 Mon Sep 17 00:00:00 2001 From: Antonin Kral Date: Wed, 11 Aug 2010 12:38:57 +0200 Subject: Imported Upstream version 1.6.0 --- s/d_logic.h | 139 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 137 insertions(+), 2 deletions(-) (limited to 's/d_logic.h') diff --git a/s/d_logic.h b/s/d_logic.h index e426cb2..0f7ba35 100644 --- a/s/d_logic.h +++ b/s/d_logic.h @@ -18,10 +18,135 @@ #pragma once -#include "../stdafx.h" +#include "../pch.h" +#include "../db/jsobj.h" +#include "util.h" namespace mongo { + + class ShardingState; + + typedef ShardChunkVersion ConfigVersion; + typedef map NSVersionMap; + + // ----------- + + class ChunkMatcher { + typedef map,BSONObjCmp> MyMap; + public: + + bool belongsToMe( const BSONObj& key , const DiskLoc& loc ) const; + + private: + ChunkMatcher( ConfigVersion version ); + + void gotRange( const BSONObj& min , const BSONObj& max ); + + ConfigVersion _version; + BSONObj _key; + MyMap _map; + + friend class ShardingState; + }; + + typedef shared_ptr ChunkMatcherPtr; + + // -------------- + // --- global state --- + // -------------- + + class ShardingState { + public: + ShardingState(); + + bool enabled() const { return _enabled; } + const string& getConfigServer() const { return _configServer; } + void enable( const string& server ); + + void gotShardName( const string& name ); + void gotShardHost( const string& host ); + + bool hasVersion( const string& ns ); + bool hasVersion( const string& ns , ConfigVersion& version ); + ConfigVersion& getVersion( const string& ns ); // TODO: this is dangeroues + void setVersion( const string& ns , const ConfigVersion& version ); + + void appendInfo( BSONObjBuilder& b ); + + ChunkMatcherPtr getChunkMatcher( const string& ns ); + + bool inCriticalMigrateSection(); + private: + + bool _enabled; + + string _configServer; + + string _shardName; + string _shardHost; + + mongo::mutex _mutex; + NSVersionMap _versions; + map _chunks; + }; + + extern ShardingState shardingState; + + // -------------- + // --- per connection --- + // -------------- + + class ShardedConnectionInfo { + public: + ShardedConnectionInfo(); + + const OID& getID() const { return _id; } + bool hasID() const { return _id.isSet(); } + void setID( const OID& id ); + + ConfigVersion& getVersion( const string& ns ); // TODO: this is dangeroues + void setVersion( const string& ns , const ConfigVersion& version ); + + static ShardedConnectionInfo* get( bool create ); + static void reset(); + + bool inForceMode() const { + return _forceMode; + } + + void enterForceMode(){ _forceMode = true; } + void leaveForceMode(){ _forceMode = false; } + + private: + + OID _id; + NSVersionMap _versions; + bool _forceMode; + + static boost::thread_specific_ptr _tl; + }; + + struct ShardForceModeBlock { + ShardForceModeBlock(){ + info = ShardedConnectionInfo::get( false ); + if ( info ) + info->enterForceMode(); + } + ~ShardForceModeBlock(){ + if ( info ) + info->leaveForceMode(); + } + + ShardedConnectionInfo * info; + }; + + // ----------------- + // --- core --- + // ----------------- + unsigned long long extractVersion( BSONElement e , string& errmsg ); + + /** * @return true if we have any shard info for the ns */ @@ -35,5 +160,15 @@ namespace mongo { /** * @return true if we took care of the message and nothing else should be done */ - bool handlePossibleShardedMessage( Message &m, DbResponse &dbresponse ); + bool handlePossibleShardedMessage( Message &m, DbResponse * dbresponse ); + + void logOpForSharding( const char * opstr , const char * ns , const BSONObj& obj , BSONObj * patt ); + + // ----------------- + // --- writeback --- + // ----------------- + + /* queue a write back on a remote server for a failed write */ + void queueWriteBack( const string& remote , const BSONObj& o ); + } -- cgit v1.2.3