SQLite DB on NFS in cluster. Will I get data corruption?

南笙酒味 提交于 2020-02-05 09:02:21

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!