data written to file missed by reader - Linux

This is a discussion on data written to file missed by reader - Linux ; Hello All, We currently run processes that communicate by writing an encoded message to a flat file while other processes are reading the file. A message that was written to the file by one process (fsync is not called after ...

+ Reply to Thread
Results 1 to 5 of 5

Thread: data written to file missed by reader

  1. data written to file missed by reader

    Hello All,

    We currently run processes that communicate by writing an encoded
    message to a flat file while other processes are reading the file. A
    message that was written to the file by one process (fsync is not
    called after each write) was missed by the reader. A second message
    was written 1 ms later. When I say "missed", I mean that the process
    read the second message and continued processing. Another process
    reading messages from the same file came through ~200 ms later and read
    the missed message and then the second message in the expected
    sequence. Is there some kind of synchronization issue after the data
    has been written that could have caused the reading process to miss the
    data? Perhaps during the flush to disk? Is there any inter-process
    file access management performed in the virtual layer?

    We are running on linux kernel 2.4.21-32.0.1 using multiple processors
    (smp) and SCSI disks in a RAID 1 configuration.

    Thanks,
    --Sean


  2. Re: data written to file missed by reader


    seanmkirkpatrick@gmail.com wrote:

    > We currently run processes that communicate by writing an encoded
    > message to a flat file while other processes are reading the file. A
    > message that was written to the file by one process (fsync is not
    > called after each write) was missed by the reader. A second message
    > was written 1 ms later. When I say "missed", I mean that the process
    > read the second message and continued processing. Another process
    > reading messages from the same file came through ~200 ms later and read
    > the missed message and then the second message in the expected
    > sequence. Is there some kind of synchronization issue after the data
    > has been written that could have caused the reading process to miss the
    > data? Perhaps during the flush to disk? Is there any inter-process
    > file access management performed in the virtual layer?


    How do readers detect that there is new data in the file? Do they check
    for a change in the modification time and then re-read the file? Or is
    new data appended to the file and they periodically try to read past
    what was previously the end of the file?

    My bet is that there is a flaw in your scheme for detecting new
    messages. But it's hard to say without knowing in much more detail how
    your scheme actually works.

    DS


  3. Re: data written to file missed by reader

    seanmkirkpatrick@gmail.com wrote:
    > Hello All,
    >
    > We currently run processes that communicate by writing an encoded
    > message to a flat file while other processes are reading the file. A
    > message that was written to the file by one process (fsync is not
    > called after each write) was missed by the reader.


    In other words, you're having trouble duplicating the reliability of
    "tail -f".



    You have a bug in the tail-following logic.

    Might you be skipping the message with an inappropriate seek operation?

    Also, be sure that you don't have multiple threads or processes sharing
    the same file descriptor. Every reader must use its own, separately
    opened fd.


  4. Re: data written to file missed by reader


    Kaz Kylheku wrote:

    > Also, be sure that you don't have multiple threads or processes sharing
    > the same file descriptor. Every reader must use its own, separately
    > opened fd.


    That's not true if one of two things is the case:

    1) The file descriptor is protected by a mutex that is acquired before
    a seek and released after the read/write, or

    2) You only use operations with built-in seeks like pread/pwrite.

    DS


  5. Re: data written to file missed by reader

    David Schwartz wrote:
    > Kaz Kylheku wrote:
    >
    > > Also, be sure that you don't have multiple threads or processes sharing
    > > the same file descriptor. Every reader must use its own, separately
    > > opened fd.

    >
    > That's not true if one of two things is the case:
    >
    > 1) The file descriptor is protected by a mutex that is acquired before
    > a seek and released after the read/write, or
    >
    > 2) You only use operations with built-in seeks like pread/pwrite.


    That's equivalent to making your own file descriptor abstraction, to
    which the original comments then apply.


+ Reply to Thread