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 {
return isatty(file_.fd());
}
void AsyncFileWriter::performIO(
void AsyncFileWriter::writeToFile(
std::vector<std::string>* ioQueue,
size_t numDiscarded) {
// kNumIovecs controls the maximum number of strings we write at once in a
......@@ -68,14 +68,20 @@ void AsyncFileWriter::performIO(
}
}
void AsyncFileWriter::onIoError(const std::exception& ex) {
LoggerDB::internalWarning(
__FILE__,
__LINE__,
"error writing to log file ",
file_.fd(),
" in AsyncFileWriter: ",
folly::exceptionStr(ex));
void AsyncFileWriter::performIO(
std::vector<std::string>* ioQueue,
size_t numDiscarded) {
try {
writeToFile(ioQueue, numDiscarded);
} catch (const std::exception& ex) {
LoggerDB::internalWarning(
__FILE__,
__LINE__,
"error writing to log file ",
file_.fd(),
" in AsyncFileWriter: ",
folly::exceptionStr(ex));
}
}
std::string AsyncFileWriter::getNumDiscardedMsg(size_t numDiscarded) {
......
......@@ -54,10 +54,11 @@ class AsyncFileWriter : public AsyncLogWriter {
}
private:
void writeToFile(std::vector<std::string>* ioQueue, size_t numDiscarded);
void performIO(std::vector<std::string>* ioQueue, size_t numDiscarded)
override;
void onIoError(const std::exception& ex) override;
std::string getNumDiscardedMsg(size_t numDiscarded);
folly::File file_;
......
......@@ -67,11 +67,7 @@ void AsyncLogWriter::cleanup() {
// If there are still any pending messages, flush them now.
if (!ioQueue->empty()) {
try {
performIO(ioQueue, numDiscarded);
} catch (const std::exception& ex) {
onIoError(ex);
}
performIO(ioQueue, numDiscarded);
}
}
......@@ -162,11 +158,7 @@ void AsyncLogWriter::ioThread() {
ioCV_.notify_all();
// Write the log messages now that we have released the lock
try {
performIO(ioQueue, numDiscarded);
} catch (const std::exception& ex) {
onIoError(ex);
}
performIO(ioQueue, numDiscarded);
// clear() empties the vector, but the allocated capacity remains so we can
// just reuse it without having to re-allocate in most cases.
......
......@@ -136,8 +136,6 @@ class AsyncLogWriter : public LogWriter {
std::vector<std::string>* logs,
size_t numDiscarded) = 0;
virtual void onIoError(const std::exception& ex) = 0;
void ioThread();
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