NodeBB icon indicating copy to clipboard operation
NodeBB copied to clipboard

Use MongoDB transactions

Open oplik0 opened this issue 4 years ago • 0 comments

I mentioned that it'd be quite simple to add MongoDB transactions in #9898 - so I decided to try it, even if it's not ideal when it comes to consistency.

I think I handled all parts of MongoDB driver where multiple writes occur (since single operations are atomic anyway).

Transactions only work on replica sets on a version newer than MongoDB 4.0, unfortunately. On singular instances nothing improves in terms of consistency. As such the current tests never take the transaction path - and to change that would require adding another entry to test matrix for newer replica set MongoDB. If it's fine to do so, I'll be glad to update this PR to have testing done properly for replica sets, but currently I just made a separate branch with all mongo tests modified to use replica sets: https://github.com/oplik0/NodeBB/actions/runs/1351224224

Edit: also now tested different mongo versions with replica set enabled:

  • 3.2 where transactions aren't yet supported: https://github.com/oplik0/NodeBB/runs/3918454468
  • 5.0 which I expected to work but good to know a major bump didn't break anything :) https://github.com/oplik0/NodeBB/actions/runs/1351273045

oplik0 avatar Oct 17 '21 11:10 oplik0