When the data is actually written to the file?

Issue #44 resolved
KudoWu created an issue

Hi Tobias,

First of all, I don't think it's a problem.I found from the write example that queue data is only written to a file when the file is closed.

I want to try to understand the specific flow by reading source code.I found turn on two threads: uncompressedFileWriteThread and compressedFileWriteThread.

  • Execute readWriteQueue2UncompressedFile in uncompressedFileWriteThread.
  • Read m_readWriteQueue and write m_uncompressedFile in readWriteQueue2UncompressedFile.
  • Execute uncompressedFile2CompressedFile in compressedFileWriteThread.
  • Read m_uncompressedFile and write m_compressedFile.

So that's what I'm strange.It stands to reason that don't wait for file close to close before writing to a file.Maybe I still have something to overlook, I'll experiment further.And hope to get your answer!

thanks a lot, KudoWu

Comments (4)

  1. KudoWu reporter

    Hi Tobias,

    I am very happy to tell you that I have solved this doubt.

    This afternoon I took a good look at the source code again.I found line 39 in UncompressedFile.cpp

    ‌ /* wait until there is sufficient data */

    ‌ tellpChanged.wait(lock, [&] {

    ‌ return

    ‌ m_abort ||

    ‌ (n + m_tellg <= m_tellp) ||

    ‌ (n + m_tellg > m_fileSize);

    ‌ });

    Here wait until the buff of the stream is full before filling in the file.I would like to ask if n is the header of the file?

    In addition, I would like to ask if the static information of the file needs to be written by myself? Can you use time as an example?

    thanks a lot, KudoWu

  2. Tobias Lorenz repo owner

    Hi KudoWu,

    yes, Vector BLF compresses and writes the data in chunks, so called LogContainers. The size of a log container is 0x20000, but it can be changed with the method File::setDefaultLogContainerSize. But that’s the reason, why there first need to be some data collected, before it actually gets written to disk. You can also switch off compression completely and then the file should be written immediately. For this, set the member variable “File::compressionLevel = 0” before opening the file.

    In the code snippet above, “n” is just the number of bytes that shall be read. If this is not available, the thread waits.

    Yes, static information can be writen as well. This is also accessible by member variable File::fileStatistics. Some information is automatically set when the file is closed, such as restorePointsOffset, uncompressedFileSize and objectCount. Other information can be set manually, such as measurementStartTime, lastObjectTime.

    I’ll keep this topic open for while in case you have further questions. ;-)

    Bye

    Tobias

  3. Log in to comment