rfc5424_msgid is only referred when streaming and
having destination name set on that log stream.

It means it does meaningless job sometimes,
that is do hash calculation even there is no destination name set.

This ticket will fix that.
---
 src/log/logd/lgs_dest.cc  |  6 ++++++
 src/log/logd/lgs_imm.cc   | 41 +++++++++++++++++++++++++++++++----------
 src/log/logd/lgs_main.cc  |  2 --
 src/log/logd/lgs_mbcsv.cc | 21 +++++++++++++++------
 4 files changed, 52 insertions(+), 18 deletions(-)

diff --git a/src/log/logd/lgs_dest.cc b/src/log/logd/lgs_dest.cc
index ec8fcc6..9f8be27 100644
--- a/src/log/logd/lgs_dest.cc
+++ b/src/log/logd/lgs_dest.cc
@@ -73,6 +73,12 @@ std::string DestinationHandler::GenerateMsgId(const 
std::string& dn,
     msgid = ((isRtStream == true) ? std::string{sname + 'R'}
                                   : std::string{sname + 'C'});
   } else {
+    // Do `InitializeHashFunction()` once
+    static bool init_invoked = false;
+    if (init_invoked == false) {
+      base::InitializeHashFunction();
+      init_invoked = true;
+    }
     msgid = base::Hash(dn);
   }
 
diff --git a/src/log/logd/lgs_imm.cc b/src/log/logd/lgs_imm.cc
index caf0cc9..1b22c15 100644
--- a/src/log/logd/lgs_imm.cc
+++ b/src/log/logd/lgs_imm.cc
@@ -2353,7 +2353,17 @@ static SaAisErrorT stream_create_and_configure1(
           char *value_str = *(reinterpret_cast<char **>(value));
           vstring.push_back(value_str);
         }
+
         log_stream_add_dest_name(*stream, vstring);
+        if (vstring.empty() == false) {
+          // Generate & cache `MSGID` to `rfc5424MsgId` which later
+          // used in RFC5424 protocol
+          (*stream)->rfc5424MsgId =
+              DestinationHandler::Instance().GenerateMsgId(
+              (*stream)->name, (*stream)->isRtStream);
+          TRACE("%s: stream %s - msgid = %s", __func__, 
(*stream)->name.c_str(),
+                (*stream)->rfc5424MsgId.c_str());
+        }
       }
     }
     i++;
@@ -2390,11 +2400,6 @@ static SaAisErrorT stream_create_and_configure1(
     osaf_abort(0);
   }
 
-  // Generate & cache `MSGID` to `rfc5424MsgId` which later
-  // used in RFC5424 protocol
-  (*stream)->rfc5424MsgId = DestinationHandler::Instance().GenerateMsgId(
-      (*stream)->name, (*stream)->isRtStream);
-
 done:
   TRACE_LEAVE2("rc: %s", saf_error(rc));
   return rc;
@@ -2519,7 +2524,20 @@ static void stream_ccb_apply_modify(const 
CcbUtilOperationData_t *opdata) {
         char *value_str = *(reinterpret_cast<char **>(value));
         vstring.push_back(value_str);
       }
+
       apply_destination_names_change(stream, vstring, attrMod->modType);
