The 1:local library is a system library of MongoDB that records information such as timestamps and indexes and replication sets.
Gechongrepl:primary> use localswitched to DB localgechongrepl:primary> show Tablesmeoplog.rsreplset.minvalidslavesstartup_logsystem.indexessystem.replsettemp
The contents of each collection under the 2:local library are recorded separately
The Me collection under the local library holds the server name the Replset.minvalid collection under the local library holds the timestamp for the latest operation of the database Startup_ under the local library The log collection records this mongod each time the boot information in the local library below the System.indexes Collection records all index information for the current library The System.replset under the local library records the member configuration information for the replica set rs.conf () Read this collection The Oplog.rs collection under the local library records all of these operations MongoDB is through the oplog.rs to achieve data synchronization. When the primary node inserts a single piece of data, there is one more record in the Oplog.rs collection
3: Simulate data insertion to observe changes in oplog.rs
Gechongrepl:primary> use testoplogswitched to db testoploggechongrepl:primary> Db.user.insert ({"Name": " Shanghai "}) Writeresult ({" ninserted ": 1}) gechongrepl:primary> use localswitched to DB localgechongrepl:primary> Db.oplog.rs.find () {"_id": ObjectId ("5593628989b809ea7938cc09"), "TS": Timestamp (1435721382, 1), "H": Numberlong ("- 5496045509734463589 ")} {" TS ": Timestamp (1435733782, 1)," H ": Numberlong (" 3093554192925239676 ")," V ": 2," OP ":" N "," N S ":" "," O ": {" msg ":" Reconfig Set "," Version ":" $ "} {" TS ": Timestamp (1435734113, 1)," H ": Numberlong (" 2858511747 060359631 ")," V ": 2," OP ":" N "," ns ":" "," O ": {" msg ":" Reconfig Set "," Version ": +}} {" TS ": Timestamp (14357412 1), "H": Numberlong (" -4071658638798562344"), "V": 2, "OP": "I", "ns": "Test.testfile", "O": {"_id": ObjectId ("5 593ac558336a98fb6114045 ")," a ":" 1 "}} {" TS ": Timestamp (1435745379, 1)," H ": Numberlong (" 2363981837641873443 ")," V ": 2, "Op": "I", "ns": "Test.testfile", "O": {"_id": ObjectId ("5593bc638336a98fb6114046"), "a": "1"}} {"TS": Timestamp (1435745380, 1), "H": Numberlong ("141517 7671185209492 ")," V ": 2," OP ":" I "," ns ":" Test.testfile "," O ": {" _id ": ObjectId (" 5593bc648336a98fb6114047 ")," a ": "1"}} {"TS": Timestamp (1435745570, 1), "H": Numberlong (" -8642862752172159081"), "V": 2, "OP": "N", "ns": "", "O": {"MSG": "Reconfig Set", "Version": 59}} {"TS": Timestamp (1435746145, 1), "H": Numberlong ("4895205971378560688"), "V": 2, "OP": "N", "ns": "", "O": {"MSG" : "Reconfig Set", "Version": -6248101199236942548}} {"TS": Timestamp (1435803750, 1), "H": Numberlong (""), "V": 2, "Op": "I", "ns": "Testoplog.user", "O": {"_id": ObjectId ("5594a065a26e221874aa3e32"), "name": "Shanghai"}}
TS: Two parameters: The first represents a timestamp; the second represents the number of operations per second op: opcode: i means insert; NS: Operation namespace O: Indicates the Document object that the insert operation contains
Detailed procedures for 4:secondary and primary data synchronization
When the primary node completes the data operation, secondary will make a series of actions to ensure the synchronization of the data: 1: Check your local library's oplog.rs collection to find the most recent timestamp. 2: Check the primary node local library Oplog.rs collection to find records larger than this timestamp. 3: Insert the found records into your own oplog.rs collection and perform these operations.
Note: The newly synced data is not viewable. Secondary default is unreadable and not writable. If you need to see if you want to perform rs.slaveok (), the current connection can be viewed, and subsequent connections or unreadable are not writable.
For more information on oplog.rs, please refer to the previous blog post:
Http://www.cnblogs.com/xiaoit/p/4585363.html
MongoDB Replica Set Configuration series 10: MongoDB local library details and data synchronization principles