简体   繁体   中英

How do primary and secondary servers work in MongoDB?

So I have 8 servers intotal. Lets name them this:

P1, S2, S3, S4, S5, S6, S7, and S8.

P1 being the primary server and the rest being secondary.

Scenario #1:

P1 loses internet connection and goes down. From my understanding, one of the secondary servers will take over.

What happens if P1 comes back online? Will it become primary again once it becomes online? What happens to any changes P1 makes while it was offline?

Scenario #2:

S4 loses internet connection and goes down.

When S4 goes offline, will it become primary for itself? And will it be able to makes changes to its own database? Once it goes back online and syncs with the main database what will decide what changes has more precedence then the other? Time when it was changed?

What happens if P1 comes back online? Will it become primary again once it becomes online? What happens to any changes P1 makes while it was offline?

No. P1 will come back online in the Secondary state. P1 could only become Primary again if another replica set election were to occur. See replication for more information.

There should be no changes to P1 while it is not in the Primary state. In the event of a dual Primary scenario, any writes made to P1 will be rolled back once it discovers it is no longer the Primary and begins a reconciliation process to become fully in sync.

When S4 goes offline, will it become primary for itself? And will it be able to makes changes to its own database? Once it goes back online and syncs with the main database what will decide what changes has more precedence then the other? Time when it was changed?

S4 will not become a Primary for itself. The server is being run as a member of a replica set and is aware that it cannot communicate with a majority of the replica set, thereby making it ineligible to be in the Primary state.

When the network partition is resolved, S4 will query the Primary node and compare its most recent oplog entry to the oplog on the Primary node. Writes will be applied in the order in which they are recorded in the oplog of the Primary.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM