[ https://issues.apache.org/jira/browse/TRAFODION-2927?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16347900#comment-16347900 ]
ASF GitHub Bot commented on TRAFODION-2927: ------------------------------------------- Github user zellerh commented on a diff in the pull request: https://github.com/apache/trafodion/pull/1429#discussion_r165243285 --- Diff: core/sql/ustat/hs_log.cpp --- @@ -389,44 +371,64 @@ NABoolean HSLogMan::GetLogFile(NAString & path, const char* cqd_value) /* until either StartLog() or */ /* ClearLog() methods are called. */ /***********************************************/ -void HSLogMan::StartLog(NABoolean needExplain, const char* logFileName) +void HSLogMan::StartLog(NABoolean needExplain) { - // The GENERATE_EXPLAIN cqd captures explain data pertaining to dynamic - // queries. Ordinarily we want it on, but for just-in-time logging triggered - // by an error, we don't need it, and can't set it because HSFuncExecQuery - // clears the diagnostics area, which causes the error to be lost. - explainOn_ = needExplain; - if (!needExplain || - HSFuncExecQuery("CONTROL QUERY DEFAULT GENERATE_EXPLAIN 'ON'") == 0) + if (!logNeeded_) // if logging isn't already on { - CollIndex activeNodes = gpClusterInfo->numOfSMPs(); - if (logFileName) - { - *logFile_ = logFileName; - currentTimingEvent_ = -1; - startTime_[0] = 0; /* reset timer */ - logNeeded_ = TRUE; - } - else if(activeNodes > 2) - {//we consider we are running on cluster - //if gpClusterInfo->numOfSMPs() > 2 - NABoolean ret = FALSE; - if(GetLogFile(*logFile_, ActiveSchemaDB()->getDefaults().getValue(USTAT_LOG))) - ret = ContainDirExist(logFile_->data()); - - if(ret) - logNeeded_ = TRUE; - - currentTimingEvent_ = -1; - startTime_[0] = 0; /* reset timer */ - } + // Construct logfile name incorporating process id and node number. Note that + // the 2nd parameter of processhandle_decompose is named cpu but is actually + // the node number for Seaquest (the 4th param, named nodenumber, is the cluster + // number). + Int32 nodeNum; + Int32 pin; + SB_Phandle_Type procHandle; + XPROCESSHANDLE_GETMINE_(&procHandle); + XPROCESSHANDLE_DECOMPOSE_(&procHandle, &nodeNum, &pin); + long currentTime = (long)time(0); + + const size_t MAX_FILENAME_SIZE = 50; + char qualifiers[MAX_FILENAME_SIZE]; + sprintf(qualifiers, ".%d.%d.%ld.txt", nodeNum, pin, currentTime); + + std::string logFileName; + QRLogger::getRootLogDirectory(CAT_SQL_USTAT, logFileName /* out */); + if (logFileName.size() > 0) + logFileName += '/'; + + const char * ustatLog = ActiveSchemaDB()->getDefaults().getValue(USTAT_LOG); + const char * fileNameStem = ustatLog + strlen(ustatLog); + if (ustatLog == fileNameStem) + fileNameStem = "ULOG"; // CQD USTAT_LOG is the empty string else - { - *logFile_ = ActiveSchemaDB()->getDefaults().getValue(USTAT_LOG); - currentTimingEvent_ = -1; - startTime_[0] = 0; /* reset timer */ - logNeeded_ = TRUE; - } + { + // strip off any directory path name; we will always use the logs directory + // as configured via QRLogger + while ((fileNameStem > ustatLog) && (*(fileNameStem - 1) != '/')) + fileNameStem--; + } + + logFileName += fileNameStem; + logFileName += qualifiers; + + NABoolean logStarted = QRLogger::startLogFile(CAT_SQL_USTAT,logFileName.c_str()); --- End diff -- Sorry, never mind, my apologies for being slow, I realize my mistake now. I was looking at the part that got removed instead of the part that gets retained in fileNameStem. > Keep log information for UPDATE STATISTICS in case of errors > ------------------------------------------------------------ > > Key: TRAFODION-2927 > URL: https://issues.apache.org/jira/browse/TRAFODION-2927 > Project: Apache Trafodion > Issue Type: Bug > Components: sql-cmp > Affects Versions: 2.3 > Reporter: David Wayne Birdsall > Assignee: David Wayne Birdsall > Priority: Major > > Presently, UPDATE STATISTICS keeps a detailed log of its internal activities > if one has specifed "update statistics log on" in advance. > In production scenarios, this is typically not done. That means when a > long-running UPDATE STATISTICS command fails on a large table, one has to > redo it with logging turned on in order to troubleshoot. > A better practice might be to always log, and delete the log if the operation > succeeds. > Another issue with UPDATE STATISTICS logs is their location. The directory is > different than other Trafodion logs and is sometimes hard to find. As part of > this JIRA, consideration should be given to writing the logs to the Trafodion > logs directory instead. -- This message was sent by Atlassian JIRA (v7.6.3#76005)