+      // Make sure generated msg is only called when
+      // 1) Have destination set
+      // 2) Not yet generated
+      if (vstring.empty() == false && stream->rfc5424MsgId.empty() == true) {
+        // Generate & cache `MSGID` to `rfc5424MsgId` which later
+        // used in RFC5424 protocol
+        stream->rfc5424MsgId =
+            DestinationHandler::Instance().GenerateMsgId(
+                stream->name, stream->isRtStream);
+        TRACE("%s: stream %s - msgid = %s", __func__, stream->name.c_str(),
+              stream->rfc5424MsgId.c_str());
+      }
     } else {
       LOG_ER("Error: Unknown attribute name");
       osafassert(0);
@@ -2860,6 +2878,14 @@ static SaAisErrorT stream_create_and_configure(
         vstring.push_back(value_str);
       }
       log_stream_add_dest_name(stream, vstring);
+      if (vstring.empty() == false) {
+        // Generate & cache `MSGID` to `rfc5424MsgId` which later
+        // used in RFC5424 protocol
+        stream->rfc5424MsgId = DestinationHandler::Instance().GenerateMsgId(
+            dn, stream->isRtStream);
+        TRACE("%s: stream %s - msgid = %s", __func__, stream->name.c_str(),
+              stream->rfc5424MsgId.c_str());
+      }
     } else if (!strcmp(attribute->attrName, "saLogStreamCreationTimestamp")) {
       if (attribute->attrValuesNumber != 0) {
         /* Restore creation timestamp if exist
@@ -2890,11 +2916,6 @@ static SaAisErrorT stream_create_and_configure(
     }
   }
 
-  // Generate & cache `MSGID` to `rfc5424MsgId` which later
-  // used in RFC5424 protocol
-  stream->rfc5424MsgId =
-      DestinationHandler::Instance().GenerateMsgId(dn, stream->isRtStream);
-
 done:
   TRACE_LEAVE2("rc: %s", saf_error(rc));
   return rc;
diff --git a/src/log/logd/lgs_main.cc b/src/log/logd/lgs_main.cc
index d8e54a6..fe2f9a2 100644
--- a/src/log/logd/lgs_main.cc
+++ b/src/log/logd/lgs_main.cc
@@ -281,8 +281,6 @@ static uint32_t log_initialize(void) {
 
   TRACE_ENTER();
 
-  base::InitializeHashFunction();
-
   /**
    * Setup immutils profile once and for all.
    * This profile says immutil_ API will be blocked
diff --git a/src/log/logd/lgs_mbcsv.cc b/src/log/logd/lgs_mbcsv.cc
index 59232e1..e46dfb8 100644
--- a/src/log/logd/lgs_mbcsv.cc
+++ b/src/log/logd/lgs_mbcsv.cc
@@ -2103,7 +2103,6 @@ uint32_t ckpt_proc_open_stream(lgs_cb_t *cb, void *data) {
     stream->logFileCurrent = param->logFileCurrent;
     stream->stb_prev_actlogFileCurrent = param->logFileCurrent;
     stream->stb_logFileCurrent = param->logFileCurrent;
-
     osaf_extended_name_lend(param->logStreamName, &objectName);
     SaImmClassNameT className = immutil_get_className(&objectName);
     if (className != nullptr && strcmp(className, "SaLogStreamConfig") == 0) {
@@ -2119,15 +2118,16 @@ uint32_t ckpt_proc_open_stream(lgs_cb_t *cb, void 
*data) {
         TRACE("Dest_name %s", param->dest_names);
         stream->stb_dest_names = std::string{param->dest_names};
         stream->dest_names = logutil::Parser(stream->stb_dest_names, ";");
+        // Generate & cache `MSGID` to `rfc5424MsgId` which later
+        // used in RFC5424 protocol
+        stream->rfc5424MsgId = DestinationHandler::Instance().GenerateMsgId(
+            stream->name, stream->isRtStream);
+        TRACE("%s: stream %s - msgid = %s", __func__, stream->name.c_str(),
+              stream->rfc5424MsgId.c_str());
       } else {
         stream->stb_dest_names = "";
         stream->dest_names.clear();
       }
-
-      // Generate & cache `MSGID` to `rfc5424MsgId` which later
-      // used in RFC5424 protocol
-      stream->rfc5424MsgId = DestinationHandler::Instance().GenerateMsgId(
-          stream->name, stream->isRtStream);
     }
   }
 
@@ -2366,6 +2366,15 @@ static uint32_t ckpt_proc_cfg_stream(lgs_cb_t *cb, void 
*data) {
       TRACE("dest_names: %s", dest_names);
       stream->stb_dest_names = std::string{dest_names};
       stream->dest_names = logutil::Parser(stream->stb_dest_names, ";");
+      // Make sure generated msg is only called when
+      // 1) Have destination set
+      // 2) Not yet generated
+      if (stream->rfc5424MsgId.empty() == true) {
+        stream->rfc5424MsgId = DestinationHandler::Instance().GenerateMsgId(
+            stream->name, stream->isRtStream);
+        TRACE("%s: stream %s - msgid = %s", __func__, stream->name.c_str(),
+              stream->rfc5424MsgId.c_str());
+      }
     } else {
       stream->stb_dest_names = "";
       stream->dest_names.clear();
-- 
2.7.4


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Opensaf-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensaf-devel

Reply via email to