How much does the node latest data weights on the election process?

In the lecture “Failover and Elections” from the second chapter, it was mentioned that in the election process, the node with the latest data, has priority over the other ones in the election.
In the documentation, I couldn’t find anything related to this.
So is this actually true? Do the nodes with fresher and latest data have priority in the election? (if the priority in the config is not tampered with).

Thank you.
Sebastian

2 Likes

Hi Sebastian_42124,

As far as I know, you are right, odes with fresher and latest data have priority in the election. Actually, its related to which node has the latest oplog timestamp which eventually means which has the latest data.

Meanwhile, I am searching in the documentation.

Kanika

1 Like

Hi Sebastian,

Please refer to the documentation link attached below.
https://docs.mongodb.com/manual/core/replica-set-elections/index.html
In the ‘Member Priority’ section it is mentioned that
"After a replica set has a stable primary, the election algorithm will make a “best-effort” attempt to have the secondary with the highest priority available call an election. Member priority affects both the timing and the outcome of elections; secondaries with higher priority call elections relatively sooner than secondaries with lower priority, and are also more likely to win. **However, a lower priority instance can be elected as primary for brief periods, even if a higher priority secondary is available. Replica set members continue to call elections until the highest priority member available becomes primary.**

Members with a priority value of 0 cannot become primary and do not seek election."

Also please refer to sections ‘Detection of Simultaneous Primaries & Back to Back Elections’ from
https://docs.mongodb.com/manual/reference/replica-set-protocol-versions/

Hope that answers…

Thanks,
Hari

Hi @harikrishnan_r,
I think @Sebastian_42124 was asking if secondary nodes with the latest data have more chances of winning the elections. Your quote mentioned the priority which is basically a setting value that can be set on nodes, which from what I understand has nothing to do with how “fresh” the data is on that node. Please correct me if I’m wrong.

As for the [quote=“harikrishnan_r, post:3, topic:7034”]Detection of Simultaneous Primaries & Back to Back Elections[/quote] I cannot find anything related between stale data and it’s effects on election winning.

Am I missing something? Thanks!

Regards, Mihai

Hi @Mihai_52198,

The question had the part with replica-set priority in config file mentioned.

“Do the nodes with fresher and latest data have priority in the election? (if the priority in the config is not tampered with)

As mentioned in the above post the nodes with recent data would be given priority in the election. I would like to quote the below lines alone to be more clear,

However, a lower priority instance can be elected as primary for brief periods even if a higher priority secondary is available.

This lower priority member can have the fresh data. Even though the config file has a lower priority for this node, it can be primary node for brief periods until a node with higher priority copies the op-log entries from the lower priority node.

Replica set members continue to call elections until the highest priority member available becomes primary.

Once the data in both the nodes are synced the back-back elections would help the node with high priority in the config file, win election and become primary.

I hope my understanding is correct. Please correct me if I’m wrong… :slight_smile:

Thanks,
Hari

@harikrishnan_r, @Kanika
Thank you for the responses.

@harikrishnan_r,
I just wanted to know if the nodes with fresher data have higher chances of getting elected. So it was confusing for me that I only read about priority in the docs, and nothing about the data that the node contains. From my understanding the priority can be set in the config, so that is why I was asking apart from that setting, if the freshness of the data is also a factor.

However, a lower priority instance can be elected as primary for brief periods even if a higher priority secondary is available.

This lower priority member can have the fresh data. Even though the config file has a lower priority for this node, it can be primary node for brief periods until a node with higher priority copies the op-log entries from the lower priority node.

If the lower priority member has the fresh data, then I understand it. But from the initial sentence in the doc, that was not clear to me at first. It only mentioned that one low priority member can be elected as primary for brief periods, but it didn’t say the reason (for example having fresher data).

Thanks,
Best regards,
Sebastian