在上一篇博客mongo源码学习(三)请求接收传输层中,稍微分析了一下TransportLayer的作用,这篇来看下ServiceEntryPoint是怎么做的。

首先ServiceEntryPoint的定义在mongo/src/mongo/transport目录下。

废话不过说,直接上代码。

service_entry_point.h

namespace mongo {

/**
 * This is the entrypoint from the transport layer into mongod or mongos.
 *
 * The ServiceEntryPoint accepts new Sessions from the TransportLayer, and is
 * responsible for running these Sessions in a get-Message, run-Message,
 * reply-with-Message loop.  It may not do this on the TransportLayer’s thread.
 */
/**
 * 这是从transport layer到mongod或者mongos的入口点。
 *
 * ServiceEntryPoint从TransportLayer中接收新的Session,并且负责运行这些Sessions的
 * get-Message,run-Message和reply-with-Message生命周期。它可能不会在TransportLayer的线程
 * 中这些事情。
 */
class ServiceEntryPoint {
    MONGO_DISALLOW_COPYING(ServiceEntryPoint);

public:
    virtual ~ServiceEntryPoint() = default;

    /**
     * Begin running a new Session. This method returns immediately.
     */
    /**
     * 开始一个新的Session。这个方法会马上返回。
     */
    ;

    /**
     * End all sessions that do not match the mask in tags.
     */
    /**
     * 结束所有和tags中掩码不匹配的sessions。
     */
    ;

    /**
     * Starts the service entry point
     */
    /**
     * 启动服务入口点。
     */
    ;

    /**
    * Shuts down the service entry point.
    */
    /**
     * 关闭服务入口点。
     */
    ;

    /**
     * Append high-level stats to a BSONObjBuilder for serverStatus
     */
    /**
     * 为serverStatus向BSONObjBuilder追加高级状态。
     */
    ;

    /**
    * Returns the number of sessions currently open.
    */
    /**
     * 返回当前打开的sessions数量。
     */
    ;

    /**
     * Processes a request and fills out a DbResponse.
     */
    /**
     * 处理一个请求并写入DbResponse。
     * P. S. 敲黑板了, 同志们,这里就是处理请求的地方了啊!
     */
    ;

protected:
    ServiceEntryPoint() = default;
};

}  // namespace mongo

嗯,我觉得最重要的方法就是handleRequest了,接口中方法名字取的通俗易懂,没毛病。

service_entry_pioint_impl.h

namespace mongo {
class ServiceContext;

namespace transport {
class Session;
}  // namespace transport

/**
 * A basic entry point from the TransportLayer into a server.
 *
 * The server logic is implemented inside of handleRequest() by a subclass.
 * startSession() spawns and detaches a new thread for each incoming connection
 * (transport::Session).
 */
/**
 * 从TransportLayer到server的一个基本入口点。
 *
 * 服务器处理请求的逻辑是通过子类的handleRequest()方法实现的。
 * startSession()会spawns并且分配一个新的线程来处理每个到来的连接(transport:Session)
 * spawn: (鱼、蛙等)大量产(卵);引起,酿成
 *
 */
class ServiceEntryPointImpl : public ServiceEntryPoint {
    MONGO_DISALLOW_COPYING(ServiceEntryPointImpl);

public:
    // 构造函数
    explicit ServiceEntryPointImpl(ServiceContext* svcCtx);

    void startSession(transport::SessionHandle session) override;

    void endAllSessions(transport::Session::TagMask tags) final;

    Status start() final;
    bool shutdown(Milliseconds timeout) final;

    void appendStats(BSONObjBuilder* bob) const final;

    size_t numOpenSessions() const final {
        return _currentConnections.load();
    }

private:
    using SSMList = stdx::list<std::shared_ptr<ServiceStateMachine>>;
    using SSMListIterator = SSMList::iterator;

    ServiceContext* const _svcCtx;
    AtomicWord<std::size_t> _nWorkers;

    mutable stdx::mutex _sessionsMutex;
    stdx::condition_variable _shutdownCondition;
    SSMList _sessions;

    size_t _maxNumConnections{DEFAULT_MAX_CONN};
    AtomicWord<size_t> _currentConnections{};
    AtomicWord<size_t> _createdConnections{};

    std::unique_ptr<transport::ServiceExecutorReserved> _adminInternalPool;
};

/*
 * Returns true if a session with remote/local addresses should be exempted from maxConns
 */
/*
 * 如果远程或本地的session可以从最大连接数约束中豁免则返回true
 */
bool shouldOverrideMaxConns(const transport::SessionHandle& session,
                            const std::vector<stdx::variant<CIDR, std::string>>& exemptions);

}  // namespace mongo

似乎也没有太多好说的了。接下来的service_entry_point_impl.cpp是大头,这里开始要深入到方法内部去了。

service_entry_point_impl.cpp

