Commit ffdc8a9a authored by Zeyi (Rice) Fan's avatar Zeyi (Rice) Fan Committed by Facebook Github Bot

move `onIoError` to `AsyncFileWriter`

Summary: This diff moves `onIoError` into `AsyncFileWriter` as it is specifically related to writing to file.

Reviewed By: yfeldblum

Differential Revision: D15324855

fbshipit-source-id: 3929a53aee7febd9185b71dfdb894990dee73413
parent 0bf12e84
...@@ -34,7 +34,7 @@ bool AsyncFileWriter::ttyOutput() const { ...@@ -34,7 +34,7 @@ bool AsyncFileWriter::ttyOutput() const {
return isatty(file_.fd()); return isatty(file_.fd());
} }
void AsyncFileWriter::performIO( void AsyncFileWriter::writeToFile(
std::vector<std::string>* ioQueue, std::vector<std::string>* ioQueue,
size_t numDiscarded) { size_t numDiscarded) {
// kNumIovecs controls the maximum number of strings we write at once in a // kNumIovecs controls the maximum number of strings we write at once in a
...@@ -68,14 +68,20 @@ void AsyncFileWriter::performIO( ...@@ -68,14 +68,20 @@ void AsyncFileWriter::performIO(
} }
} }
void AsyncFileWriter::onIoError(const std::exception& ex) { void AsyncFileWriter::performIO(
LoggerDB::internalWarning( std::vector<std::string>* ioQueue,
__FILE__, size_t numDiscarded) {
__LINE__, try {
"error writing to log file ", writeToFile(ioQueue, numDiscarded);
file_.fd(), } catch (const std::exception& ex) {
" in AsyncFileWriter: ", LoggerDB::internalWarning(
folly::exceptionStr(ex)); __FILE__,
__LINE__,
"error writing to log file ",
file_.fd(),
" in AsyncFileWriter: ",
folly::exceptionStr(ex));
}
} }
std::string AsyncFileWriter::getNumDiscardedMsg(size_t numDiscarded) { std::string AsyncFileWriter::getNumDiscardedMsg(size_t numDiscarded) {
......
...@@ -54,10 +54,11 @@ class AsyncFileWriter : public AsyncLogWriter { ...@@ -54,10 +54,11 @@ class AsyncFileWriter : public AsyncLogWriter {
} }
private: private:
void writeToFile(std::vector<std::string>* ioQueue, size_t numDiscarded);
void performIO(std::vector<std::string>* ioQueue, size_t numDiscarded) void performIO(std::vector<std::string>* ioQueue, size_t numDiscarded)
override; override;
void onIoError(const std::exception& ex) override;
std::string getNumDiscardedMsg(size_t numDiscarded); std::string getNumDiscardedMsg(size_t numDiscarded);
folly::File file_; folly::File file_;
......
...@@ -67,11 +67,7 @@ void AsyncLogWriter::cleanup() { ...@@ -67,11 +67,7 @@ void AsyncLogWriter::cleanup() {
// If there are still any pending messages, flush them now. // If there are still any pending messages, flush them now.
if (!ioQueue->empty()) { if (!ioQueue->empty()) {
try { performIO(ioQueue, numDiscarded);
performIO(ioQueue, numDiscarded);
} catch (const std::exception& ex) {
onIoError(ex);
}
} }
} }
...@@ -162,11 +158,7 @@ void AsyncLogWriter::ioThread() { ...@@ -162,11 +158,7 @@ void AsyncLogWriter::ioThread() {
ioCV_.notify_all(); ioCV_.notify_all();
// Write the log messages now that we have released the lock // Write the log messages now that we have released the lock
try { performIO(ioQueue, numDiscarded);
performIO(ioQueue, numDiscarded);
} catch (const std::exception& ex) {
onIoError(ex);
}
// clear() empties the vector, but the allocated capacity remains so we can // clear() empties the vector, but the allocated capacity remains so we can
// just reuse it without having to re-allocate in most cases. // just reuse it without having to re-allocate in most cases.
......
...@@ -136,8 +136,6 @@ class AsyncLogWriter : public LogWriter { ...@@ -136,8 +136,6 @@ class AsyncLogWriter : public LogWriter {
std::vector<std::string>* logs, std::vector<std::string>* logs,
size_t numDiscarded) = 0; size_t numDiscarded) = 0;
virtual void onIoError(const std::exception& ex) = 0;
void ioThread(); void ioThread();
bool preFork(); bool preFork();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment