可以在NFS文件系統上鎖定sqlite文件嗎?

[英]Locking sqlite file on NFS filesystem possible?


Let's say there are two python scripts that want to write data to the same table which is stored in an SQLite file using the sqlite3 module. The SQLite-file is stored on an NFS filesystem. In the SQLite-FAQ I read:

假設有兩個python腳本想要將數據寫入同一個表,該表使用sqlite3模塊存儲在SQLite文件中。 SQLite文件存儲在NFS文件系統中。在SQLite-FAQ中我讀到:

SQLite uses reader/writer locks to control access to the database. [...] But use caution: this locking mechanism might not work correctly if the database file is kept on an NFS filesystem. This is because fcntl() file locking is broken on many NFS implementations. You should avoid putting SQLite database files on NFS if multiple processes might try to access the file at the same time.

SQLite使用讀取器/寫入器鎖來控制對數據庫的訪問。 [...]但請注意:如果數據庫文件保存在NFS文件系統上,則此鎖定機制可能無法正常工作。這是因為許多NFS實現都會破壞fcntl()文件鎖定。如果多個進程可能同時嘗試訪問該文件,則應避免將SQLite數據庫文件放在NFS上。

Does this mean it is not possible at all or is there some way to ensure that one process waits until the other is done?

這是否意味着它根本不可能或者是否有某種方法可以確保一個進程等到另一個進程完成?

The INSERTs are not complex. Just some:

INSERT並不復雜。一些:

INSERT_STATEMENT = "INSERT INTO some_table (row, col, val) VALUES (?, ?, ?)"
connection.executemany(INSERT_STATEMENT, triples)

And the inserted sets are disjoint.

並且插入的集合是不相交的。

A further question: Does the NFS-Problems occure when two processes try to write to the same table or when they try to write to the same database (which is a file)? Would it be a workaround to let each process create its own table in the same database (file) and write to that?

還有一個問題:當兩個進程嘗試寫入同一個表或嘗試寫入同一個數據庫(即文件)時,是否會出現NFS問題?讓每個進程在同一個數據庫(文件)中創建自己的表並寫入該表是否是一種解決方法?

1 个解决方案

#1


19  

Do not use SQLite with NFS. It is as simple as that. NFS semantics are different than regular filesystems and are looser. You will eventually get corruption. Every now and then someone on the SQLite-users mailing list posts with their "workarounds". They never work although they appear to in the short term.

不要將SQLite與NFS一起使用。它是如此簡單。 NFS語義與常規文件系統不同,並且更寬松。你最終會腐敗。 SQLite用戶郵件列表中的某個人偶爾發布他們的“變通辦法”。他們從不工作,雖然他們似乎在短期內。


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2012/03/28/720273d1897edc9185d6906ada3a51fb.html



 
粤ICP备14056181号  © 2014-2020 ITdaan.com