--- src/log/logd/lgs_cache.cc | 31 +++++++++++++++++-------------- src/log/logd/lgs_cache.h | 2 +- 2 files changed, 18 insertions(+), 15 deletions(-)
diff --git a/src/log/logd/lgs_cache.cc b/src/log/logd/lgs_cache.cc index 27e33702d..f30a23899 100644 --- a/src/log/logd/lgs_cache.cc +++ b/src/log/logd/lgs_cache.cc @@ -180,16 +180,21 @@ bool Cache::Data::is_overdue() const { return (current - queue_at > max_resilience); } -bool Cache::Data::is_valid(std::string* reason) const { +bool Cache::Data::is_valid() const { + std::string reason{"Ok"}; + bool rc = true; if (is_stream_open() == false) { - *reason = "the log stream has been closed"; - return false; + reason = "the log stream has been closed"; + rc = false; + } else if (is_overdue() == true) { + reason = "the record is overdue (stream: " + param_->stream()->name + ")"; + rc = false; } - if (is_overdue() == true) { - *reason = "the record is overdue (stream: " + param_->stream()->name + ")"; - return false; + if ((rc == false) && (is_client_alive() == false)) { + LOG_NO("Drop the invalid log record, reason: %s", reason.c_str()); + LOG_NO("The record info: %s", log_record_); } - return true; + return rc; } void Cache::Data::CloneData(CkptPushAsync* output) const { @@ -413,13 +418,7 @@ void Cache::PopOverdueData() { if (Empty() == true || is_active() == false) return; std::string reason{"Ok"}; auto data = Front(); - if (data->is_valid(&reason) == false) { - // Either the targeting stream has been closed or the owner is dead. - // syslog the detailed info about dropped log record if latter case. - if (data->is_client_alive() == false) { - LOG_NO("Drop the invalid log record, reason: %s", reason.c_str()); - LOG_NO("The record info: %s", data->record()); - } + if (data->is_valid() == false) { Pop(false); } } @@ -427,6 +426,10 @@ void Cache::PopOverdueData() { void Cache::FlushFrontElement() { if (Empty() || !is_active() || !is_iothread_ready()) return; auto data = Front(); + if (data->is_valid() == false) { + Pop(false); + return; + } int rc = data->Write(); // Write still gets timeout, do nothing. if ((rc == -1) || (rc == -2)) return; diff --git a/src/log/logd/lgs_cache.h b/src/log/logd/lgs_cache.h index a5d6181fb..d044bc240 100644 --- a/src/log/logd/lgs_cache.h +++ b/src/log/logd/lgs_cache.h @@ -167,7 +167,7 @@ class Cache { // Check if the data is valid or not. The data is not valid if either // the targeting stream is closed or the the time of its staying in the // queue is reaching the maximum. - bool is_valid(std::string* reason) const; + bool is_valid() const; // Dump the values of data's attributes. void Dump() const; // Clone values of my attributes to `CkptPushAsync`; and CkptPushAsync -- 2.17.1 _______________________________________________ Opensaf-devel mailing list Opensaf-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/opensaf-devel