Просмотр исходного кода

HPCC-22651 Remove any assumption log files are fixed width

Signed-off-by: Shamser Ahmed <shamser.ahmed@lexisnexis.co.uk>
Shamser Ahmed 5 лет назад
Родитель
Сommit
2396aadc4f

+ 23 - 22
esp/services/ws_workunits/ws_workunitsHelpers.cpp

@@ -2084,45 +2084,46 @@ void WsWuInfo::readWorkunitLog(IFile* sourceFile, MemoryBuffer& buf, const char*
     else
         eof = lineReader->readLine(line.clear());
 
-    const unsigned positionProcessId = getPositionOfField(logfields, MSGFIELD_process);
+    const unsigned columnNumPID = getPositionOfField(logfields, MSGFIELD_process);
     bool outputThisLine = false;
     unsigned processID = 0;
     bool foundEndWUID = false; 
     while (!eof)
     {
-        if (line.length() > positionProcessId+1)
-        {
-            const char * lineStartingProcessId = line.str()+positionProcessId;
-            if (outputThisLine)
-            {
-                //If the slave is restarted before WU is finished, we cannot find out the "Finished wuid=...".
-                //So, we should check whether the slave is restarting or not.
-                unsigned pID = 0;
-                foundEndWUID = parseLogLine(lineStartingProcessId, endwuid, pID);
-                if ((pID > 0) && (pID != processID))
-                    break;
-            }
-            else if (strstr(lineStartingProcessId, startwuid))
-            {
-                outputThisLine = true;
-                foundEndWUID = false;
-                if (processID == 0)
-                    parseLogLine(lineStartingProcessId, nullptr, processID);
-            }
-        }
         if (outputThisLine)
         {
+            //If the slave is restarted before WU is finished, we cannot find out the "Finished wuid=...".
+            //So, we should check whether the slave is restarting or not.
+            unsigned pID = 0;
+            foundEndWUID = parseLogLine(line.str(), endwuid, pID, columnNumPID);
+            if ((pID > 0) && (pID != processID))
+                break;
             outputALine(line.length(), line.str(), buf, outIOS);
             if (foundEndWUID)
                 outputThisLine = false;
         }
+        else if (strstr(line.str(), startwuid))
+        {
+            outputThisLine = true;
+            foundEndWUID = false;
+            outputALine(line.length(), line.str(), buf, outIOS);
+            if (processID == 0)
+                parseLogLine(line.str(), nullptr, processID, columnNumPID);
+        }
         eof = lineReader->readLine(line.clear());
     }
 }
 
-bool WsWuInfo::parseLogLine(const char* line, const char* endWUID, unsigned& processID)
+bool WsWuInfo::parseLogLine(const char* line, const char* endWUID, unsigned& processID, const unsigned columnNumPID)
 {
     const char* bptr = line;
+    for (unsigned cur=0;  cur < columnNumPID && *bptr; ++cur)
+    {
+        while(*bptr && *bptr!=' ') ++bptr;  // Skip field
+        while(*bptr && *bptr==' ') ++bptr;  // Skip spaces
+    }
+    if (!*bptr) return false;
+
     const char* eptr = bptr + 1;
     while (*eptr && isdigit(*eptr))     //Read ProcessID
         eptr++;

+ 1 - 1
esp/services/ws_workunits/ws_workunitsHelpers.hpp

@@ -141,7 +141,7 @@ class WsWuInfo
     IEspWUArchiveModule* readArchiveModuleAttr(IPropertyTree& moduleTree, const char* path);
     void readArchiveFiles(IPropertyTree* archiveTree, const char* path, IArrayOf<IEspWUArchiveFile>& files);
     void outputALine(size32_t len, const char* content, MemoryBuffer& outputBuf, IFileIOStream* outIOS);
-    bool parseLogLine(const char* line, const char* endWUID, unsigned& processID);
+    bool parseLogLine(const char* line, const char* endWUID, unsigned& processID, const unsigned columnNumPID);
     void readWorkunitLog(IFile* ios, MemoryBuffer& buf, const char* outFile);
     void readFileContent(const char* sourceFileName, const char* sourceIPAddress,
         const char* sourceAlias, MemoryBuffer &mb, bool forDownload);

+ 3 - 3
system/jlib/jlog.cpp

@@ -127,11 +127,11 @@ public:
             if (MsgFieldMap[i].val==MSGFIELD_time && (logfields & (MSGFIELD_microTime|MSGFIELD_milliTime)) )
                 continue;
             if (MsgFieldMap[i].val & positionoffield)
-                return pos;
+                break;
             if (MsgFieldMap[i].val & logfields)
-                pos += strlen(MsgFieldMap[i].str);
+                ++pos;
         }
-        return 0;
+        return pos;
     }
     unsigned extractMessageFieldsFromHeader(const char *line, bool hashPrefixed)
     {