如何确保与sqlite和NFS进行安全的文件同步 [英] How to ensure a safe file sync with sqlite and NFS

查看:251
本文介绍了如何确保与sqlite和NFS进行安全的文件同步的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近将我的应用程序的工作空间文件格式转换为sqlite.为了确保在NFS上的可靠操作,我使用了通用的更新策略,我对存储在本地硬盘上临时位置中的副本进行了所有修改.仅在保存时,我才通过用temp文件复制原始文件来修改原始文件(可能在NFS上).我只打开原始文件以对其保留排他锁,以便其他人尝试打开该文件,并会警告他们其他人正在使用它.

I have recently converted my workspace file format for my application to sqlite. In order to ensure robust operation on NFS I've used a common update policy, I do all modifications to a copy stored in a temp location on the local harddisk. Only when saving do I modify the original file (potentially on NFS) by copying over the original file with the temp file. I only open the orginal file to keep an exclusive lock on it so it someone else tries to open they will be warned that someone else is using it.

问题是这样的:当我将临时文件保存回原始文件时,我必须释放原始文件的锁定,这为其他人进入并获取原始文件提供了一个窗口,尽管这是一个小窗口

The problem is this: When I go to save my temp file back over the original file I must release the lock on the orginal file, this provides a window for someone else to get in and take the original, albeit a small window.

我可以考虑以下几种方法:

I can think of a few ways around this:

(1)就是简单地通过使用sql将temp的内容转储到原始文件中,即在原始文件,vacumm原始文件上删除表,从temp中选择并插入原始文件中.我不喜欢对存储在NFS上的sqlite文件执行sql操作.这使我感到腐败问题.我这样想对吗?

(1) being to simply dump the contents of the temp in to the orginal by using sql, i.e. drop tables on original, vacumm original, select from temp and insert into orginal. I don't like doing sql operations on a sqlite file stored on NFS though. This scares me with corruptions issues. Am I right to think like this?

(2)使用临时文件复制临时文件时,请使用各种额外的文件作为防护,以防止其他文件进入.将文件用作互斥锁最多是有问题的.我也不喜欢在应用程序崩溃时挂起多余文件的想法.

(2) Use various extra files to act as a guard to prevent other from coming in while copying the temp over the original. Using files as a mutex is problematic at best. I also don't like the idea of having extra files hanging around if the application crashes.

我想知道是否有人对此有任何不同的解决方案.再次将临时文件复制到原始文件上,同时确保其他应用程序不会潜入并抓住原始文件吗?

I'm wondering if anyone has any different solutions for this. Again to copy the temp file over the original file while ensuring other application don't sneak in and grab the original file while doing so?

我正在使用python2.5,sqlalchemy 0.6.6和sqlite 3.6.20

I'm using python2.5, sqlalchemy 0.6.6 and sqlite 3.6.20

谢谢, 院长

推荐答案

SQLite NFS问题是由于缓存和锁定损坏所致.如果您的进程是唯一访问NFS上文件的进程,那么您会没事的.

SQLite NFS issues are due to broken caching and locking. If your process is the only one accessing the file on NFS then you'll be ok.

SQLite备份API旨在完全解决您的问题.您可以直接备份到NFS数据库或另一个本地临时文件,然后将其复制.备份API处理所有锁定和并发问题.

The SQLite backup API was designed to solve exactly your problem. You can either backup directly to the NFS database or to another local temp file and then copy that. The backup API deals with all the locking and concurrency issues.

您可以使用APSW来访问备份API或pysqlite的最新版本. (公开:我是APSW的作者.)

You can use APSW to get access to the backup API or the most recent version of pysqlite. (Disclosure: I am the APSW author.)

这篇关于如何确保与sqlite和NFS进行安全的文件同步的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