Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.007 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'cache': 0.05; 'rename': 0.07; 'subject:file': 0.07; 'subject:How': 0.09; 'flush': 0.09; 'file,': 0.15; 'atomically': 0.16; 'fancy': 0.16; 'maildir': 0.16; 'posix': 0.16; 'processes.': 0.16; 'renames': 0.16; 'side.': 0.16; 'stuff.': 0.16; 'documented': 0.17; 'platforms': 0.18; 'file.': 0.20; 'exists.': 0.22; 'help.': 0.22; 'to:2**1': 0.23; 'header:In- Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'disk': 0.27; 'operations,': 0.27; "doesn't": 0.28; 'run': 0.28; 'locks': 0.29; 'e.g.': 0.30; 'compatible': 0.30; 'file': 0.32; 'not.': 0.32; 'true.': 0.33; 'to:addr:python-list': 0.33; 'another': 0.33; 'too.': 0.35; "won't": 0.35; 'there': 0.35; 'correctly': 0.37; 'two': 0.37; 'data': 0.37; 'subject:: ': 0.38; 'sure': 0.38; 'delete': 0.38; 'to:addr:python.org': 0.39; 'received:192': 0.39; 'received:192.168': 0.40; 'matter': 0.61; 'time,': 0.62; 'provide': 0.62; 'talking': 0.66; 'race': 0.71; 'received:204': 0.72; 'flushing': 0.84; 'subject:status': 0.84 Date: Thu, 12 Jul 2012 14:30:41 +0200 From: Laszlo Nagy User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:10.0.2) Gecko/20120216 Thunderbird/10.0.2 MIME-Version: 1.0 To: Christian Heimes , python-list@python.org Subject: Re: How to safely maintain a status file References: <4FF9F454.40207@shopzeus.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 19 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1342096256 news.xs4all.nl 6923 [2001:888:2000:d::a6]:60753 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:25210 > You are contradicting yourself. Either the OS is providing a fully > atomic rename or it doesn't. All POSIX compatible OS provide an atomic > rename functionality that renames the file atomically or fails without > loosing the target side. On POSIX OS it doesn't matter if the target exists. This is not a contradiction. Although the rename operation is atomic, the whole "change status" process is not. It is because there are two operations: #1 delete old status file and #2. rename the new status file. And because there are two operations, there is still a race condition. I see no contradiction here. > > You don't need locks or any other fancy stuff. You just need to make > sure that you flush the data and metadata correctly to the disk and > force a re-write of the directory inode, too. It's a standard pattern on > POSIX platforms and well documented in e.g. the maildir RFC. It is not entirely true. We are talking about two processes. One is reading a file, another one is writting it. They can run at the same time, so flushing disk cache forcedly won't help.