Repository: trafodion
Updated Branches:
  refs/heads/master 66499100c -> 82bfb1a22


RMS infrastructure now reads the configured pid Max from 
/proc/sys/kernel/pid_max
but limits it to a maximum of 128K. It can be overridden by "PID_MAX" 
environment
variable in ms.env.

If the PID_MAX variable is set to 0, 64K is assumed to be configured pid max.
If the PID_MAX variable is set to less than 32K, then 32K is assumed to be 
configured pid max.

When a SQL process has a pin greater than the configured pid max, an error 
message
"Pid , is higher than the configured pid max <configured_pid>" is written to
the SQL log file and disables RMS for those processes. Node won't be brought 
down.

"Get Statistics for rms " shows the the configured pid max.

The environment variable to set the size of RMS shared segment size is now
changed to RMS_SHARED_SEG_SIZE_MB.

genms change for controlling pid_max and rms shared segment size


Project: http://git-wip-us.apache.org/repos/asf/trafodion/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafodion/commit/e7624aaa
Tree: http://git-wip-us.apache.org/repos/asf/trafodion/tree/e7624aaa
Diff: http://git-wip-us.apache.org/repos/asf/trafodion/diff/e7624aaa

Branch: refs/heads/master
Commit: e7624aaaf8d1cad59186c07686404c652d0eb97b
Parents: 087af70
Author: selvaganesang <selva.govindara...@esgyn.com>
Authored: Fri Feb 16 15:56:48 2018 +0000
Committer: selvaganesang <selva.govindara...@esgyn.com>
Committed: Fri Feb 16 15:56:48 2018 +0000

----------------------------------------------------------------------
 core/sqf/sql/scripts/genms              |  8 ++++
 core/sql/bin/ex_sscp_main.cpp           |  2 +-
 core/sql/cli/Globals.cpp                | 17 ++++++--
 core/sql/cli/sqlcli.h                   |  1 +
 core/sql/common/ComRtUtils.cpp          | 23 ++++++++++
 core/sql/common/ComRtUtils.h            |  2 +
 core/sql/executor/ExExeUtilGetStats.cpp | 10 +++--
 core/sql/executor/ExStats.cpp           |  9 +++-
 core/sql/executor/ExStats.h             |  2 +
 core/sql/executor/ex_esp_frag_dir.cpp   | 18 ++++++--
 core/sql/regress/core/EXPECTEDRTS       |  1 +
 core/sql/regress/core/FILTERRTS         |  1 +
 core/sql/runtimestats/SqlStats.cpp      | 64 +++++++++++++++++-----------
 core/sql/runtimestats/SqlStats.h        | 10 +++--
 14 files changed, 126 insertions(+), 42 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafodion/blob/e7624aaa/core/sqf/sql/scripts/genms
----------------------------------------------------------------------
diff --git a/core/sqf/sql/scripts/genms b/core/sqf/sql/scripts/genms
index aa9129a..29ac957 100755
--- a/core/sqf/sql/scripts/genms
+++ b/core/sqf/sql/scripts/genms
@@ -208,6 +208,14 @@ echo "REST_INSTALL_DIR=$restinstalldir"
 echo "TRAF_VAR=$TRAF_VAR"
 echo "TRAF_CONF=$TRAF_CONF"
 
+if [[ ! -z "$PID_MAX" ]]; then
+   echo "PID_MAX=$PID_MAX"
+fi
+
+if [[ ! -z "$RMS_SHARED_SEG_SIZE_MB" ]]; then
+   echo "RMS_SHARED_SEG_SIZE_MB=$RMS_SHARED_SEG_SIZE_MB"
+fi
+
 echo ""
 echo ""
 echo "# Added by gensq.pl"

http://git-wip-us.apache.org/repos/asf/trafodion/blob/e7624aaa/core/sql/bin/ex_sscp_main.cpp
----------------------------------------------------------------------
diff --git a/core/sql/bin/ex_sscp_main.cpp b/core/sql/bin/ex_sscp_main.cpp
index a1f1f2b..40b19e2 100644
--- a/core/sql/bin/ex_sscp_main.cpp
+++ b/core/sql/bin/ex_sscp_main.cpp
@@ -165,7 +165,7 @@ void runServer(Int32 argc, char **argv)
   struct tm *nowtm;
 
   long maxSegSize = STATS_MAX_SEG_SIZE;
