How to quickly file::close and then reopen the new file?

Issue #215 resolved
KudoWu created an issue

Hello Tobias,

I ran into a problem with file::close in actual development.

I want to store messages generated on different dates in the corresponding file, but after I call close, the file still needs to wait for the end of other threads, such as m_compressedFileThread. Then when I reopen with a new filename, an error occurs(corrupt stack?).

After my testing, I've reopened it, but it still saves the previous static information.I've also tried creating two files, alternating open close, but this doesn't seem feasible.

As a last resort, I would like to consult you, I will try other methods as well.Because the previous program does not seem to produce corresponding problems.

Anyway, thank you very much!

Bye

KudoWu

Comments (6)

  1. Tobias Lorenz repo owner

    Hello KudoWu,

    the file::close operation indeed takes a while to finalize the file, so to write the last objects, finalize and compress the log container(s) and to write file statistics. Afterwards you should be able to open another file. I fixed a couple of issues in this regard and also provided test cases, so I hope this works fine now. The safest way is of course to delete the File object and create a new one.

    What’s not tested well is to append objects to an existing file.

    Do you have a test sequence by hand that reproduces the issue? This makes it easier for me to analyze and fix the issue. Maybe I can derive this code also as a permanent test case also.

    Bye

    Tobias

  2. KudoWu reporter

    Hello Tobias,

    Sorry to reply to you now. Yes, the safest way is to delete the file object and create a new one, but this will cause some messages to be lost, which is fatal for me.

    And sorry, I don't seem to have found the test case you said.

    If you test the sequence manually, I don't think it's necessary. Just close a file, reopen it after a while, and then write the sequence, and the problem will occur, I wonder if you can understand what I mean?

    We are circumventing this problem by depositing only one file at a time for now, but it is not very friendly for viewing logs.

    Here's a simple process:

    1. create file1, file2
    2. open file1, start storage frame
    3. file1 already stored for 1h, close file1, open file2
    4. file2 already stored for 1h, close file2, open file2 with a new file name
    5. file1 stack error occurs

    Bye

    KudoWu

  3. KudoWu reporter

    Hello Tobias,

    Recently I tried again according to your method and it works, thank you!

    Bye

    KudoWu

  4. Log in to comment