[devel] [PATCH 0/1] Review Request for log: fix to remove the cfg file when log file rotation [#3045]

2019-05-30 Thread Canh Van Truong
Summary: log: fix to remove the cfg file when log file rotation [#3045]
Review request for Ticket(s): 3045
Peer Reviewer(s): Lennart, Vu 
Pull request to: *** LIST THE PERSON WITH PUSH ACCESS HERE ***
Affected branch(es): develop
Development branch: ticket-3045
Base revision: b0dd5b39172e01d644a84804abda2b1ded6e81cc
Personal repository: git://git.code.sf.net/u/canht32/review


Impacted area   Impact y/n

 Docsn
 Build systemn
 RPM/packaging   n
 Configuration files n
 Startup scripts n
 SAF servicesy
 OpenSAF servicesn
 Core libraries  n
 Samples n
 Tests   n
 Other   n


Comments (indicate scope for each "y" above):
-
*** EXPLAIN/COMMENT THE PATCH SERIES HERE ***

revision 2a9afe2cc3bc03fdb2b358fb795f16f2b8088a27
Author: Canh Van Truong 
Date:   Thu, 30 May 2019 11:18:18 +0700

log: fix to remove the cfg file when log file rotation [#3045]

If the date(include year, month and day) in oldest cfg file name and the
date of created oldest log file is different, logd cannot find out the
oldest cfg file. The oldest cfg file is never removed when log file rotation.
So number of cfg file is huge after time while the log file has already been
rotated.

Update to remove the cfg in this case.
Also limit the number of cfg files should be removed if there are still huge
cfg files in disk to avoid hanging main thread



Complete diffstat:
--
 src/log/logd/lgs_filehdl.cc |  8 ++--
 src/log/logd/lgs_stream.cc  | 96 -
 2 files changed, 47 insertions(+), 57 deletions(-)


Testing Commands:
-
*** LIST THE COMMAND LINE TOOLS/STEPS TO TEST YOUR CHANGES ***


Testing, Expected Results:
--
*** PASTE COMMAND OUTPUTS / TEST RESULTS ***


Conditions of Submission:
-
*** HOW MANY DAYS BEFORE PUSHING, CONSENSUS ETC ***


Arch  Built StartedLinux distro
---
mipsn  n
mips64  n  n
x86 n  n
x86_64  n  n
powerpc n  n
powerpc64   n  n


Reviewer Checklist:
---
[Submitters: make sure that your review doesn't trigger any checkmarks!]


Your checkin has not passed review because (see checked entries):

___ Your RR template is generally incomplete; it has too many blank entries
that need proper data filled in.

___ You have failed to nominate the proper persons for review and push.

___ Your patches do not have proper short+long header

___ You have grammar/spelling in your header that is unacceptable.

___ You have exceeded a sensible line length in your headers/comments/text.

___ You have failed to put in a proper Trac Ticket # into your commits.

___ You have incorrectly put/left internal data in your comments/files
(i.e. internal bug tracking tool IDs, product names etc)

___ You have not given any evidence of testing beyond basic build tests.
Demonstrate some level of runtime or other sanity testing.

___ You have ^M present in some of your files. These have to be removed.

___ You have needlessly changed whitespace or added whitespace crimes
like trailing spaces, or spaces before tabs.

___ You have mixed real technical changes with whitespace and other
cosmetic code cleanup changes. These have to be separate commits.

___ You need to refactor your submission into logical chunks; there is
too much content into a single commit.

___ You have extraneous garbage in your review (merge commits etc)

___ You have giant attachments which should never have been sent;
Instead you should place your content in a public tree to be pulled.

___ You have too many commits attached to an e-mail; resend as threaded
commits, or place in a public tree for a pull.

___ You have resent this content multiple times without a clear indication
of what has changed between each re-send.

___ You have failed to adequately and individually address all of the
comments and change requests that were proposed in the initial review.

___ You have a misconfigured ~/.gitconfig file (i.e. user.name, user.email etc)

___ Your computer have a badly configured date and time; confusing the
the threaded patch review.

___ Your changes affect IPC mechanism, and you don't present any results
for in-service upgradability test.

___ Your changes affect user manual and documentation, your patch series
do not contain the patch that updates the Doxygen manual.



___
Opensaf-devel mailing list
Opensaf-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/opensaf-devel


[devel] [PATCH 1/1] log: fix to remove the cfg file when log file rotation [#3045]

2019-05-30 Thread Canh Van Truong
If the date(include year, month and day) in oldest cfg file name and the
date of created oldest log file is different, logd cannot find out the
oldest cfg file. The oldest cfg file is never removed when log file rotation.
So number of cfg file is huge after time while the log file has already been
rotated.

Update to remove the cfg in this case.
Also limit the number of cfg files should be removed if there are still huge
cfg files in disk to avoid hanging main thread
---
 src/log/logd/lgs_filehdl.cc |  8 ++--
 src/log/logd/lgs_stream.cc  | 96 -
 2 files changed, 47 insertions(+), 57 deletions(-)

diff --git a/src/log/logd/lgs_filehdl.cc b/src/log/logd/lgs_filehdl.cc
index be2b95e1f..f31e45883 100644
--- a/src/log/logd/lgs_filehdl.cc
+++ b/src/log/logd/lgs_filehdl.cc
@@ -794,10 +794,10 @@ int get_number_of_cfg_files_hdl(void *indata, void 
*outdata,
   }
 }
 
-if ((old_ind != -1) && (cfg_old_date == log_old_date) &&
-(cfg_old_time <= log_old_time)) {
-  TRACE_1(" (cfg_old_date:%d == log_old_date:%d) &&"
-  " (cfg_old_time:%d <= log_old_time:%d )",
+if ((old_ind != -1) && (((cfg_old_date == log_old_date) &&
+(cfg_old_time <= log_old_time)) || (cfg_old_date < log_old_date))) {
+  TRACE_1(" (cfg_old_date:%d - log_old_date:%d) -"
+  " (cfg_old_time:%d - log_old_time:%d )",
   cfg_old_date, log_old_date, cfg_old_time, log_old_time);
   TRACE_1("oldest: %s", cfg_namelist[old_ind]->d_name);
   n = snprintf(oldest_file, max_outsize, "%s/%s", path.c_str(),
diff --git a/src/log/logd/lgs_stream.cc b/src/log/logd/lgs_stream.cc
index d31ae170b..cb9a935e7 100644
--- a/src/log/logd/lgs_stream.cc
+++ b/src/log/logd/lgs_stream.cc
@@ -270,69 +270,59 @@ static int delete_config_file(log_stream_t *stream) {
 
 /**
  * Remove oldest log file until there are 'maxFilesRotated' - 1 files left
+ * The oldest cfg files are also removed
  *
  * @param stream
- * @return -1 on error
+ * @return true/false
  */
-static int rotate_if_needed(log_stream_t *stream) {
+static bool rotate_if_needed(log_stream_t *stream) {
   char oldest_log_file[PATH_MAX];
   char oldest_cfg_file[PATH_MAX];
-  int rc = 0;
-  int log_file_cnt, cfg_file_cnt;
-  bool oldest_cfg = false;
+  const int max_files_rotated = static_cast(stream->maxFilesRotated);
 
   TRACE_ENTER();
 
-  /* Rotate out log files from previous lifes */
-  if ((log_file_cnt = get_number_of_log_files_h(stream, oldest_log_file)) ==
-  -1) {
-rc = -1;
-goto done;
-  }
-
-  /* Rotate out cfg files from previous lifes */
-  if (!((cfg_file_cnt = get_number_of_cfg_files_h(stream, oldest_cfg_file)) ==
--1)) {
-oldest_cfg = true;
-  }
-
-  TRACE("delete oldest_cfg_file: %s oldest_log_file %s", oldest_cfg_file,
-oldest_log_file);
-
-  /*
-  ** Remove until we have one less than allowed, we are just about to
-  ** create a new one again.
-  */
-  while (log_file_cnt >= static_cast(stream->maxFilesRotated)) {
-if ((rc = file_unlink_h(oldest_log_file)) == -1) {
-  LOG_NO("Could not log delete: %s - %s", oldest_log_file, 
strerror(errno));
-  goto done;
+  // Get number of log files and the oldest log file
+  int log_file_cnt = get_number_of_log_files_h(stream, oldest_log_file);
+  while (log_file_cnt >= max_files_rotated) {
+TRACE("Delete oldest_log_file %s", oldest_log_file);
+if (file_unlink_h(oldest_log_file) == -1) {
+  LOG_NO("Delete log file fail: %s - %s", oldest_log_file, 
strerror(errno));
+  return false;
 }
-
-if (oldest_cfg == true) {
-  oldest_cfg = false;
-  if ((rc = file_unlink_h(oldest_cfg_file)) == -1) {
-LOG_NO("Could not cfg  delete: %s - %s", oldest_cfg_file,
-   strerror(errno));
-goto done;
-  }
-}
-
-if ((log_file_cnt = get_number_of_log_files_h(stream, oldest_log_file)) ==
--1) {
-  rc = -1;
-  goto done;
+log_file_cnt = get_number_of_log_files_h(stream, oldest_log_file);
+  }
+  if (log_file_cnt == -1) return false;
+
+  // Housekeeping for cfg files
+  int number_deleted_files = 0;
+  int cfg_file_cnt = get_number_of_cfg_files_h(stream, oldest_cfg_file);
+  while (cfg_file_cnt >= max_files_rotated) {
+TRACE("Delete oldest_cfg_file %s", oldest_cfg_file);
+if (file_unlink_h(oldest_cfg_file) == -1) {
+  LOG_NO("Delete cfg file fail: %s - %s", oldest_cfg_file, 
strerror(errno));
+  return false;
 }
-
-if (!((cfg_file_cnt = get_number_of_cfg_files_h(stream, oldest_cfg_file)) 
==
-  -1)) {
-  oldest_cfg = true;
+++number_deleted_files;
+cfg_file_cnt = get_number_of_cfg_files_h(stream, oldest_cfg_file);
+
+// If there is too much cfg files that the rotation hasn't deleted them
+// in previous, lgs should limit the deleting to avoid main thread is hung
+// due to the deleting huge cfg files will take long times.
+// The workaround here is that hard-code to