Lawrence Weeks wrote:

On Oct 23, 2004, at 11:14 AM, Stephen Warren wrote:
So, this means we can't have each user have CONFIRM_APPEND set to the same file. This is the only way to guarantee avoiding multiple TMDA processes writing to the file at the same time.

Unless TMDA is rather poorly written, I would not expect any issues with multiple TMDA processes appending to the same files simultaneously. I presume that it uses standard Unix streaming buffered IO, and writes in append mode, for the plain text files. If so, this should work fine.

Interesting. I just tracked down the code in TMDA and simulated it by manually running two Python processes and interleaving the IO. It works fine!

To the original poster: This means everyone's CONFIRM_APPEND can point at the exact same file... Sorry!

Looking at the manual pages for the open(2) system call, it appears that the kernel ensures that each write, even from different processes at the same time, is actually atomic and will always append to the file. I guess you learn something new everyday.

There are a couple of minor caveats though - it doesn't work if the file you're appending to is mounted over NFS:

O_APPEND
    The  file  is opened in append mode. Before each write, the file
    pointer is positioned at the end of the file, as if with  lseek.
    O_APPEND may lead to corrupted files on NFS file systems if more
    than one process appends data  to  a  file  at  once.   This  is
    because  NFS does not support appending to a file, so the client
    kernel has to simulate it, which can't be done  without  a  race
    condition.

Also, the TMDA code first opens the file, then checks whether the line to be appended already exists, then re-opens the file for append and does the append. If two processes attempt to append the same data, at the same time, that doesn't already exist in the file, it's possible that it will be appended twice. This isn't really a problem, since it'll work just fine, but simply waste a little space. The same thing would happen if you used multiple CONFIRM_APPEND files anyway.

--
Stephen Warren, Software Engineer, NVIDIA, Fort Collins, CO
[EMAIL PROTECTED]     http://www.wwwdotorg.org/pgp.html

Attachment: signature.asc
Description: OpenPGP digital signature

_____________________________________________
tmda-users mailing list ([EMAIL PROTECTED])
http://tmda.net/lists/listinfo/tmda-users

Reply via email to