xp-forge / mongodb

MongoDB for the XP Framework
0 stars 0 forks source link

Retry "Exception: not primary" when writing #43

Closed thekid closed 1 year ago

thekid commented 1 year ago

The clientside cluster view may become outdated, causing us to erroneously write to non-primary nodes. This is how this can occur (see https://github.com/xp-forge/mongodb/issues/42#issuecomment-1712795735):

Event Client view Server side situation
Client: Before (n/a) {Primary: A, Secondary: [B, C]}
Client: Connect {Primary: A, Secondary: [B, C]} {Primary: A, Secondary: [B, C]}
Remote: Primary change {Primary: A, Secondary: [B, C]} {Primary: B, Secondary: [A, C]}
Client: Write {Primary: A, Secondary: [B, C]} {Primary: B, Secondary: [A, C]}

The client has an inconsistent view of the server side situation and uses node A for writing which it believes to be the primary, while in reality it's changed its role to a secondary.

If we encounter an error indicating this condition, we now refresh the cluster view, then retry the write once.

thekid commented 1 year ago

Released in https://github.com/xp-forge/mongodb/releases/tag/v2.1.0