mongo源码学习(四)服务入口点ServiceEntryPoint的更多相关文章

  1. mongo源码学习(三)请求接收传输层

    在上一篇博客中(mongo源码学习(二)db.cpp之mongoDbMain方法分析),我们把db.cpp中的mongoDbMain的执行过程分析了一下,最后会调用initAndListen(serv ...

  2. mongo源码学习(四)invariant

    前言 在看MongoDB源码的时候,经常会看到这个玩意儿:invariant. invariant的字面意思是:不变式. 在emacs上跳转到函数定义要安装一个插件,ggtags,费了老大劲儿.这都可 ...

  3. dubbo源码学习(四):暴露服务的过程

    dubbo采用的nio异步的通信,通信协议默认为 netty,当然也可以选择 mina,grizzy.在服务端(provider)在启动时主要是开启netty监听,在zookeeper上注册服务节点, ...

  4. Dubbo源码学习之-服务导出

    前言 忙的时候,会埋怨学习的时间太少,缺少个人的空间,于是会争分夺秒的工作.学习.而一旦繁忙的时候过去,有时间了之后,整个人又会不自觉的陷入一种懒散的状态中,时间也显得不那么重要了,随便就可以浪费掉几 ...

  5. mongo源码学习(二)db.cpp之mongoDbMain方法分析

    mongo后台进程的入口:mongo/src/mongo/db/dbmain.cpp,wmain(for windows)和main函数,main函数也很简单,就是委托给db.cpp中的mongoDb ...

  6. [spring源码学习]四、IOC源码——普通bean初始化

    一.代码例子 此节开始涉及到一个bean具体生成和保存的过程,仅仅涉及到最简单的bean,代码依旧是最简单的 public static void main(String[] args) { Defa ...

  7. dubbo 源码学习1 服务发布机制

    1.源码版本:2.6.1 源码demo中采用的是xml式的发布方式,在dubbo的 DubboNamespaceHandler 中定义了Spring Framework 的扩展标签,即 <dub ...

  8. mongo源码学习(一)

    在git上把mongo的源码给拉下来了,然后目录大概是这样的: 这个mongo是用C++写的,编译并没有用Makefile而是用的scons工具,这个好像是python写的. mongo后台进程的入口 ...

  9. 菜鸟系列Fabric源码学习—orderer服务启动

    Fabric 1.4 orderer 服务启动流程 1.提要 orderer提供broadcast和deliver两个服务接口.orderer节点与各个peer节点通过grpc连接,orderer将所 ...

随机推荐

  1. 【转载,整理】Spotlight 监控

    非常好用,安装简易的监控软件 官网:https://www.quest.com spotlight官网链接地址:https://www.quest.com/products/#%20 一. Spotl ...

  2. U811.1接口EAI系列之二--生成销售出库单调用U8的EAI通用处理方法--PowerBuilder语言

    1.销售系统销售出库,更新U811.1材料库存的EAI的XML生成. 2.主要根据U8配置会生成出库单和同时是否更新库存量,还是更新现存量等等. 3.具体参考代码如下: 作者:王春天 2013-11- ...

  3. MySQL 忘记root密码的两种处理方法

    [背景] 由于各个原因,我遇到过不只一次我服务的客户忘记了MySQL的root密码:如果是普通用户还好,我们可以用root用户去改它的密码,要命 的是把root给丢了! 对于MySQL来说如果你忘记了 ...

  4. talend hive数据导入到mysql中

    thiveInput->tmap->tMysqloutput thiveInput: tmap: tmysqlOutput:注意编码问题:noDatetimeStringSync=true ...

  5. git 权限问题:insufficient permission for adding an object to repository database .git

    在git pull 的时候报错:insufficient permission for adding an object to repository database .git (去仓库里的objec ...

  6. 携程的配置中心(阿波罗apollo)

    https://github.com/ctripcorp/apollo https://pan.baidu.com/s/1dFEGMIX#list/path=%2Fmeetup%20ppt%2F040 ...

  7. mysql SQLyog导入csv数据失败怎么办?

    分享下mysql使用SQLyog导入csv数据失败的解决方法 给mysql导入数据,选中某个表选择导入--导入使用本地csv数据即可,单有的时候不知道什么问题导入不成功!!! 给mysql导入数据,使 ...

  8. shiro 自定义过滤器,拦截过期session的请求,并且以ajax形式返回

    自定义过滤器: public class CustomFormAuthenticationFilter extends FormAuthenticationFilter { @Override pro ...

  9. IOS 设备备份文件详解 (二)

    这篇主要讲解如何解析Manifest.mbdb文件. 使用二进制工具打开这个文件,文件的头6个字节是固定的,相当于是文件的一种标识 后面的内容是一个一个的项,可以使用一个循环来读取文件,一个一个解析. ...

  10. haproxy-1.7.7 源码安装

    安装一下依赖 yum install openssl-devel openssl 编译安装 make TARGET=linux2628 USE_OPENSSL=1 ADDLIB=-lz make in ...