SlideShare a Scribd company logo
MongoDB

2011/6/28
•                  @nobu_k

    •   Preferred Infrastructure (PFI)
    •   Sedue

•   Sedue        MongoDB(1.6)

    •                 CT○

        •   http://slidesha.re/hl8PyL
        •   MongoDB as Search Engine Repository
• oplog
•
• MongoDB
  • https://github.com/mongodb/mongo/
     commits/master/
•                 2011/6/26

    •2
•        pull
oplog


•
•                       2

    • createOplog
    • logOp
    • db/oplog[h,cpp]
•
createOplog


• oplog
•
createOplog
void createOplog() {                                 > use local
  dblock lk;     // DB                               switched to db local
                                                     > show collections
                             // DB.                  me
  const char * ns = "local.oplog.$main";             oplog.$main
                                                     pair.sync
                                                     slaves
                                                     sources
                                                     system.indexes
  bool rs = !cmdLine._replSet.empty();
  if( rs )
      ns = rsoplog;      // "local.oplog.rs";
                         // in db/repl/rs_optime.h


                                 NS
oplog

Client::Context ctx(ns);         //         NS

NamespaceDetails * nsd = nsdetails( ns );

if ( nsd ) {    // oplog
   ...              ...
    ...                    ...
}
• oplog
• ReplicaSet

 •
oplog
•         oplog

•
    1. oplog

    2. BSON       NS

      •                BSON!!

    3. oplog
•
    • Mac
• oplog     capped collection
createOplog
•
    •   db/repl.cpp
    •   db/repl/rs_initialsync.cpp
    •   db/repl/rs_initiate.cpp
•   ReplicaSet



    •
•
    •   dblock
    •   CmdLine
    •   Context
    •   DBDirectClient
    •   NamespaceDetails, nsdetails
•
dblock
•   DB

    •   db/concurrency.h
•   Deprecated
    •                 writelock

•                  dbMutex

    •   scoped_lock

    •   RAII
CmdLine
•
    •   db/cmdline.[h, cpp]
•                                  boost::program_options



•   extern                            2

    •   db/db.cpp //

    •   client/clientOnly.cpp //
Client::Context
•
    •            NS

    •   Client

    •   db/client.[h,cpp]
•   RAII

•   DB
currentClient
•                                   Client

    •            Thread Local

    • boost::thread_specific_ptr<Client>
    • cc(), currenctClient, Context::getClient
•                            DB
DBDirectClient
•
•   DBClientInterface (client/dbclient.h)
•   DBConnector (client/dbclient.h)
•   DBClientWithCommands : public DBClientInterface
    •   DBClientBase : public DBClientWithCommands, public DBConnector
        •   DBDirectClient : public DBClientBase
•   findOne

    •   c.findOne→DBClientInterface::findOne→DBClientInterface::findN→(virtual
           )DBDirectClient::query→DBClientBase::query

        •               DBClientCursor

•
NamespaceDetails
• .ns               (1   )

•
  • Database
  • MongoDataFile
  • Record
•
nsdetails
•           Context NamespaceDetails

    •   db/pdfile.h
•   cc().database()->namespaceIndex->details
•   NamespaceIndex
    •   map<string, NamespaceDetails>

    •
logOp


•
•
oplog
{
    ts:                • oplog   BSON
    op:
    ns:       NS       •
    o: BSON

    o2:
}                      •          o2
•   i : insert
•   u : update
•   d : delete
•   c : db cmd? userCreateNS?
•   db : declares presence of a database
•   n : no op (              )

    •
    •   keep alive
•
logOp
_logOp

void logOp(const char *opstr, const char *ns,
 const BSONObj& obj, BSONObj *patt, bool *b) {
 if ( replSettings.master ) {
   _logOp(opstr, ns, 0, obj, patt, b);
 }

    logOpForSharding( opstr , ns , obj , patt );
}
_logOp
•
    • _logOpOld
    • _logOpRS
    • etc?
•
_logOpOld
•
• Record theDataFileMgr
  • fast_oplog_insert!!
•               (       mmap
    )
append_O_Obj
• partial ”o”+
•        BSONBuilder



 •
 • repeatedly          ed
_logOpRS


•
logOp


•
• grep it!
• applyOperation_inlock
• pretouch
We are hiring           !
•
    •
    •
•
    •
•
    •
    •   OSS

    •
•             (´   ω   `)

More Related Content

PDF
PDF
openstack源码分析(1)
PPTX
Comets notes
PDF
Gogo shell
PDF
Page compression. PGCON_2016
PDF
Vidoop CouchDB Talk
PDF
LINE iOS開発で実践しているGit tips
PDF
RestMQ - HTTP/Redis based Message Queue
openstack源码分析(1)
Comets notes
Gogo shell
Page compression. PGCON_2016
Vidoop CouchDB Talk
LINE iOS開発で実践しているGit tips
RestMQ - HTTP/Redis based Message Queue

What's hot (19)

KEY
Clojure + MongoDB on Heroku
PPTX
Redis
PDF
N hidden gems you didn't know hippo delivery tier and hippo (forge) could give
PPT
Владимир Мигуро "Дао Node.js"
PPT
Mongodb
PPTX
Php 7.x 8.0 and hhvm and
PDF
NoSQL Injections in Node.js - The case of MongoDB
PDF
37562259 top-consuming-process
PPTX
Extending php (7), the basics
PDF
Security Challenges in Node.js
PPT
Sample file processing
PDF
PyCon KR 2019 sprint - RustPython by example
PPTX
Jk rubyslava 25
PDF
PuppetDB, Puppet Explorer and puppetdbquery
KEY
Coq to Rubyによる証明駆動開発@名古屋ruby会議02
PDF
Fast and cost effective geospatial analysis pipeline with AWS lambda
PDF
The Art of Command Line (2021)
PDF
Docker tips & tricks
PDF
Etcd terraform by Alex Somesan
Clojure + MongoDB on Heroku
Redis
N hidden gems you didn't know hippo delivery tier and hippo (forge) could give
Владимир Мигуро "Дао Node.js"
Mongodb
Php 7.x 8.0 and hhvm and
NoSQL Injections in Node.js - The case of MongoDB
37562259 top-consuming-process
Extending php (7), the basics
Security Challenges in Node.js
Sample file processing
PyCon KR 2019 sprint - RustPython by example
Jk rubyslava 25
PuppetDB, Puppet Explorer and puppetdbquery
Coq to Rubyによる証明駆動開発@名古屋ruby会議02
Fast and cost effective geospatial analysis pipeline with AWS lambda
The Art of Command Line (2021)
Docker tips & tricks
Etcd terraform by Alex Somesan
Ad

Similar to 第一回MongoDBソースコードリーディング (20)

PDF
MongoDB: a gentle, friendly overview
PDF
Blocks & GCD
PDF
Full metal mongo
PDF
MongoDB: Optimising for Performance, Scale & Analytics
KEY
MongoDB at GUL
KEY
NOSQL101, Or: How I Learned To Stop Worrying And Love The Mongo!
PDF
Ensuring High Availability for Real-time Analytics featuring Boxed Ice / Serv...
PDF
How to use MongoDB with CakePHP
PDF
Latinoware
PDF
Kyotoproducts
KEY
Rails with mongodb
KEY
Mongodb intro
PDF
Functional Hostnames and Why they are Bad
PDF
Take advantage of C++ from Python
PPTX
Backup, Restore, and Disaster Recovery
PPTX
Backup, Restore, and Disaster Recovery
PDF
MongoDB Munich 2012: MongoDB for official documents in Bavaria
KEY
Kiosk / PHP
PDF
Replacing Oracle with MongoDB for a templating application at the Bavarian go...
PDF
Using MongoDB and Python
MongoDB: a gentle, friendly overview
Blocks & GCD
Full metal mongo
MongoDB: Optimising for Performance, Scale & Analytics
MongoDB at GUL
NOSQL101, Or: How I Learned To Stop Worrying And Love The Mongo!
Ensuring High Availability for Real-time Analytics featuring Boxed Ice / Serv...
How to use MongoDB with CakePHP
Latinoware
Kyotoproducts
Rails with mongodb
Mongodb intro
Functional Hostnames and Why they are Bad
Take advantage of C++ from Python
Backup, Restore, and Disaster Recovery
Backup, Restore, and Disaster Recovery
MongoDB Munich 2012: MongoDB for official documents in Bavaria
Kiosk / PHP
Replacing Oracle with MongoDB for a templating application at the Bavarian go...
Using MongoDB and Python
Ad

More from nobu_k (8)

PDF
Elasticsearchと機械学習を実際に連携させる
PDF
機械学習を利用したちょっとリッチな検索
PDF
4th PFI System reading
PDF
Goraft and InfluxDB
PPT
Transactional Information Systems入門
PDF
Riak Source Code Reading #2: Erlang Client
PPTX
Paxos
KEY
Suffix Array@Solr勉強会
Elasticsearchと機械学習を実際に連携させる
機械学習を利用したちょっとリッチな検索
4th PFI System reading
Goraft and InfluxDB
Transactional Information Systems入門
Riak Source Code Reading #2: Erlang Client
Paxos
Suffix Array@Solr勉強会

Recently uploaded (20)

PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
Machine Learning_overview_presentation.pptx
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPTX
Group 1 Presentation -Planning and Decision Making .pptx
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PDF
Electronic commerce courselecture one. Pdf
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Empathic Computing: Creating Shared Understanding
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
“AI and Expert System Decision Support & Business Intelligence Systems”
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Machine Learning_overview_presentation.pptx
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Group 1 Presentation -Planning and Decision Making .pptx
Programs and apps: productivity, graphics, security and other tools
Spectral efficient network and resource selection model in 5G networks
Reach Out and Touch Someone: Haptics and Empathic Computing
Assigned Numbers - 2025 - Bluetooth® Document
Electronic commerce courselecture one. Pdf
Per capita expenditure prediction using model stacking based on satellite ima...
Mobile App Security Testing_ A Comprehensive Guide.pdf
Encapsulation_ Review paper, used for researhc scholars
Diabetes mellitus diagnosis method based random forest with bat algorithm
Building Integrated photovoltaic BIPV_UPV.pdf
Network Security Unit 5.pdf for BCA BBA.
Unlocking AI with Model Context Protocol (MCP)
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Empathic Computing: Creating Shared Understanding
Agricultural_Statistics_at_a_Glance_2022_0.pdf

第一回MongoDBソースコードリーディング

  • 2. @nobu_k • Preferred Infrastructure (PFI) • Sedue • Sedue MongoDB(1.6) • CT○ • http://slidesha.re/hl8PyL • MongoDB as Search Engine Repository
  • 4. • MongoDB • https://github.com/mongodb/mongo/ commits/master/ • 2011/6/26 •2 • pull
  • 6. 2 • createOplog • logOp • db/oplog[h,cpp] •
  • 8. createOplog void createOplog() { > use local dblock lk; // DB switched to db local > show collections // DB. me const char * ns = "local.oplog.$main"; oplog.$main pair.sync slaves sources system.indexes bool rs = !cmdLine._replSet.empty(); if( rs ) ns = rsoplog; // "local.oplog.rs"; // in db/repl/rs_optime.h NS
  • 9. oplog Client::Context ctx(ns); // NS NamespaceDetails * nsd = nsdetails( ns ); if ( nsd ) { // oplog ... ... ... ... }
  • 11. oplog • oplog • 1. oplog 2. BSON NS • BSON!! 3. oplog
  • 12. • Mac • oplog capped collection
  • 13. createOplog • • db/repl.cpp • db/repl/rs_initialsync.cpp • db/repl/rs_initiate.cpp • ReplicaSet •
  • 14. • dblock • CmdLine • Context • DBDirectClient • NamespaceDetails, nsdetails •
  • 15. dblock • DB • db/concurrency.h • Deprecated • writelock • dbMutex • scoped_lock • RAII
  • 16. CmdLine • • db/cmdline.[h, cpp] • boost::program_options • extern 2 • db/db.cpp // • client/clientOnly.cpp //
  • 17. Client::Context • • NS • Client • db/client.[h,cpp] • RAII • DB
  • 18. currentClient • Client • Thread Local • boost::thread_specific_ptr<Client> • cc(), currenctClient, Context::getClient • DB
  • 19. DBDirectClient • • DBClientInterface (client/dbclient.h) • DBConnector (client/dbclient.h) • DBClientWithCommands : public DBClientInterface • DBClientBase : public DBClientWithCommands, public DBConnector • DBDirectClient : public DBClientBase • findOne • c.findOne→DBClientInterface::findOne→DBClientInterface::findN→(virtual )DBDirectClient::query→DBClientBase::query • DBClientCursor •
  • 20. NamespaceDetails • .ns (1 ) • • Database • MongoDataFile • Record •
  • 21. nsdetails • Context NamespaceDetails • db/pdfile.h • cc().database()->namespaceIndex->details • NamespaceIndex • map<string, NamespaceDetails> •
  • 23. oplog { ts: • oplog BSON op: ns: NS • o: BSON o2: } • o2
  • 24. i : insert • u : update • d : delete • c : db cmd? userCreateNS? • db : declares presence of a database • n : no op ( ) • • keep alive •
  • 25. logOp _logOp void logOp(const char *opstr, const char *ns, const BSONObj& obj, BSONObj *patt, bool *b) { if ( replSettings.master ) { _logOp(opstr, ns, 0, obj, patt, b); } logOpForSharding( opstr , ns , obj , patt ); }
  • 26. _logOp • • _logOpOld • _logOpRS • etc? •
  • 27. _logOpOld • • Record theDataFileMgr • fast_oplog_insert!! • ( mmap )
  • 28. append_O_Obj • partial ”o”+ • BSONBuilder • • repeatedly ed
  • 32. We are hiring ! • • • • • • • • OSS • • (´ ω `)

Editor's Notes