Making async_logger::flush() synchronous and really flush in-memory data. #3046
Replies: 4 comments 7 replies
-
I see what you mean, but I don't understand the assumption that database or POSIX flushes ( The current workaround would be to access sinks by |
Beta Was this translation helpful? Give feedback.
-
As far as I researched, IMO. |
Beta Was this translation helpful? Give feedback.
-
Since this is an asynchronous interface, Btw #2819 seems like a good starting point. |
Beta Was this translation helpful? Give feedback.
-
As commented in the PR #2819 , I propose to re-implement the async_logger and make its flush() interface synchronous and really flush in-memory message into file.
The current
async_logger::flush()
implementation, in my opinion, is very counter-intuitive and broken. It is a long established conventions in the C/C++/POSIX world and database world that a "flush" operation should flush its in-memory cache data into disk , (A "sync", instead, persist the OS file cache into disk). However, the current implemention of flush() just post a flush message into the backend queue and return immediately, without knowing when would the in-memory message flushed to file or whether or not it would be flushed to file (e.g., it might be overwritten). This is just not reasonable, because, if a flush operation is just a undeterministic flush, why would the user call the flush() function explicitly? The user could just let the messages in-queue and flushed by the backend thread periodically or when the queue is full. So, if a user call the flush() explicitly, it is mostly that he/she want to make sure that these messages are onto file after flush.The current implementation is so counter-intuitive and it is the reason why there are so many issues/discussions about it: #2982 #1696 #2819
I also ran into such a bug while using
async_logger::flush()
So, I would propose to change the
async_logger::flush()
implementation and make it synchronouse.To make this easier, we should reimplement the async_logger so that it has its own message queue that could be pulled continously by worker threads. This make it easier to sink all the messages belonging to a async_logger.
I would like to propose a patch for this and would like some feedback.
Beta Was this translation helpful? Give feedback.
All reactions