[TRAFODION-2455] More refinements to row count estimation retry logic

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

Branch: refs/heads/master
Commit: dbc6c0876ca5af07b63d68f388bad07195d106a5
Parents: f165363
Author: Dave Birdsall <dbirds...@apache.org>
Authored: Wed Jan 25 22:40:56 2017 +0000
Committer: Dave Birdsall <dbirds...@apache.org>
Committed: Wed Jan 25 22:40:56 2017 +0000

----------------------------------------------------------------------
 core/sqf/monitor/linux/process.cxx              | 19 ++++++++++++++++--
 core/sql/executor/HBaseClient_JNI.cpp           |  9 +++++++--
 core/sql/executor/HBaseClient_JNI.h             |  1 +
 .../java/org/trafodion/sql/HBaseClient.java     |  2 ++
 core/sql/ustat/hs_cli.cpp                       |  6 ------
 core/sql/ustat/hs_cli.h                         |  3 ---
 core/sql/ustat/hs_globals.cpp                   | 21 ++++++++++++++------
 core/sql/ustat/hs_log.cpp                       |  5 +++--
 8 files changed, 45 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/dbc6c087/core/sqf/monitor/linux/process.cxx
----------------------------------------------------------------------
diff --git a/core/sqf/monitor/linux/process.cxx 
b/core/sqf/monitor/linux/process.cxx
index d84d6af..67c1980 100755
--- a/core/sqf/monitor/linux/process.cxx
+++ b/core/sqf/monitor/linux/process.cxx
@@ -1306,6 +1306,7 @@ bool CProcess::Create (CProcess *parent, int & result)
     char sq_ic[5];
     char term[20];
     char tz[100];
+    bool tz_exists;
     char xauthority[MAX_PROCESS_PATH];
     char *display;
     char *vnodes;
@@ -1317,7 +1318,11 @@ bool CProcess::Create (CProcess *parent, int & result)
     env = getenv ("TERM");
     STRCPY (term, (env?env:"ansi"));
     env = getenv ("TZ");
-    STRCPY (tz, (env?env:""));
+    tz_exists = (env != NULL);
+    if (tz_exists)
+    {
+      STRCPY (tz, env); // see note regarding TZ below
+    }
     env = getenv ("USER");
     STRCPY (user, (env?env:""));
     env = getenv ("HOME");
@@ -1505,7 +1510,17 @@ bool CProcess::Create (CProcess *parent, int & result)
     setEnvStrVal ( childEnv, nextEnv, "USER", user );
     setEnvStrVal ( childEnv, nextEnv, "HOME", home );
     setEnvStrVal ( childEnv, nextEnv, "TERM", term );
-    setEnvStrVal ( childEnv, nextEnv, "TZ", tz );
+    if (tz_exists)
+    {
+      // Note that if TZ does not exist, we don't want to set it.
+      // The absence of TZ causes the glib localtime function to
+      // use the local time as defined in /etc/localtime. But,
+      // an invalid TZ setting (such as the empty string) causes
+      // the localtime function to use UTC. So, the semantics of
+      // an unset TZ are not the same as the semantics of
+      // TZ=<empty string>.
+      setEnvStrVal ( childEnv, nextEnv, "TZ", tz );
+    }
     setEnvStrVal ( childEnv, nextEnv, "CLASSPATH", getenv("CLASSPATH"));
 
     if ( display )

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/dbc6c087/core/sql/executor/HBaseClient_JNI.cpp
----------------------------------------------------------------------
diff --git a/core/sql/executor/HBaseClient_JNI.cpp 
b/core/sql/executor/HBaseClient_JNI.cpp
index 32e2203..da43948 100644
--- a/core/sql/executor/HBaseClient_JNI.cpp
+++ b/core/sql/executor/HBaseClient_JNI.cpp
@@ -63,6 +63,7 @@ static const char* const hbcErrorEnumStr[] =
  ,"Java exception in getHBulkLoadClient()."
  ,"Preparing parameters for estimateRowCount()."
  ,"Java exception in estimateRowCount()."
+ ,"estimateRowCount() returned false."
  ,"Java exception in releaseHBulkLoadClient()."
  ,"Java exception in getBlockCacheFraction()."
  ,"Preparing parameters for getLatestSnapshot()."
