mongodb - main 函数入口

main函数在: /src/mongo/db/db.cpp  


主函数实现的步骤在: main -> mongoDbMain 

主要工作:

  • 参数解析
  • 内存文件flush到硬盘 (线程)
  • 服务监听 


详细事情: 

  1. 检测CPU是大端还是小端,大端就不支持了
  2. 解析输入的命令参数
  3. 每隔一分钟对所有内存映射文件进行flush操作到磁盘dataFileSync.go();
  4. 服务监听 initAndListen


1234 static int mongoDbMain(int argc, char* argv[], char **envp) {                    
1235     static StaticObserver staticObserver;                                        
1236                                                                                  
1237     getcurns = ourgetns;                                                         
1238                                                                                  
1239     setupSignalHandlers();                                                       
1240                                                                                  
1241     dbExecCommand = argv[0];      // 此处莫非是暗示我们所有的binary都是由这一个main所在文件build出来的?                              
1242                                                                                  
1243     srand(curTimeMicros());       // 设置随机数种子                                               
1244                                                                                  
1245     {                                                                            
1246         unsigned x = 0x12345678;                                                 
1247         unsigned char& b = (unsigned char&) x;                                   
1248         if ( b != 0x78 ) {                                                       
1249             out() << "big endian cpus not yet supported" << endl;                
1250             return 33;                                                           
1251         }                                                                        
1252     }                                                                            
1253                                                                                  
1254     if( argc == 1 )                                                              
1255         cout << dbExecCommand << " --help for help and startup options" << endl; 
1256                                                                                  
1257     //   输入参数解析
1258     processCommandLineOptions(std::vector<std::string>(argv, argv + argc));      
1259     mongo::runGlobalInitializersOrDie(argc, argv, envp);                         
1260     CmdLine::censor(argc, argv);                                                 
1261                                                                                  
1262     if (!initializeServerGlobalState())                                          
1263         ::_exit(EXIT_FAILURE);                                                   
1264                                                                                  
1265     // Per SERVER-7434, startInterruptThread() must run after any forks          
1266     // (initializeServerGlobalState()) and before creation of any other threads. 
1267     startInterruptThread();                                                      
1268                                                                                  
1269     dataFileSync.go();          // 将内存数据flush到磁盘                                                 
1270                                                                                  
1271 #if defined(_WIN32)                                                              
1272     if (ntservice::shouldStartService()) {                                       
1273         ntservice::startService();                                               
1274         // exits directly and so never reaches here either.                      
1275     }                                                                            
1276 #endif                                                                           
1277                                                                                  
1278     StartupTest::runTests();                                                     
1279     initAndListen(cmdLine.port);        // 服务监听                                         
1280     dbexit(EXIT_CLEAN);                                                          
1281     return 0;                                                                    
1282 }     


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值