-  char *envSegSize = getenv("MX_RTS_STATS_SEG_SIZE");
+  char *envSegSize = getenv("RMS_SHARED_SEG_SIZE_MB");
   if (envSegSize)
   {
     maxSegSize = (long) str_atoi(envSegSize, str_len(envSegSize));

http://git-wip-us.apache.org/repos/asf/trafodion/blob/e7624aaa/core/sql/cli/Globals.cpp
----------------------------------------------------------------------
diff --git a/core/sql/cli/Globals.cpp b/core/sql/cli/Globals.cpp
index ed30502..5ecd5c1 100644
--- a/core/sql/cli/Globals.cpp
+++ b/core/sql/cli/Globals.cpp
@@ -176,10 +176,21 @@ void CliGlobals::init( NABoolean espProcess,
     cli_globals = this;
     int error;
     statsGlobals_ = (StatsGlobals *)shareStatsSegment(shmId_);
-    if (statsGlobals_ == NULL
-      || (statsGlobals_ != NULL && 
-        statsGlobals_->getVersion() != 
StatsGlobals::CURRENT_SHARED_OBJECTS_VERSION_))
+    NABoolean reportError = FALSE;
+    char msg[256];;
+    if (statsGlobals_ != NULL && myPin_ >= 
statsGlobals_->getConfiguredPidMax())
+       reportError = TRUE;
+    if ((statsGlobals_ == NULL)
+      || ((statsGlobals_ != NULL) && 
+        ((statsGlobals_->getVersion() != 
StatsGlobals::CURRENT_SHARED_OBJECTS_VERSION_) ||
+        (myPin_ >= statsGlobals_->getConfiguredPidMax()))))
     {
+      if (reportError) {
+         snprintf(msg, sizeof(msg),
+          "Pid %d,%d is higher than the configured pid max %d",
+           myCpu_, myPin_, statsGlobals_->getConfiguredPidMax());
+         SQLMXLoggingArea::logExecRtInfo(__FILE__, __LINE__, msg, 0);
+      }
       statsGlobals_ = NULL;
       statsHeap_ = new (getExecutorMemory()) 
         NAHeap("Process Stats Heap", getExecutorMemory(),

http://git-wip-us.apache.org/repos/asf/trafodion/blob/e7624aaa/core/sql/cli/sqlcli.h
----------------------------------------------------------------------
diff --git a/core/sql/cli/sqlcli.h b/core/sql/cli/sqlcli.h
index 3a8a5b4..ff5deea 100644
--- a/core/sql/cli/sqlcli.h
+++ b/core/sql/cli/sqlcli.h
@@ -1157,6 +1157,7 @@ enum SQLSTATS_ITEM_ID {
   SQLSTATS_RMS_STATS_RESET_TIMESTAMP = 130,
   SQLSTATS_RMS_STATS_NUM_SQL_SIK = 131,
   SQLSTATS_PROCESS_STATS_HEAPS = 132,
+  SQLSTATS_RMS_CONFIGURED_PID_MAX = 133,
 /* SQLSTATS_ITEM_ID for BMO_STATS */
   SQLSTATS_BMO_HEAP_USED = 150,
   SQLSTATS_BMO_HEAP_ALLOC = 151,

http://git-wip-us.apache.org/repos/asf/trafodion/blob/e7624aaa/core/sql/common/ComRtUtils.cpp
----------------------------------------------------------------------
diff --git a/core/sql/common/ComRtUtils.cpp b/core/sql/common/ComRtUtils.cpp
index f2619f9..15f2e7d 100644
--- a/core/sql/common/ComRtUtils.cpp
+++ b/core/sql/common/ComRtUtils.cpp
@@ -1122,3 +1122,26 @@ const char *ComRtGetUnknownString(Int32 val)
   sprintf(ComRtGetUnknownString_Buf, "UNKNOWN (%d)", (int) val);
   return &(ComRtGetUnknownString_Buf[0]);
 }
+
+
+pid_t ComRtGetConfiguredPidMax()
+{
+   FILE *fd_pid_max;
+   char buffer[100];
+   size_t bytesRead = 0;
+   pid_t pid_max = 0;
+
+   fd_pid_max = fopen("/proc/sys/kernel/pid_max", "r");
+   if (fd_pid_max != NULL) {
+      bytesRead = fread(buffer, 1, sizeof(buffer)-1, fd_pid_max);
+      if (ferror(fd_pid_max))
+         assert(false); 
+      if (feof(fd_pid_max))
+         clearerr(fd_pid_max);
+      buffer[bytesRead] = '\0';
+      pid_max = atoi(buffer);
+      fclose(fd_pid_max);
+      return pid_max;
+   } 
+   return 0;
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/trafodion/blob/e7624aaa/core/sql/common/ComRtUtils.h
----------------------------------------------------------------------
diff --git a/core/sql/common/ComRtUtils.h b/core/sql/common/ComRtUtils.h
index 94d309c..d26e52e 100644
--- a/core/sql/common/ComRtUtils.h
+++ b/core/sql/common/ComRtUtils.h
@@ -288,4 +288,6 @@ Int16 getBDRClusterName(char *bdrClusterName);
 
 SB_Phandle_Type *get_phandle_with_retry(char *pname, short *fserr = NULL);
 
+pid_t ComRtGetConfiguredPidMax();
+
 #endif // COMRTUTILS_H

http://git-wip-us.apache.org/repos/asf/trafodion/blob/e7624aaa/core/sql/executor/ExExeUtilGetStats.cpp
----------------------------------------------------------------------
diff --git a/core/sql/executor/ExExeUtilGetStats.cpp 
b/core/sql/executor/ExExeUtilGetStats.cpp
index 72bdd2b..b6d47c7 100644
--- a/core/sql/executor/ExExeUtilGetStats.cpp
+++ b/core/sql/executor/ExExeUtilGetStats.cpp
@@ -3658,7 +3658,7 @@ short ExExeUtilGetRTSStatisticsTcb::work()
       {
         if (rmsStatsItems_ == NULL)
         {
-          maxRMSStatsItems_ = 33;
+          maxRMSStatsItems_ = 34;
           rmsStatsItems_ = new (getGlobals()->getDefaultHeap()) 
                   SQLSTATS_ITEM[maxRMSStatsItems_];
           initSqlStatsItems(rmsStatsItems_, maxRMSStatsItems_, FALSE);
@@ -3695,7 +3695,8 @@ short ExExeUtilGetRTSStatisticsTcb::work()
           rmsStatsItems_[30].statsItem_id = SQLSTATS_SSCP_REPLY_MSG_BYTES;
           rmsStatsItems_[31].statsItem_id = SQLSTATS_RMS_STATS_RESET_TIMESTAMP;
           rmsStatsItems_[32].statsItem_id = SQLSTATS_RMS_STATS_NUM_SQL_SIK;
-          // maxRMSStatsItems_ is set to 33
+          rmsStatsItems_[33].statsItem_id = SQLSTATS_RMS_CONFIGURED_PID_MAX;
+          // maxRMSStatsItems_ is set to 34
           rmsStatsItems_[0].str_value = new (getGlobals()->getDefaultHeap())
             char[MAX_SEGMENT_NAME_LEN+1];
           rmsStatsItems_[0].str_max_len = MAX_SEGMENT_NAME_LEN;
@@ -3884,7 +3885,10 @@ short ExExeUtilGetRTSStatisticsTcb::work()
                        timestamp[3], timestamp[4], timestamp[5],
                        timestamp[6], timestamp[7]);
            break;
-
+          case SQLSTATS_RMS_CONFIGURED_PID_MAX:
+            sprintf(Int64Val, "%ld", rmsStatsItems_[i].int64_value);
+            sprintf(statsBuf_, "%-30s%s", "Configured Pid Max", Int64Val);
+            break;
           }
           if (strlen(statsBuf_) > 0)
             if (moveRowToUpQueue(statsBuf_, strlen(statsBuf_), &rc) == -1)

http://git-wip-us.apache.org/repos/asf/trafodion/blob/e7624aaa/core/sql/executor/ExStats.cpp
----------------------------------------------------------------------
diff --git a/core/sql/executor/ExStats.cpp b/core/sql/executor/ExStats.cpp
index 7093c44..006b79f 100644
--- a/core/sql/executor/ExStats.cpp
+++ b/core/sql/executor/ExStats.cpp
@@ -10069,6 +10069,7 @@ ExRMSStats::ExRMSStats(NAHeap *heap)
   rmsStatsResetTimestamp_ = NA_JulianTimestamp();
   numQueryInvKeys_ = 0;
   nodesInCluster_ = 0;
+  configuredPidMax_ = 0;
 }
 
 void ExRMSStats::reset()
@@ -10217,7 +10218,7 @@ void ExRMSStats::getVariableStatsInfo(char * dataBuffer,
         "stmtStatsGCed: %d lastGCTime: %ld "
         "totalStmtStatsGCed: %ld ssmpReqMsgCnt: %ld ssmpReqMsgBytes: %ld 
ssmpReplyMsgCnt: %ld ssmpReplyMsgBytes: %ld "
         "sscpReqMsgCnt: %ld sscpReqMsgBytes: %ld sscpReplyMsgCnt: %ld 
sscpReplyMsgBytes: %ld resetTimestamp: %ld " 
-        "numQueryInvKeys: %d ",
+        "numQueryInvKeys: %d  configuredPidMax: %d",
         statType(),
         rmsVersion_,
         nodeName_,
@@ -10252,7 +10253,8 @@ void ExRMSStats::getVariableStatsInfo(char * dataBuffer,
         sscpReplyMsgCnt_,
         sscpReplyMsgBytes_,
         rmsStatsResetTimestamp_,
-        numQueryInvKeys_
+        numQueryInvKeys_,
+        configuredPidMax_
        );
   }
   buf += str_len(buf);
@@ -10384,6 +10386,9 @@ Lng32 ExRMSStats::getStatsItem(SQLSTATS_ITEM* 
sqlStats_item)
   case SQLSTATS_RMS_STATS_NUM_SQL_SIK:
     sqlStats_item->int64_value = numQueryInvKeys_;
     break;
+  case SQLSTATS_RMS_CONFIGURED_PID_MAX:
+    sqlStats_item->int64_value = configuredPidMax_;
+    break;
   default:
     sqlStats_item->error_code = -EXE_STAT_NOT_FOUND;
     break;

http://git-wip-us.apache.org/repos/asf/trafodion/blob/e7624aaa/core/sql/executor/ExStats.h
----------------------------------------------------------------------
diff --git a/core/sql/executor/ExStats.h b/core/sql/executor/ExStats.h
index f6b074a..e244b4d 100644
--- a/core/sql/executor/ExStats.h
+++ b/core/sql/executor/ExStats.h
@@ -3283,6 +3283,7 @@ public:
   }
   inline void setNumQueryInvKeys(Int32 n) { numQueryInvKeys_ = n; }
   inline void setNodesInCluster(short n) { nodesInCluster_ = n; }
+  inline void setConfiguredPidMax(pid_t pid) { configuredPidMax_ = pid; }
   Lng32 getStatsItem(SQLSTATS_ITEM* sqlStats_item);
   void reset();
 private: 
@@ -3320,6 +3321,7 @@ private:
   Int64 rmsStatsResetTimestamp_;
   Int32 numQueryInvKeys_;
   short nodesInCluster_;
+  pid_t configuredPidMax_;
 };
 
 

http://git-wip-us.apache.org/repos/asf/trafodion/blob/e7624aaa/core/sql/executor/ex_esp_frag_dir.cpp
----------------------------------------------------------------------
diff --git a/core/sql/executor/ex_esp_frag_dir.cpp 
b/core/sql/executor/ex_esp_frag_dir.cpp
index 81ee824..233f952 100644
--- a/core/sql/executor/ex_esp_frag_dir.cpp
+++ b/core/sql/executor/ex_esp_frag_dir.cpp
@@ -101,11 +101,23 @@ ExEspFragInstanceDir::ExEspFragInstanceDir(CliGlobals 
*cliGlobals,
   pid_ = phandle.getPin();
 
   tid_ = syscall(SYS_gettid);
-  if (statsGlobals_ == NULL
-    || (statsGlobals_ != NULL && 
-      statsGlobals_->getVersion() != 
StatsGlobals::CURRENT_SHARED_OBJECTS_VERSION_))
+  NABoolean reportError = FALSE;
+  char msg[256];;
+  if (statsGlobals_ != NULL && pid_ >= statsGlobals_->getConfiguredPidMax())
+     reportError = TRUE;
+  if ((statsGlobals_ == NULL)
+     || ((statsGlobals_ != NULL) && 
+        ((statsGlobals_->getVersion() != 
StatsGlobals::CURRENT_SHARED_OBJECTS_VERSION_) ||
+        (pid_ >= statsGlobals_->getConfiguredPidMax()))))
   {
+    if (reportError) {
+         snprintf(msg, sizeof(msg), 
+          "Pid %d,%d is higher than the configured pid max %d",
+           cpu_, pid_, statsGlobals_->getConfiguredPidMax()); 
+         SQLMXLoggingArea::logExecRtInfo(__FILE__, __LINE__, msg, 0);
+    }
     statsGlobals_ = NULL;
+
     statsHeap_ = new (heap_) 
         NAHeap("Process Stats Heap", (NAHeap *)heap_,
         8192,

http://git-wip-us.apache.org/repos/asf/trafodion/blob/e7624aaa/core/sql/regress/core/EXPECTEDRTS
----------------------------------------------------------------------
diff --git a/core/sql/regress/core/EXPECTEDRTS 
b/core/sql/regress/core/EXPECTEDRTS
index 95af9ad..fe867e0 100644
--- a/core/sql/regress/core/EXPECTEDRTS
+++ b/core/sql/regress/core/EXPECTEDRTS
@@ -3546,6 +3546,7 @@ SSCP Reply Message Count      353
 SSCP Reply Message Bytes      139,848
 RMS Stats Reset Timestamp     2017/11/23 16:54:16.511971
 No. Query Invalidation Keys   121
+Configured Pid Max            32768
 
 
 --- SQL operation complete.

http://git-wip-us.apache.org/repos/asf/trafodion/blob/e7624aaa/core/sql/regress/core/FILTERRTS
----------------------------------------------------------------------
diff --git a/core/sql/regress/core/FILTERRTS b/core/sql/regress/core/FILTERRTS
index c7f92bc..3832ed8 100755
--- a/core/sql/regress/core/FILTERRTS
+++ b/core/sql/regress/core/FILTERRTS
@@ -81,6 +81,7 @@ s/SSCP Request Message Bytes[ ]*[0-9,]*/SSCP Request Message 
Bytes @sscpRequestM
 s/SSCP Reply Message Count[ ]*[0-9,]*/SSCP Reply Message Count 
@sscpReplytMessageCount@/
 s/SSCP Reply Message Bytes[ ]*[0-9,]*/SSCP Reply Message Bytes 
@sscpReplyMessageBytes@/
 s/Query Invalidation Keys[ ]*[0-9]*/Query Invalidation Keys/
+s/Configured Pid Max[ ]*[0-9]*/Configured Pid Max @configuredPidMax@/
 s/IPC Memory Allocated[ 0-9]*/IPC Memory Allocated @exeMemory@/
 s/EXE Memory Allocated[ 0-9]*/EXE Memory Allocated @ipcMemory@/
 s/IPC Memory Used High WM[ 0-9]*/IPC Memory Used High WM @exeMemory@/

http://git-wip-us.apache.org/repos/asf/trafodion/blob/e7624aaa/core/sql/runtimestats/SqlStats.cpp
----------------------------------------------------------------------
diff --git a/core/sql/runtimestats/SqlStats.cpp 
b/core/sql/runtimestats/SqlStats.cpp
index 0b64e02..d801909 100644
--- a/core/sql/runtimestats/SqlStats.cpp
+++ b/core/sql/runtimestats/SqlStats.cpp
@@ -96,6 +96,30 @@ StatsGlobals::StatsGlobals(void *baseAddr, short envType, 
Lng32 maxSegSize)
   releasingSemPid_ = -1;
   seabedError_ = 0;
   seabedPidRecycle_ = false;
+  // Get /proc/sys/kernel/pid_max 
+  // If it is greater than a reasonable value, then
+  // let PID_MAX environment variable to override it
+  // Make sure Pid Max is set to a PID_MAX_DEFAULT_MIN value at least
+  char *pidMaxStr;
+  configuredPidMax_ = ComRtGetConfiguredPidMax();
+  if (configuredPidMax_ == 0)
+     configuredPidMax_ = PID_MAX_DEFAULT;
+  if (configuredPidMax_ > PID_MAX_DEFAULT_MAX) {
+     if ((pidMaxStr = getenv("PID_MAX")) != NULL)
+        configuredPidMax_ = atoi(pidMaxStr);
+     else
+        configuredPidMax_ = PID_MAX_DEFAULT_MAX;
+  }
+  if (configuredPidMax_ == 0)
+     configuredPidMax_ = PID_MAX_DEFAULT;
+  else if (configuredPidMax_ < PID_MAX_DEFAULT_MIN)
+     configuredPidMax_ = PID_MAX_DEFAULT_MIN; 
+  statsArray_ = new (&statsHeap_) GlobalStatsArray[configuredPidMax_];
+  for (pid_t i = 0; i < configuredPidMax_ ; i++) {
+      statsArray_[i].processId_ = 0;
+      statsArray_[i].processStats_ = NULL;
+      statsArray_[i].phandleSeqNum_ = -1;
+  }
 }
 
 void StatsGlobals::init()
@@ -116,6 +140,7 @@ void StatsGlobals::init()
   rmsStats_->setRmsVersion(version_);
   rmsStats_->setRmsEnvType(rtsEnvType_);
   rmsStats_->setStoreSqlSrcLen(storeSqlSrcLen_);
+  rmsStats_->setConfiguredPidMax(configuredPidMax_);
   int rc;
   nodeId_ = cpu_;
   MS_Mon_Node_Info_Type nodeInfo;
@@ -168,35 +193,25 @@ const char *StatsGlobals::rmsEnvType(RTSEnvType envType)
 
 void StatsGlobals::addProcess(pid_t pid, NAHeap *heap)
 {
-  if (statsArray_ == NULL)
-  {
-    statsArray_ = new (&statsHeap_) GlobalStatsArray[MAX_PID_ARRAY_SIZE];
-    for (pid_t i = 0; i < MAX_PID_ARRAY_SIZE ; i++)
-    {
-      statsArray_[i].processId_ = 0;
-      statsArray_[i].processStats_ = NULL;
-      statsArray_[i].creationTime_ = 0;
-      statsArray_[i].phandleSeqNum_ = -1;
-    }
-  }
+  if (pid >= configuredPidMax_)
+     return;
+  char msg[256];;
   if (statsArray_[pid].processStats_ != NULL)
   {
-
-    char msg[256];;
-    str_sprintf(msg,
+    snprintf(msg, sizeof(msg),
         "Pid %d,%d got recycled soon or SSMP didn't receive the death message 
",
            cpu_, pid);
     SQLMXLoggingArea::logExecRtInfo(__FILE__, __LINE__, msg, 0);
     removeProcess(pid, TRUE);
   }   
   statsArray_[pid].processId_ = pid;
-  statsArray_[pid].creationTime_ = GetCliGlobals()->myStartTime();
   statsArray_[pid].phandleSeqNum_ = GetCliGlobals()->myVerifier();
   statsArray_[pid].processStats_ = new (heap) ProcessStats(heap, nodeId_, pid);
   incProcessRegd();
   incProcessStatsHeaps();
   if (pid > maxPid_)
      maxPid_ = pid;
+  return;
 }
 
 void StatsGlobals::removeProcess(pid_t pid, NABoolean calledAtAdd)
@@ -204,13 +219,10 @@ void StatsGlobals::removeProcess(pid_t pid, NABoolean 
calledAtAdd)
   short retcode;
   NABoolean queryRemain = FALSE;
   NAHeap *prevHeap = NULL;
-  if (statsArray_ == NULL)
+  if (pid >= configuredPidMax_)
      return;
   if (statsArray_[pid].processStats_ != NULL)
   {
-    if (!calledAtAdd)
-    {
-    }
     stmtStatsList_->position();
     StmtStats *ss;
     prevHeap = statsArray_[pid].processStats_->getHeap();
@@ -238,7 +250,6 @@ void StatsGlobals::removeProcess(pid_t pid, NABoolean 
calledAtAdd)
     }
   }
   statsArray_[pid].processId_ = 0;
-  statsArray_[pid].creationTime_ = 0;
   statsArray_[pid].phandleSeqNum_ = -1;
   statsArray_[pid].processStats_ = NULL;
   if (pid == maxPid_)
@@ -259,9 +270,9 @@ void StatsGlobals::checkForDeadProcesses(pid_t myPid)
 {
   int error = 0;
 
-  if (statsArray_ == NULL)
-    return;
-
+  if (myPid >= configuredPidMax_)
+     return;
+  
   if (!DeadPollingInitialized)
   {
     DeadPollingInitialized = true;  // make getenv calls once per process
@@ -407,8 +418,7 @@ void StatsGlobals::cleanupDanglingSemaphore(NABoolean 
checkForSemaphoreHolders)
 
 ProcessStats *StatsGlobals::checkProcess(pid_t pid)
 {
-
-  if (statsArray_ == NULL)
+  if (pid >= configuredPidMax_)
     return NULL;
   if (statsArray_[pid].processId_ == pid)
     return statsArray_[pid].processStats_;
@@ -424,6 +434,8 @@ StmtStats *StatsGlobals::addQuery(pid_t pid, char *queryId, 
Lng32 queryIdLen,
   StmtStats *ss;
   char *sqlSrc = NULL;
   Lng32 storeSqlSrcLen = 0;
+  if (pid >= configuredPidMax_)
+     return NULL;
   if (storeSqlSrcLen_ > 0)
   {
     sqlSrc = sourceStr;
@@ -445,6 +457,7 @@ int StatsGlobals::getStatsSemaphore(Long &semId, pid_t pid)
 {
   int error = 0;
   timespec ts;
+  ex_assert(pid < configuredPidMax_, "Semaphore can't be obtained for pids 
greater than configured pid max")
   error = sem_trywait((sem_t *)semId);
   NABoolean retrySemWait = FALSE;
   NABoolean resetClock = TRUE;
@@ -1228,7 +1241,6 @@ StmtStats::StmtStats(NAHeap *heap, pid_t pid, char 
*queryId, Lng32 queryIdLen,
       :heap_(heap),
       pid_(pid),
       stats_(NULL),
-      EspProcHandle_(NULL),
       refCount_(0),
       fragId_(fragId)
 {

http://git-wip-us.apache.org/repos/asf/trafodion/blob/e7624aaa/core/sql/runtimestats/SqlStats.h
----------------------------------------------------------------------
diff --git a/core/sql/runtimestats/SqlStats.h b/core/sql/runtimestats/SqlStats.h
index 0377c3d..eb2cfb4 100644
--- a/core/sql/runtimestats/SqlStats.h
+++ b/core/sql/runtimestats/SqlStats.h
@@ -1,5 +1,5 @@
 /**********************************************************************
-// @@@ START COPYRIGHT @@@
+/ @@@ START COPYRIGHT @@@
 //
 // Licensed to the Apache Software Foundation (ASF) under one
 // or more contributor license agreements.  See the NOTICE file
@@ -69,13 +69,14 @@ class MemoryMonitor;
 #include "SQLCLIdev.h"
 #include "memorymonitor.h"
 
-#define MAX_PID_ARRAY_SIZE 65536
+#define PID_MAX_DEFAULT     65536
+#define PID_MAX_DEFAULT_MAX 131072
+#define PID_MAX_DEFAULT_MIN 32768
 
 typedef struct GlobalStatsArray
 {
   pid_t  processId_;
   SB_Verif_Type  phandleSeqNum_;
-  Int64  creationTime_;
   ProcessStats  *processStats_;
 } GlobalStatsArray;
 
@@ -219,7 +220,6 @@ private:
   char *queryId_;
   Lng32 queryIdLen_;
   ExMasterStats *masterStats_;
-  HashQueue *EspProcHandle_;
   ExStatisticsArea *stats_;
   Int64 lastMergedTime_;
   ExStatisticsArea *mergedStats_;
@@ -435,6 +435,7 @@ public:
   inline pid_t getSemPid() { return semPid_; }
   inline pid_t getSsmpPid();
   inline Int64 getSsmpTimestamp();
+  inline pid_t getConfiguredPidMax() { return configuredPidMax_; }
   inline void setSsmpDumpTimestamp(Int64 dumpTime) 
           { ssmpDumpedTimestamp_ = dumpTime; }
   inline Int64 getSsmpDumpTimestamp() 
@@ -531,6 +532,7 @@ private:
   pid_t maxPid_;
   Int64 ssmpDumpedTimestamp_;
   MemoryMonitor *memMonitor_;
+  pid_t configuredPidMax_;
 };
 StatsGlobals * shareStatsSegment(Int32 &shmid, NABoolean checkForSSMP = TRUE);
 short getMasterCpu(char *uniqueStmtId, Lng32 uniqueStmtIdLen, char *nodeName, 
short maxLen, short &cpu);

Reply via email to