@@ -1307,6 +1308,10 @@ HBC_RetCode HBaseClient_JNI::estimateRowCount(const 
char* tblName,
                                               Int64& rowCount,
                                               Int32& breadCrumb)
 {
+  // Note: Please use HBC_ERROR_ROWCOUNT_EST_EXCEPTION only for
+  // those error returns that call getExceptionDetails(). This
+  // tells the caller that Java exception information is available.
+
   QRLogger::log(CAT_SQL_HBASE, LL_DEBUG, 
"HBaseClient_JNI::estimateRowCount(%s) called.", tblName);
   breadCrumb = 1;
   if (jenv_ == NULL)
@@ -1356,9 +1361,9 @@ HBC_RetCode HBaseClient_JNI::estimateRowCount(const char* 
tblName,
   breadCrumb = 5;
   if (jresult == false)
   {
-    logError(CAT_SQL_HBASE, "HBaseClient_JNI::estimateRowCount()", 
getLastError());
+    logError(CAT_SQL_HBASE, "HBaseClient_JNI::estimateRowCount() returned 
false", getLastError());
     jenv_->PopLocalFrame(NULL);
-    return HBC_ERROR_ROWCOUNT_EST_EXCEPTION;
+    return HBC_ERROR_ROWCOUNT_EST_FALSE;
   }
 
   breadCrumb = 6;

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/dbc6c087/core/sql/executor/HBaseClient_JNI.h
----------------------------------------------------------------------
diff --git a/core/sql/executor/HBaseClient_JNI.h 
b/core/sql/executor/HBaseClient_JNI.h
index c15913e..735cd09 100644
--- a/core/sql/executor/HBaseClient_JNI.h
+++ b/core/sql/executor/HBaseClient_JNI.h
@@ -364,6 +364,7 @@ typedef enum {
  ,HBC_ERROR_GET_HBLC_EXCEPTION
  ,HBC_ERROR_ROWCOUNT_EST_PARAM
  ,HBC_ERROR_ROWCOUNT_EST_EXCEPTION
+ ,HBC_ERROR_ROWCOUNT_EST_FALSE
  ,HBC_ERROR_REL_HBLC_EXCEPTION
  ,HBC_ERROR_GET_CACHE_FRAC_EXCEPTION
  ,HBC_ERROR_GET_LATEST_SNP_PARAM

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/dbc6c087/core/sql/src/main/java/org/trafodion/sql/HBaseClient.java
----------------------------------------------------------------------
diff --git a/core/sql/src/main/java/org/trafodion/sql/HBaseClient.java 
b/core/sql/src/main/java/org/trafodion/sql/HBaseClient.java
index a6d26b5..d677991 100644
--- a/core/sql/src/main/java/org/trafodion/sql/HBaseClient.java
+++ b/core/sql/src/main/java/org/trafodion/sql/HBaseClient.java
@@ -1124,6 +1124,8 @@ public class HBaseClient {
               // ignore the interruption and keep going
             }  
             retryWait = 2 * retryWait;
+            if (retryWait > 30000)
+              retryWait = 30000;  // max out the retry wait at 30 seconds
           }
           else {
             // we've retried enough; just re-throw

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/dbc6c087/core/sql/ustat/hs_cli.cpp
----------------------------------------------------------------------
diff --git a/core/sql/ustat/hs_cli.cpp b/core/sql/ustat/hs_cli.cpp
index 5e693a8..ff16b86 100644
--- a/core/sql/ustat/hs_cli.cpp
+++ b/core/sql/ustat/hs_cli.cpp
@@ -499,12 +499,6 @@ Lng32 HSClearCLIDiagnostics()
   return retcode;
 }
 
-// Clear any JNI diagnostic text stored in the CLI
-void HSFuncClearJniErrorStr()
-{
-  GetCliGlobals()->currContext()->setJniErrorStr("");
-}
-
 // Obtain any JNI diagnostic text stored in the CLI
 const char * HSFuncGetJniErrorStr()
 {

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/dbc6c087/core/sql/ustat/hs_cli.h
----------------------------------------------------------------------
diff --git a/core/sql/ustat/hs_cli.h b/core/sql/ustat/hs_cli.h
index 97ce4ab..ffb55a9 100644
--- a/core/sql/ustat/hs_cli.h
+++ b/core/sql/ustat/hs_cli.h
@@ -129,9 +129,6 @@ Lng32 HSFuncExecDDL( const char *dml
                   );
 Lng32 HSClearCLIDiagnostics();
 
-// Clear any JNI diagnostic text stored in the CLI
-void HSFuncClearJniErrorStr();
-
 // Obtain any JNI diagnostic text stored in the CLI
 const char * HSFuncGetJniErrorStr();
 

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/dbc6c087/core/sql/ustat/hs_globals.cpp
----------------------------------------------------------------------
diff --git a/core/sql/ustat/hs_globals.cpp b/core/sql/ustat/hs_globals.cpp
index ca1255e..df0594c 100644
--- a/core/sql/ustat/hs_globals.cpp
+++ b/core/sql/ustat/hs_globals.cpp
@@ -72,6 +72,7 @@
 #include "PrivMgrComponentPrivileges.h"
 #include "PrivMgrCommands.h"
 #include "CmpDDLCatErrorCodes.h"
+#include "HBaseClient_JNI.h"  // to get HBC_ERROR_ROWCOUNT_EST_EXCEPTION
 
 #include <sys/stat.h>
 #include <sys/types.h>
@@ -3123,7 +3124,6 @@ Lng32 HSGlobalsClass::Initialize()
     LM->StartTimer("getRowCount()");
     Int32 errorCode = 0;
     Int32 breadCrumb = 0;
-    HSFuncClearJniErrorStr();   // clear out any stale error info 
     actualRowCount = objDef->getRowCount(currentRowCountIsEstimate_,
                                          inserts, deletes, updates,
                                          numPartitions,
@@ -3138,20 +3138,29 @@ Lng32 HSGlobalsClass::Initialize()
         LM->Log(LM->msg);
         sprintf(LM->msg, "\terrorCode=%d, breadCrumb=%d", errorCode, 
breadCrumb);
         LM->Log(LM->msg);
-        const char * jniErrorStr = HSFuncGetJniErrorStr();
-        if (strlen(jniErrorStr) > 0)
+        if (errorCode == HBC_ERROR_ROWCOUNT_EST_EXCEPTION)
           {
-            LM->Log("\tJNI exception info:");
-            LM->Log(jniErrorStr);
+            const char * jniErrorStr = HSFuncGetJniErrorStr();
+            if (strlen(jniErrorStr) > 0)
+              {
+                LM->Log("\tJNI exception info:");
+                LM->Log(jniErrorStr);
+              }
           }
       }
 
-    if (errorCode)
+    if (errorCode == HBC_ERROR_ROWCOUNT_EST_EXCEPTION)
       {
         *CmpCommon::diags() << DgSqlCode(-UERR_BAD_EST_ROWCOUNT) << 
DgInt0(errorCode) 
                             << DgInt1(breadCrumb) << 
DgString0(HSFuncGetJniErrorStr());
         return -1;
       }
+    else if (errorCode)
+      {
+        *CmpCommon::diags() << DgSqlCode(-UERR_BAD_EST_ROWCOUNT) << 
DgInt0(errorCode) 
+                            << DgInt1(breadCrumb) << DgString0("");
+        return -1;
+      }
 
     // We only allow an estimate when sampling, and then only if the
     // estimated row count is at least ustat_min_estimate_for_rowcount (CQD),

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/dbc6c087/core/sql/ustat/hs_log.cpp
----------------------------------------------------------------------
diff --git a/core/sql/ustat/hs_log.cpp b/core/sql/ustat/hs_log.cpp
index 776a316..f7584d0 100644
--- a/core/sql/ustat/hs_log.cpp
+++ b/core/sql/ustat/hs_log.cpp
@@ -285,9 +285,10 @@ void HSLogMan::Log(const char *data)
       {
         ofstream fileout(logFile_->data(), ios::app);
         time_t currentTime = time(0);
-        struct tm * currentTimeExploded = localtime(&currentTime);
+        struct tm currentTimeExploded;
+        localtime_r(&currentTime,&currentTimeExploded);
         char localTime[100];  // way more space than needed
-        strftime(localTime,sizeof(localTime),"%c",currentTimeExploded);
+        strftime(localTime,sizeof(localTime),"%c",&currentTimeExploded);
         fileout << "[" << localTime << "] " << data << endl;
       }
   }

Reply via email to