History:
Multiple processes are appending to and updating multiple files. "\n" line/record delimiter. The hardest hit files were being truncated, sometimes in the middle of a line. Had been using flock() per numerous examples, but didn't work. I suspect something to do with locks in user space.
Partial solutions:
Switched to using DBI::CSV and I wrote a daemon with example (verbatim) from IO::Select using IO::Socket with a simple protocol to arbitrate file access. Sockets are being read and printed using "\n" to complete:
Process requested a socket ==> Daemon accepted socket request
Process asked for access ==> Daemon accepted request - via socket
Daemon granted access ==> Process accepted access - via socket
Process accessed file
Process gave up access ==> Daemon accepted - via socket
Process and Daemon moved on
Results:
Immediate results were positive. It took a while before I started to find "signs" of corruption which couldn't be verified - some data seemed inconsistent, though there could be a perfectly reasonable explanation for it. Then I found some log files (should be simple appends) that had portions of lines mushed together, and some lines that had embedded "\n" where the processes couldn't be generating it.
Question:
Is there some way to ensure that the DBI::CSV actually locks files for update, or some way to make sure any write buffers it uses are being flushed with every write/update?
I can't think of anything else that may be allowing processes to clobber each other's file updates.
Thanks.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.