Ahmet Burak
Ahmet Burak

Reputation: 11

Assigning a dedicated Primary node for write operations in MongoDB replica set

Distribution of my MongoDB cluster consisting of 15 nodes across 3 different data centers is as listed below:

DataCenter 1:

Router-1
ConfigServer-1
Shard1Node1 [Primary]
Shard2Node2 [Secondary]
Shard3Node2 [Secondary]

DataCenter 2:

Router-2
ConfigServer-2
Shard1Node2 [Secondary]
Shard2Node1 [Primary]
Shard3Node3 [Secondary]

DataCenter 3:

Router-3
ConfigServer-3
Shard1Node3 [Secondary]
Shard2Node3 [Secondary]
Shard3Node1 [Primary]`

I have application instances running, connecting to a local MongoDB router in each of the three data centers. These instances perform write operations using zone sharding, directing them to the Primary nodes in their respective data centers. For reading data from other shards, they utilize the Secondary nodes located in their respective data centers.

In the scenario where the connection between Data Center 1 and the other data centers is lost, in view of Data Center 1; while continuing to read through the secondaries of other shards, I need to continue writing to the primary node that has been disconnected from the replica set. However, in a 3-node replica set, the remaining primary node relinquishes its primary status and becomes a secondary, rejecting write operations.

How can I solve this problem?

Update

I want all my applications distributed accross all data centers can write data and read other data centers last synced data even if they lost connection from others.

Update 2 The above setup is a simplified setup for 3 data centers, in the real scenario I have 7 data centers, so I do not want to add an extra 1 secondary next to the local primary for each new center I add.

Upvotes: 0

Views: 45

Answers (1)

Wernfried Domscheit
Wernfried Domscheit

Reputation: 59622

Not clear what you mean, the PRIMARY node is always a node which belongs to the majority of all members.

If Data Center 1 gets lost, then the new primaries will be elected either from Data Center 2 or Data Center 3.

You could change it by setting members to {priority: 0, votes: 0} at nodes in Data Center 2 and Data Center 3, however then you will lose much of your high-availability.

Upvotes: 0

Related Questions