Where does mongodb stand in the CAP theorem?

后端 未结 8 2074
鱼传尺愫
鱼传尺愫 2020-11-28 18:15

Everywhere I look, I see that MongoDB is CP. But when I dig in I see it is eventually consistent. Is it CP when you use safe=true? If so, does that mean that when I write wi

8条回答
  •  情深已故
    2020-11-28 19:01

    I'm not sure about P for Mongo. Imagine situation:

    • Your replica gets split into two partitions.
    • Writes continue to both sides as new masters were elected
    • Partition is resolved - all servers are now connected again
    • What happens is that new master is elected - the one that has highest oplog, but the data from the other master gets reverted to the common state before partition and it is dumped to a file for manual recovery
    • all secondaries catch up with the new master

    The problem here is that the dump file size is limited and if you had a partition for a long time you can loose your data forever.

    You can say that it's unlikely to happen - yes, unless in the cloud where it is more common than one may think.

    This example is why I would be very careful before assigning any letter to any database. There's so many scenarios and implementations are not perfect.

    If anyone knows if this scenario has been addressed in later releases of Mongo please comment! (I haven't been following everything that was happening for some time..)

提交回复
热议问题