From ec55bcd089fb08f9ad8542b737b7129fcd4ef798 Mon Sep 17 00:00:00 2001 From: Shamser Ahmed Date: Wed, 18 Dec 2024 14:20:29 +0000 Subject: [PATCH] HPCC-33142 Distinguish between id and sequency number in SysInfoLogger Use id or msgid for unique SysInfoLogger message identifier Use SeqNum for the sequence number used to the generated ensure id/msgid is unique Signed-off-by: Shamser Ahmed --- dali/base/sysinfologger.cpp | 61 +++++++++++++++++++++---------------- dali/base/sysinfologger.hpp | 4 +++ 2 files changed, 39 insertions(+), 26 deletions(-) diff --git a/dali/base/sysinfologger.cpp b/dali/base/sysinfologger.cpp index 3bd277bb2a1..b3fdfcba83d 100644 --- a/dali/base/sysinfologger.cpp +++ b/dali/base/sysinfologger.cpp @@ -23,10 +23,10 @@ #define SYS_INFO_VERSION "1.0" #define SYS_INFO_ROOT "/SysLogs" -#define ATTR_NEXTID "@nextId" +#define ATTR_NEXTSEQN "@nextSeqNum" #define ATTR_VERSION "@version" #define MSG_NODE "msg" -#define ATTR_ID "@id" +#define ATTR_SEQNUM "@seqNum" #define ATTR_TIMESTAMP "@ts" #define ATTR_AUDIENCE "@audience" #define ATTR_CLASS "@class" @@ -34,6 +34,8 @@ #define ATTR_HIDDEN "@hidden" #define ATTR_SOURCE "@source" +static constexpr unsigned __int64 nonSysInfoLogMsgMask = 0x80000000; + static void extractDate(timestamp_type ts, unsigned & year, unsigned & month, unsigned & day) { CDateTime timeStamp; @@ -41,24 +43,29 @@ static void extractDate(timestamp_type ts, unsigned & year, unsigned & month, un timeStamp.getDate(year, month, day); } -static unsigned __int64 makeMessageId(unsigned year, unsigned month, unsigned day, unsigned id) +unsigned __int64 makeMessageId(unsigned year, unsigned month, unsigned day, unsigned seqN, bool nonSysInfoLogMsg) { - return id<<21 | year<<9 | month<<5 | day; + // bits 0-4 = day, bits 5-8 = month, bits 9-22 = year + // bit 24-30 unused + // bit 31 = (flag) unset means SysInfoLogger managed message, set means message managed elsewhere + // bits 32-63 = sequence number + return seqN<<32 | (nonSysInfoLogMsg?nonSysInfoLogMsgMask:0) | year<<9 | month<<5 | day; } -static unsigned __int64 makeMessageId(unsigned __int64 ts, unsigned id) +unsigned __int64 makeMessageId(unsigned __int64 ts, unsigned seqN, bool nonSysInfoLogMsg) { unsigned year, month, day; extractDate(ts, year, month, day); - return makeMessageId(year, month, day, id); + return makeMessageId(year, month, day, seqN, nonSysInfoLogMsg); } -static void decodeMessageId(unsigned __int64 msgId, unsigned & year, unsigned & month, unsigned & day, unsigned & id) +static bool decodeMessageId(unsigned __int64 msgId, unsigned & year, unsigned & month, unsigned & day, unsigned & seqn) { day = msgId & 0x1F; month = (msgId>>5) & 0x0F; - year = (msgId>>9) & 0xFFF; - id = (msgId>>21); + year = (msgId>>9) & 0x3FFF; + seqn = msgId>>32; + return msgId & nonSysInfoLogMsgMask; } class CSysInfoLoggerMsg : implements ISysInfoLoggerMsg @@ -77,10 +84,10 @@ class CSysInfoLoggerMsg : implements ISysInfoLoggerMsg { msgPtree.setown(createPTree(MSG_NODE)); } - CSysInfoLoggerMsg(unsigned id, const LogMsgCategory & cat, LogMsgCode code, const char * source, const char * msg, timestamp_type ts, bool hidden) + CSysInfoLoggerMsg(unsigned seqn, const LogMsgCategory & cat, LogMsgCode code, const char * source, const char * msg, timestamp_type ts, bool hidden) { msgPtree.setown(createPTree(MSG_NODE)); - msgPtree->setPropInt64(ATTR_ID, id); + msgPtree->setPropInt64(ATTR_SEQNUM, seqn); msgPtree->setPropBool(ATTR_HIDDEN, hidden); msgPtree->setPropInt64(ATTR_TIMESTAMP, ts); msgPtree->setPropInt(ATTR_CODE, code); @@ -130,7 +137,7 @@ class CSysInfoLoggerMsg : implements ISysInfoLoggerMsg } virtual unsigned __int64 queryLogMsgId() const override { - return makeMessageId(queryTimeStamp(), msgPtree->getPropInt64(ATTR_ID, 0)); + return makeMessageId(queryTimeStamp(), msgPtree->getPropInt64(ATTR_SEQNUM, 0)); } virtual const char * queryMsg() const override { @@ -146,8 +153,8 @@ class CSysInfoLoggerMsg : implements ISysInfoLoggerMsg { unsigned year, month, day; extractDate(queryTimeStamp(), year, month, day); - unsigned __int64 id = msgPtree->getPropInt64(ATTR_ID, 0); - xpath.appendf("m%04u%02u/d%02u/" MSG_NODE "[" ATTR_ID "='%" I64F "u']", year, month, day, id); + unsigned __int64 seqn = msgPtree->getPropInt64(ATTR_SEQNUM, 0); + xpath.appendf("m%04u%02u/d%02u/" MSG_NODE "[" ATTR_SEQNUM "='%" I64F "u']", year, month, day, seqn); return xpath; } IPropertyTree * getTree() @@ -220,14 +227,16 @@ class CSysInfoLoggerMsgFilter : public CSimpleInterfaceOfqueryRoot(); - unsigned id = root->getPropInt(ATTR_NEXTID, 1); - if (id==UINT_MAX) // wrap id to reuse id numbers (shouldn't wrap but no harm in doing this for safety) - id=1; - root->setPropInt(ATTR_NEXTID, id+1); + unsigned seqn = root->getPropInt(ATTR_NEXTSEQN, 1); + if (seqn==UINT_MAX) // wrap id to reuse id numbers (shouldn't wrap but no harm in doing this for safety) + seqn=1; + root->setPropInt(ATTR_NEXTSEQN, seqn+1); StringBuffer xpath; unsigned year, month, day; @@ -515,10 +524,10 @@ unsigned __int64 logSysInfoError(const LogMsgCategory & cat, LogMsgCode code, co throw makeStringExceptionV(-1, "logSysInfoLogger: unable to create connection to '%s'", xpath.str()); IPropertyTree * msgPT = connMsgRoot->queryRoot(); - CSysInfoLoggerMsg sysInfoMsg(id, cat, code, source, msg, ts, false); + CSysInfoLoggerMsg sysInfoMsg(seqn, cat, code, source, msg, ts, false); msgPT->setPropTree(nullptr, sysInfoMsg.getTree()); msgPT->setProp(".", msg); // previous setPropTree doesn't set the node value - return makeMessageId(ts, id); + return makeMessageId(ts, seqn); } unsigned updateMessage(IConstSysInfoLoggerMsgFilter * msgFilter, std::function updateOp) diff --git a/dali/base/sysinfologger.hpp b/dali/base/sysinfologger.hpp index 2eb0af56edd..9eb0d986e66 100644 --- a/dali/base/sysinfologger.hpp +++ b/dali/base/sysinfologger.hpp @@ -89,4 +89,8 @@ SYSINFO_API unsigned deleteLogSysInfoMsg(IConstSysInfoLoggerMsgFilter * msgFilte SYSINFO_API bool deleteLogSysInfoMsg(unsigned __int64 msgId, const char *source=nullptr); SYSINFO_API unsigned deleteOlderThanLogSysInfoMsg(bool visibleOnly, bool hiddenOnly, unsigned year, unsigned month, unsigned day, const char *source=nullptr); +/* makeMessageId - Create a message id from date, sequence number and nonSysInfoLogMsg flag to uniquely identify a message + - nonSysInfoLogMsg flag is used to identify whether or not the message is managed by SysInfoLogger */ +SYSINFO_API unsigned __int64 makeMessageId(unsigned __int64 ts, unsigned seqN, bool nonSysInfoLogMsg=false); +SYSINFO_API unsigned __int64 makeMessageId(unsigned year, unsigned month, unsigned day, unsigned seqN, bool nonSysInfoLogMsg=false); #endif