Strange QFileInfo behavior when using a SAN
-
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. -
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. -
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 :) -
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 :)@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)?
-