Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Strange QFileInfo behavior when using a SAN

Strange QFileInfo behavior when using a SAN

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 591 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mrlukas
    wrote on last edited by
    #1

    Hi,

    I have come across a strange behavior in Windows when writing to a drive that is mapped to a storage network (SAN).
    After writing (appending) & closing a file, the file size when checking via QFileInfo is sometimes too small.
    This can even happen 3 hours after closing the file. I would hope that any caching on the SAN side is completed by then. After all, we are talking about files that rarely exceed 1MB.
    At one point a 700KB file was successfully copied from the SAN via Windows Explorer, yet QFileInfo was still under the impression that the file on the SAN was only 200KB large.

    This is how the file is written in the application:

    • open a QFile (use QFile::Append if file already exists)
    • write data
    • flush
    • close file

    This is how the file size is retrieved:

    return QFileInfo(file_name).size();
    

    The NAS in question is a "Hitachi Virtual Storage Platform G800".
    Is there something I can do in my code to address this issue? For instance, is it more reliable to determine the size of a file by opening a new QFile + calling size() instead of using QFileInfo? From what I can tell (see this thread for instance) the QFileInfo cache should not be an issue.
    The problem is very difficult to reproduce. Hundreds of files are written every day. Files may receive additional data 2-3x per day. Only very few files show these symptoms.

    K 1 Reply Last reply
    0
    • M mrlukas

      Hi,

      I have come across a strange behavior in Windows when writing to a drive that is mapped to a storage network (SAN).
      After writing (appending) & closing a file, the file size when checking via QFileInfo is sometimes too small.
      This can even happen 3 hours after closing the file. I would hope that any caching on the SAN side is completed by then. After all, we are talking about files that rarely exceed 1MB.
      At one point a 700KB file was successfully copied from the SAN via Windows Explorer, yet QFileInfo was still under the impression that the file on the SAN was only 200KB large.

      This is how the file is written in the application:

      • open a QFile (use QFile::Append if file already exists)
      • write data
      • flush
      • close file

      This is how the file size is retrieved:

      return QFileInfo(file_name).size();
      

      The NAS in question is a "Hitachi Virtual Storage Platform G800".
      Is there something I can do in my code to address this issue? For instance, is it more reliable to determine the size of a file by opening a new QFile + calling size() instead of using QFileInfo? From what I can tell (see this thread for instance) the QFileInfo cache should not be an issue.
      The problem is very difficult to reproduce. Hundreds of files are written every day. Files may receive additional data 2-3x per day. Only very few files show these symptoms.

      K Offline
      K Offline
      koahnig
      wrote on last edited by
      #2

      @mrlukas

      Hi and welcome to devnet forum

      When you are using already QFile it has a size member as weel.
      Are both values consistent?

      Vote the answer(s) that helped you to solve your issue(s)

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mrlukas
        wrote on last edited by
        #3

        Hi koahnig,

        Thank you for the response.

        At the moment a QFile is only opened AFTER the file size is read. The size influences which operation needs to be triggered.

        Is QFile::size more likely to return the "true" file size - since the target file is actually opened?
        Or might it be necessary to do a QFile::readAll to determine the current size of the data?

        I am planning to add log statements to the code - then all three methods of determining the file size can be compared.
        Let's hope that at least one method returns the correct value :)

        JonBJ 1 Reply Last reply
        0
        • M mrlukas

          Hi koahnig,

          Thank you for the response.

          At the moment a QFile is only opened AFTER the file size is read. The size influences which operation needs to be triggered.

          Is QFile::size more likely to return the "true" file size - since the target file is actually opened?
          Or might it be necessary to do a QFile::readAll to determine the current size of the data?

          I am planning to add log statements to the code - then all three methods of determining the file size can be compared.
          Let's hope that at least one method returns the correct value :)

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #4

          @mrlukas
          One would expect this might be down to some kind of caching somewhere.

          • Make 100% sure you have closed the file (debug statements) before you try to read its size. Make sure you do not have any other handle onto the file open elsewhere in your code.

          • For testing, put in some kind of delay of a few seconds after closing before trying to read the size, just in case.

          • How does the size reported from Qt compare, at the same instant in time, with that reported by Windows (e.g. File Explorer)?

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved