问题
I use SQLite for a database which I want to persist on an NFS. Any VM in my cluster might shut down at some point in which case docker swarm will spin up a replica on another VM to take over.
Unfortunately the NFS seems not to support file locking so I turned it off (by mounting with "nolock") now I worry if I can be sure that the data will not be corrupted.
Scenarios I could think of are: One of the VMs was simply disconnected from the internet just long enough for another replica to spin up and take over traffic, then it comes back and writes to the DB --> Corrupt data
Would it be save to use NFS like this if file locking is supported? Am I right in assuming it is not when "nolock" is specified?
回答1:
The documentation says about nolock
:
This is useful for accessing a database on a filesystem that does not support locking. Caution: Database corruption might result if two or more processes write to the same database and any one of those processes uses nolock=1.
An alternative would be to use the unix-dotfile
VFS that implements locking by creating a separate file. This works even on lockless NFS, but
- it's slower than 'real' locking;
- it prevents any kind of concurrency (only a single client can access the DB, even for reading); and
- if your client dies in the middle of a transaction, the lock file stays around and must be removed by hand.
来源:https://stackoverflow.com/questions/46159099/sqlite-db-on-nfs-in-cluster-will-i-get-data-corruption