搜索

MongoDB源码分析--Command体系架构

发表于 2025-11-05 12:27:59 来源:益强智未来
MongoDB源码分析--Command体系架构
复制//commands.h class Command {   public:   //执行当前Command时所使用的码分锁类型 enum LockType { READ = -1/*读*/ , NONE = 0 /*无锁*/, WRITE = 1 /*写*/};   const string name;   /* 运行指定的命令,需要子类实现      fromRepl - command is being invoked as part of replication syncing.  In this situation you      normally do not want to log the command to the local oplog.      如执行成功返回true,体系否则为false, errmsg记录错误信息      */ virtualbool run(const string& db, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool fromRepl) = 0;   /*      note: logTheTop() MUST be false if READ      if NONE, cant use Client::Context setup      use with caution      */ virtual LockType locktype() const = 0;   /* 是否有管理特权才可运行该命令 has privileges to run this command. */ virtualbool adminOnly() const {   returnfalse;      }   //html格式的帮助信息 void htmlHelp(stringstream&) const;   /* 与adminOnly相似,但更严格: 要么被验证,要么只运行在本地接口(local interface)      注:当本属性为true时,架构adminOnly()也必须为true.      */ virtualbool localHostOnlyIfNoAuth(const BSONObj& cmdObj) { returnfalse; }   /* 如果replication pair 的码分slaves可以运行命令的网站模板,则返回true      (the command directly from a client -- if fromRepl,体系 always allowed).      */ virtualbool slaveOk() const = 0;   /* 通过在查询命令中打开 slaveok选项,客户端强制在一个slave上运行一个命令时,架构返回true.      */ virtualbool slaveOverrideOk() {   returnfalse;      }   /* Override and return true to if true,码分log the operation (logOp()) to the replication log.      (not done if fromRepl of course)      Note if run() returns false, we do NOT log.      */ virtualbool logTheOp() { returnfalse; }   virtualvoid help( stringstream& help ) const;   /* Return true if authentication and security applies to the commands.  Some commands      (e.g., getnonce, authenticate) can be done by anyone even unauthorized.      */ virtualbool requiresAuth() { returntrue; }   /** @param webUI:在web上暴露当前command,形如 localhost:28017/<name>      @param oldName: 旧选项,体系表示当前command的架构旧(已弃用)名称      */    Command(constchar *_name, bool webUI = false, constchar *oldName = 0);   virtual ~Command() {}   protected:      BSONObj getQuery( const BSONObj& cmdObj ) {   if ( cmdObj["query"].type() == Object )   return cmdObj["query"].embeddedObject();   if ( cmdObj["q"].type() == Object )   return cmdObj["q"].embeddedObject();   return BSONObj();      }   staticvoid logIfSlow( const Timer& cmdTimer,  const string& msg);   //command map,其包含系统实现的所有command对象,免费源码下载以便findCommand查询时使用 //注意也包含该command的码分旧名称(构造方法中的oldName参数)所对应的对象, static map<string,体系Command*> * _commands;   //与上面形同,但不含旧名称的架构command map static map<string,Command*> * _commandsByBestName;   //将web类型的command放到该map中 static map<string,Command*> * _webCommands;   public:   staticconst map<string,Command*>* commandsByBestName() { return _commandsByBestName; }   staticconst map<string,Command*>* webCommands() { return _webCommands; }   /** @return 返回是站群服务器否找到或已执行command */ staticbool runAgainstRegistered(constchar *ns, BSONObj& jsobj, BSONObjBuilder& anObjBuilder);   static LockType locktype( const string& name );   //根据命令名称在集合中找到相应Command对象 static Command * findCommand( const string& name );   };  1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16.17.18.19.20.21.22.23.24.25.26.27.28.29.30.31.32.33.34.35.36.37.38.39.40.41.42.43.44.45.46.47.48.49.50.51.52.53.54.55.56.57.58.59.60.61.62.63.64.65.66.67.68.69.70.71.72.73.74.75.76.77.78.79.80.81.82.83.84.85.86.87.88.89.90.91.92.93.94.
随机为您推荐
版权声明:本站资源均来自互联网,如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

Copyright © 2016 Powered by MongoDB源码分析--Command体系架构,益强智未来  滇ICP备2023006006号-17sitemap

回顶部