dotnet / dotNext

Next generation API for .NET
https://dotnet.github.io/dotNext/
MIT License
1.56k stars 119 forks source link

ASP.net Cluster Raft question to configure full in memory mode #199

Closed guillaume-chervet closed 8 months ago

guillaume-chervet commented 8 months ago

Hi again, and still thank you for this awesome library.

I think it is my latest question for SlimFaas: https://github.com/AxaFrance/SlimFaas

I would like for security reason for some scenario to be able to set up raft cluster in full memory mode instead of hard disk usage. I would like to be able to set à mode whithout any disk write (like we can do with redis)

May you indicate to me the procedure to follow? Class to overload, ect. Or may be it is already possible to do by using MemoryBased implementation and configuration?

Regards,

sakno commented 8 months ago

MemoryBasedStateMachine abstract class is for building in-memory current view of the data, but Write-Ahead Log is still persistent. It means that the in-memory state can be recovered from the persisted log entries. DiskBasedStateMachine is for building complex DB engines such as SQL or document-oriented databases. The difference is fully explained here.

For security reasons, you can use MemoryBasedStateMachine and encrypt log entries stored on the disk. However, it can be done by Linux infrastructure (partition with enabled fs-level encryption) rather than by code. The same true if you want to place a whole WAL to the memory. Just mount ram-fs on your Linux machine and specify a path to that mount point as a storage for WAL. Everything will be in the memory in that case.

However, I strongly discourage from doing that. Persistence is a major characteristics of Raft. Let's imagine you have 7 nodes. Due to failure, 4 of them are down. Due to lack of persistence, they lost any state. On restart, they have a conflict with other 3 nodes because their WALs not empty. The cluster will not be able to reach the majority without human intrusion.