MongoDB2011/6/28
•                  @nobu_k    •   Preferred Infrastructure (PFI)    •   Sedue•   Sedue        MongoDB(1.6)    •           ...
• oplog•
• MongoDB  • https://github.com/mongodb/mongo/     commits/master/•                 2011/6/26    •2•        pull
oplog•
•                       2    • createOplog    • logOp    • db/oplog[h,cpp]•
createOplog• oplog•
createOplogvoid createOplog() {                                 > use local  dblock lk;     // DB                         ...
oplogClient::Context ctx(ns);         //         NSNamespaceDetails * 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_...
CmdLine•    •   db/cmdline.[h, cpp]•                                  boost::program_options•   extern                    ...
Client::Context•    •            NS    •   Client    •   db/client.[h,cpp]•   RAII•   DB
currentClient•                                   Client    •            Thread Local    • boost::thread_specific_ptr<Client...
DBDirectClient••   DBClientInterface (client/dbclient.h)•   DBConnector (client/dbclient.h)•   DBClientWithCommands : publ...
NamespaceDetails• .ns               (1   )•  • Database  • MongoDataFile  • Record•
nsdetails•           Context NamespaceDetails    •   db/pdfile.h•   cc().database()->namespaceIndex->details•   NamespaceIn...
logOp••
oplog{    ts:                • oplog   BSON    op:    ns:       NS       •    o: BSON    o2:}                      •      ...
•   i : insert•   u : update•   d : delete•   c : db cmd? userCreateNS?•   db : declares presence of a database•   n : no ...
logOp_logOpvoid logOp(const char *opstr, const char *ns, const BSONObj& obj, BSONObj *patt, bool *b) { if ( replSettings.m...
_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    ••             (´   ω   `)
Upcoming SlideShare
Loading in...5
×

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

1,710

Published on

Published in: Technology
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,710
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
9
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • 第一回MongoDBソースコードリーディング

    1. 1. MongoDB2011/6/28
    2. 2. • @nobu_k • Preferred Infrastructure (PFI) • Sedue• Sedue MongoDB(1.6) • CT○ • http://slidesha.re/hl8PyL • MongoDB as Search Engine Repository
    3. 3. • oplog•
    4. 4. • MongoDB • https://github.com/mongodb/mongo/ commits/master/• 2011/6/26 •2• pull
    5. 5. oplog•
    6. 6. • 2 • createOplog • logOp • db/oplog[h,cpp]•
    7. 7. createOplog• oplog•
    8. 8. createOplogvoid 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. 9. oplogClient::Context ctx(ns); // NSNamespaceDetails * nsd = nsdetails( ns );if ( nsd ) { // oplog ... ... ... ...}
    10. 10. • oplog• ReplicaSet •
    11. 11. oplog• oplog• 1. oplog 2. BSON NS • BSON!! 3. oplog
    12. 12. • • Mac• oplog capped collection
    13. 13. createOplog• • db/repl.cpp • db/repl/rs_initialsync.cpp • db/repl/rs_initiate.cpp• ReplicaSet •
    14. 14. • • dblock • CmdLine • Context • DBDirectClient • NamespaceDetails, nsdetails•
    15. 15. dblock• DB • db/concurrency.h• Deprecated • writelock• dbMutex • scoped_lock • RAII
    16. 16. CmdLine• • db/cmdline.[h, cpp]• boost::program_options• extern 2 • db/db.cpp // • client/clientOnly.cpp //
    17. 17. Client::Context• • NS • Client • db/client.[h,cpp]• RAII• DB
    18. 18. currentClient• Client • Thread Local • boost::thread_specific_ptr<Client> • cc(), currenctClient, Context::getClient• DB
    19. 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. 20. NamespaceDetails• .ns (1 )• • Database • MongoDataFile • Record•
    21. 21. nsdetails• Context NamespaceDetails • db/pdfile.h• cc().database()->namespaceIndex->details• NamespaceIndex • map<string, NamespaceDetails> •
    22. 22. logOp••
    23. 23. oplog{ ts: • oplog BSON op: ns: NS • o: BSON o2:} • o2
    24. 24. • i : insert• u : update• d : delete• c : db cmd? userCreateNS?• db : declares presence of a database• n : no op ( ) • • keep alive•
    25. 25. logOp_logOpvoid 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. 26. _logOp• • _logOpOld • _logOpRS • etc?•
    27. 27. _logOpOld•• Record theDataFileMgr • fast_oplog_insert!!• ( mmap )
    28. 28. append_O_Obj• partial ”o”+• BSONBuilder • • repeatedly ed
    29. 29. _logOpRS•
    30. 30. logOp•• grep it!
    31. 31. • applyOperation_inlock• pretouch
    32. 32. We are hiring !• • •• •• • • OSS •• (´ ω `)
    1. A particular slide catching your eye?

      Clipping is a handy way to collect important slides you want to go back to later.

    ×