Repository: trafodion Updated Branches: refs/heads/master 9f4e549d0 -> dd301dc47
[TRAFODION-2853] memory leak of ComDiagsArea in CmpContext heap of mxosrvr The ComDiagsArea is allocated in many places and from different heaps in Trafodion, making it difficult to detect the source of the leak. Hence, a different approach is taken to fix this issue. Currently, ComDiagsArea is allocated in many places unconditionally even when SQL statement completes execution without any error or warnings. Then it is deallocated. Changed this strategy and allocate ComDiagsArea only when there is an error or warning while compiling or executing the SQL statement. This should help the product in two ways 1) To reduce the pathlength. The smaller query execution would benefit the most by chopping of few more microseconds. 2) Reduce the memory growth due to leaked ComDiagsArea Project: http://git-wip-us.apache.org/repos/asf/trafodion/repo Commit: http://git-wip-us.apache.org/repos/asf/trafodion/commit/b97982c4 Tree: http://git-wip-us.apache.org/repos/asf/trafodion/tree/b97982c4 Diff: http://git-wip-us.apache.org/repos/asf/trafodion/diff/b97982c4 Branch: refs/heads/master Commit: b97982c4494e078c5de2d883442d86265f24dadc Parents: c13cd58 Author: selvaganesang <[email protected]> Authored: Fri Mar 9 01:19:35 2018 +0000 Committer: selvaganesang <[email protected]> Committed: Sat Mar 10 01:45:40 2018 +0000 ---------------------------------------------------------------------- core/sql/arkcmp/CmpConnection.cpp | 4 +- core/sql/arkcmp/CmpContext.cpp | 14 +- core/sql/arkcmp/CmpContext.h | 2 +- core/sql/cli/Cli.cpp | 294 ++++++------------------- core/sql/cli/Context.cpp | 22 +- core/sql/cli/ExSqlComp.cpp | 21 +- core/sql/cli/Statement.cpp | 11 +- core/sql/executor/ExCancel.cpp | 9 +- core/sql/executor/ExExeUtilCli.cpp | 6 +- core/sql/executor/ExExeUtilCli.h | 2 +- core/sql/executor/ExExplain.cpp | 2 +- core/sql/executor/ExStats.cpp | 2 +- core/sql/executor/ex_control.cpp | 5 +- core/sql/executor/ex_ddl.cpp | 6 - core/sql/executor/ex_root.cpp | 28 +-- core/sql/export/ComDiags.h | 8 +- core/sql/optimizer/OptimizerSimulator.cpp | 2 +- core/sql/runtimestats/ssmpipc.cpp | 4 +- core/sql/runtimestats/ssmpipc.h | 2 +- core/sql/sqlci/Param.cpp | 8 +- core/sql/sqlci/Param.h | 2 +- core/sql/sqlci/SqlCmd.cpp | 106 +++++++-- core/sql/sqlci/SqlciCmd.cpp | 6 +- core/sql/sqlci/sqlcmd.h | 8 +- core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp | 18 +- 25 files changed, 261 insertions(+), 331 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/trafodion/blob/b97982c4/core/sql/arkcmp/CmpConnection.cpp ---------------------------------------------------------------------- diff --git a/core/sql/arkcmp/CmpConnection.cpp b/core/sql/arkcmp/CmpConnection.cpp index aa72355..67cd642 100644 --- a/core/sql/arkcmp/CmpConnection.cpp +++ b/core/sql/arkcmp/CmpConnection.cpp @@ -554,7 +554,9 @@ void ExCmpMessage::actOnReceive(IpcConnection* ) if (cmpStatement) { - *this << *cmpStatement->diags(); + ComDiagsArea *diags = cmpStatement->diags(); + if (diags->getNumber() > 0) + *this << *cmpStatement->diags(); if (cmpStatement->reply()) *this << *cmpStatement->reply(); } http://git-wip-us.apache.org/repos/asf/trafodion/blob/b97982c4/core/sql/arkcmp/CmpContext.cpp ---------------------------------------------------------------------- diff --git a/core/sql/arkcmp/CmpContext.cpp b/core/sql/arkcmp/CmpContext.cpp index f824e1e..5734b77 100644 --- a/core/sql/arkcmp/CmpContext.cpp +++ b/core/sql/arkcmp/CmpContext.cpp @@ -763,7 +763,7 @@ CmpContext::compileDirect(char *data, UInt32 data_len, CollHeap *outHeap, char *&gen_code, UInt32 &gen_code_len, UInt32 parserFlags, const char *parentQid, Int32 parentQidLen, - ComDiagsArea *diagsArea) + ComDiagsArea *&diagsArea) { CmpStatement::ReturnStatus rs = CmpStatement::CmpStatement_SUCCESS; @@ -1081,10 +1081,14 @@ CmpContext::compileDirect(char *data, UInt32 data_len, CollHeap *outHeap, } } - // get any errors or warnings from compilation out before distroy it - if (diagsArea) - diagsArea->mergeAfter(*CmpCommon::diags()); - + ComDiagsArea *compileDiagsArea = CmpCommon::diags(); + if (compileDiagsArea->getNumber() > 0) + { + // get any errors or warnings from compilation out before distroy it + if (diagsArea == NULL) + diagsArea = ComDiagsArea::allocate(outHeap); + diagsArea->mergeAfter(*compileDiagsArea); + } // cleanup and return if (cmpStatement && cmpStatement->readyToDie()) delete cmpStatement; http://git-wip-us.apache.org/repos/asf/trafodion/blob/b97982c4/core/sql/arkcmp/CmpContext.h ---------------------------------------------------------------------- diff --git a/core/sql/arkcmp/CmpContext.h b/core/sql/arkcmp/CmpContext.h index 5df2eca..eceb9c1 100644 --- a/core/sql/arkcmp/CmpContext.h +++ b/core/sql/arkcmp/CmpContext.h @@ -381,7 +381,7 @@ public : CmpMessageObj::MessageTypeEnum op, char *&gen_code, UInt32 &gen_code_len, UInt32 parserFlags, const char *parentQid, Int32 parentQidLen, - ComDiagsArea *diagsArea = NULL); + ComDiagsArea *&diagsArea); // set/reset an env in compiler envs void setArkcmpEnvDirect(const char *name, const char *value, http://git-wip-us.apache.org/repos/asf/trafodion/blob/b97982c4/core/sql/cli/Cli.cpp ---------------------------------------------------------------------- diff --git a/core/sql/cli/Cli.cpp b/core/sql/cli/Cli.cpp index 41e9bf7..d157eda 100644 --- a/core/sql/cli/Cli.cpp +++ b/core/sql/cli/Cli.cpp @@ -8314,7 +8314,7 @@ Lng32 SQLCLI_LOBcliInterface ContextCli & currContext = *(cliGlobals->currContext()); ComDiagsArea & diags = currContext.diags(); - ComDiagsArea * myDiags = ComDiagsArea::allocate(currContext.exHeap()); + ComDiagsArea * myDiags = NULL; ExeCliInterface *cliInterface = NULL; if (inCliInterface && (*inCliInterface)) @@ -8413,11 +8413,7 @@ Lng32 SQLCLI_LOBcliInterface cliRC = cliInterface->executeImmediate(query); if (cliRC < 0) - { - cliInterface->retrieveSQLDiagnostics(myDiags); - goto error_return; - } cliRC = 0; } @@ -8439,12 +8435,7 @@ Lng32 SQLCLI_LOBcliInterface currContext.resetSqlParserFlags(0x1); if (cliRC < 0) - { - - cliInterface->retrieveSQLDiagnostics(myDiags); - goto error_return; - } // create lob descriptor chunks table salted str_sprintf(query, "create ghost table %s (descPartnKey largeint not null, descSysKey largeint not null, chunkNum int not null, chunkLen largeint not null, dataOffset largeint, stringParam varchar(400), primary key(descPartnKey, descSysKey, chunkNum)) salt using 8 partitions", @@ -8459,13 +8450,7 @@ Lng32 SQLCLI_LOBcliInterface currContext.resetSqlParserFlags(0x1); if (cliRC < 0) - { - - cliInterface->retrieveSQLDiagnostics(myDiags); - goto error_return; - } - cliRC = 0; } break; @@ -8483,11 +8468,7 @@ Lng32 SQLCLI_LOBcliInterface currContext.resetSqlParserFlags(0x1); if (cliRC < 0) - { - cliInterface->retrieveSQLDiagnostics(myDiags); - goto error_return; - } str_sprintf(query, "drop ghost table %s", lobDescChunksName); @@ -8501,14 +8482,7 @@ Lng32 SQLCLI_LOBcliInterface if (cliRC < 0) - { - cliInterface->retrieveSQLDiagnostics(myDiags); - goto error_return; - } - - - cliRC = 0; } break; @@ -8526,10 +8500,7 @@ Lng32 SQLCLI_LOBcliInterface currContext.resetSqlParserFlags(0x1); if (cliRC < 0) - { - cliInterface->retrieveSQLDiagnostics(myDiags); goto error_return; - } str_sprintf(query, "cleanup table %s", lobDescChunksName); @@ -8542,10 +8513,7 @@ Lng32 SQLCLI_LOBcliInterface currContext.resetSqlParserFlags(0x1); if (cliRC < 0) - { - cliInterface->retrieveSQLDiagnostics(myDiags); goto error_return; - } cliRC = 0; } break; @@ -8567,10 +8535,7 @@ Lng32 SQLCLI_LOBcliInterface currContext.resetSqlParserFlags(0x1); if (cliRC < 0) - { - cliInterface->retrieveSQLDiagnostics(myDiags); goto error_return; - } // insert into lob descriptor chunks table @@ -8601,11 +8566,7 @@ Lng32 SQLCLI_LOBcliInterface currContext.resetSqlParserFlags(0x1); if (cliRC < 0) - { - cliInterface->retrieveSQLDiagnostics(myDiags); - - goto error_return; - } + goto error_return; if (inoutDescPartnKey) *inoutDescPartnKey = descPartnKey; @@ -8650,11 +8611,7 @@ Lng32 SQLCLI_LOBcliInterface currContext.resetSqlParserFlags(0x1); if (cliRC < 0) - { - cliInterface->retrieveSQLDiagnostics(myDiags); - goto error_return; - } str_sprintf(query, "select numChunks from table(ghost table %s) h where h.descPartnKey = %ld and h.syskey = %ld for read committed access", lobDescHandleName, @@ -8670,11 +8627,7 @@ Lng32 SQLCLI_LOBcliInterface currContext.resetSqlParserFlags(0x1); if (cliRC < 0) - { - cliInterface->retrieveSQLDiagnostics(myDiags); - goto error_return; - } // insert into lob descriptor chunks table if (blackBox && (blackBoxLen && (*blackBoxLen > 0))) @@ -8704,11 +8657,7 @@ Lng32 SQLCLI_LOBcliInterface currContext.resetSqlParserFlags(0x1); if (cliRC < 0) - { - cliInterface->retrieveSQLDiagnostics(myDiags); - goto error_return; - } if (inoutDescPartnKey) *inoutDescPartnKey = descPartnKey; @@ -8741,11 +8690,7 @@ Lng32 SQLCLI_LOBcliInterface currContext.resetSqlParserFlags(0x1); if (cliRC < 0) - { - cliInterface->retrieveSQLDiagnostics(myDiags); - goto error_return; - } @@ -8761,11 +8706,7 @@ Lng32 SQLCLI_LOBcliInterface currContext.resetSqlParserFlags(0x1); if (cliRC < 0) - { - cliInterface->retrieveSQLDiagnostics(myDiags); - goto error_return; - } if ((lobType != Lob_External_HDFS_File) && blackBox) { @@ -8801,11 +8742,7 @@ Lng32 SQLCLI_LOBcliInterface currContext.resetSqlParserFlags(0x1); if (cliRC < 0) - { - cliInterface->retrieveSQLDiagnostics(myDiags); - - goto error_return; - } + goto error_return; // update lob handle with the returned values if (outLobHandle) @@ -8839,11 +8776,7 @@ Lng32 SQLCLI_LOBcliInterface currContext.resetSqlParserFlags(0x1); if (cliRC < 0) - { - cliInterface->retrieveSQLDiagnostics(myDiags); - - goto error_return; - } + goto error_return; // delete from lob descriptor chunks table str_sprintf(query, "delete from table(ghost table %s) where descPartnKey = %ld and descSysKey = %ld", @@ -8857,11 +8790,7 @@ Lng32 SQLCLI_LOBcliInterface currContext.resetSqlParserFlags(0x1); if (cliRC < 0) - { - cliInterface->retrieveSQLDiagnostics(myDiags); - goto error_return; - } } break; @@ -8882,16 +8811,11 @@ Lng32 SQLCLI_LOBcliInterface currContext.resetSqlParserFlags(0x1); if (cliRC < 0) - { - cliInterface->retrieveSQLDiagnostics(myDiags); - goto error_return; - } + cliRC = cliInterface->fetch(); if (cliRC < 0) { - cliInterface->retrieveSQLDiagnostics(myDiags); - cliInterface->fetchRowsEpilogue(0); goto error_return; } @@ -8922,10 +8846,7 @@ Lng32 SQLCLI_LOBcliInterface { cliRC = cliInterface->fetchRowsEpilogue(0); if (cliRC < 0) - { - cliInterface->retrieveSQLDiagnostics(myDiags); goto error_return; - } } // This lob has only one chunk. Read and return the single descriptor. @@ -8943,16 +8864,11 @@ Lng32 SQLCLI_LOBcliInterface currContext.resetSqlParserFlags(0x1); if (cliRC < 0) - { - cliInterface->retrieveSQLDiagnostics(myDiags); - goto error_return; - } cliRC = cliInterface->fetch(); if (cliRC < 0) { - cliInterface->retrieveSQLDiagnostics(myDiags); cliInterface->fetchRowsEpilogue(0); @@ -9007,11 +8923,7 @@ Lng32 SQLCLI_LOBcliInterface cliRC = cliInterface->fetchRowsEpilogue(0); if (cliRC < 0) - { - cliInterface->retrieveSQLDiagnostics(myDiags); - goto error_return; - } cliRC = saveCliErr; } @@ -9030,11 +8942,7 @@ Lng32 SQLCLI_LOBcliInterface currContext.resetSqlParserFlags(0x1); if (cliRC < 0) - { - cliInterface->retrieveSQLDiagnostics(myDiags); - goto error_return; - } if (inCliInterface) *inCliInterface = cliInterface; @@ -9046,8 +8954,6 @@ Lng32 SQLCLI_LOBcliInterface cliRC = cliInterface->fetch(); if (cliRC < 0) { - cliInterface->retrieveSQLDiagnostics(myDiags); - cliInterface->fetchRowsEpilogue(0); if (inCliInterface) @@ -9093,7 +8999,6 @@ Lng32 SQLCLI_LOBcliInterface cliRC = cliInterface->fetchRowsEpilogue(0); if (cliRC < 0) { - cliInterface->retrieveSQLDiagnostics(myDiags); if (inCliInterface) *inCliInterface = NULL; @@ -9121,11 +9026,7 @@ Lng32 SQLCLI_LOBcliInterface currContext.resetSqlParserFlags(0x1); if (cliRC < 0) - { - cliInterface->retrieveSQLDiagnostics(myDiags); - goto error_return; - } // delete data from the chunks desc table str_sprintf(query, "delete from table(ghost table %s)", @@ -9139,11 +9040,7 @@ Lng32 SQLCLI_LOBcliInterface currContext.resetSqlParserFlags(0x1); if (cliRC < 0) - { - cliInterface->retrieveSQLDiagnostics(myDiags); - - goto error_return; - } + goto error_return; } break; @@ -9208,11 +9105,7 @@ Lng32 SQLCLI_LOBcliInterface if (cliRC < 0) - { - cliInterface->retrieveSQLDiagnostics(myDiags); - goto error_return; - } cliRC = saveCliErr; } @@ -9241,20 +9134,19 @@ Lng32 SQLCLI_LOBcliInterface NADELETEBASIC(query, currContext.exHeap()); + if (cliRC < 0) + { + if (myDiags == NULL) + myDiags = ComDiagsArea::allocate(currContext.exHeap()); + cliInterface->retrieveSQLDiagnostics(myDiags); + diags.mergeAfter(*myDiags); + myDiags->decrRefCount(); + } if (NOT (inCliInterface && (*inCliInterface))) { delete cliInterface; cliInterface = NULL; } - - if (cliRC < 0) - { - if (myDiags->getNumber() > 0) - { - diags.mergeAfter(*myDiags); - } - } - myDiags->deAllocate(); if (cliRC < 0) return cliRC; else if (cliRC == 100) @@ -9297,7 +9189,7 @@ Lng32 SQLCLI_LOB_GC_Interface ContextCli & currContext = *(cliGlobals->currContext()); ComDiagsArea & diags = currContext.diags(); - ComDiagsArea * myDiags = ComDiagsArea::allocate(currContext.exHeap()); + ComDiagsArea * myDiags = NULL; ExeCliInterface *cliInterface = NULL; cliInterface = new (currContext.exHeap()) @@ -9360,11 +9252,7 @@ Lng32 SQLCLI_LOB_GC_Interface currContext.resetSqlParserFlags(0x1); if (cliRC < 0) - { - cliInterface->retrieveSQLDiagnostics(myDiags); - goto error_return; - } { //Allocate an inmemory array of numEntries. ExLobInMemoryDescChunksEntry *dcInMemoryArray = new ExLobInMemoryDescChunksEntry[numEntries]; @@ -9381,18 +9269,11 @@ Lng32 SQLCLI_LOB_GC_Interface currContext.resetSqlParserFlags(0x1); if (cliRC < 0) - { - cliInterface->retrieveSQLDiagnostics(myDiags); - goto error_return; - } cliRC = cliInterface->fetch(); if (cliRC < 0) { - cliInterface->retrieveSQLDiagnostics(myDiags); - cliInterface->fetchRowsEpilogue(0); - goto error_return; } @@ -9436,21 +9317,14 @@ Lng32 SQLCLI_LOB_GC_Interface i++; if (cliRC < 0) { - cliInterface->retrieveSQLDiagnostics(myDiags); - cliInterface->fetchRowsEpilogue(0); - goto error_return; } } cliRC = cliInterface->fetchRowsEpilogue(0); if (cliRC < 0) - { - cliInterface->retrieveSQLDiagnostics(myDiags); - goto error_return; - } // adjust in memory array to calculate holes and new offsets. ExpLOBoper::calculateNewOffsets(dcInMemoryArray,numEntries); @@ -9486,8 +9360,6 @@ Lng32 SQLCLI_LOB_GC_Interface if (cliRC < 0) { - cliInterface->retrieveSQLDiagnostics(myDiags); - //tbd Give warning and rollback just these updates and return with warning. For now return error and abort the iud operation itself since there is no support for nested transactions or SUSPEND and RESUME. goto error_return; } @@ -9539,12 +9411,12 @@ Lng32 SQLCLI_LOB_GC_Interface if (cliRC < 0) { - if (myDiags->getNumber() > 0) - { - diags.mergeAfter(*myDiags); - } + if (myDiags == NULL) + myDiags = ComDiagsArea::allocate(currContext.exHeap()); + diags.mergeAfter(*myDiags); + myDiags->decrRefCount(); + } - myDiags->deAllocate(); if (cliRC < 0) return cliRC; else if (cliRC == 100) @@ -9577,7 +9449,8 @@ Lng32 SQLCLI_LOBddlInterface ContextCli & currContext = *(cliGlobals->currContext()); ComDiagsArea & diags = currContext.diags(); - ComDiagsArea * myDiags = ComDiagsArea::allocate(currContext.exHeap()); + ComDiagsArea * myDiags = NULL; + char logBuf[4096]; lobDebugInfo("In LOBddlInterface",0,__LINE__,lobTrace); ExeCliInterface *cliInterface = NULL; @@ -9612,11 +9485,7 @@ Lng32 SQLCLI_LOBddlInterface currContext.resetSqlParserFlags(0x1); if (cliRC < 0) - { - cliInterface->retrieveSQLDiagnostics(myDiags); - goto error_return; - } // populate the lob metadata table for (Lng32 i = 0; i < numLOBs; i++) @@ -9634,11 +9503,7 @@ Lng32 SQLCLI_LOBddlInterface currContext.resetSqlParserFlags(0x1); if (cliRC < 0) - { - cliInterface->retrieveSQLDiagnostics(myDiags); - - goto error_return; - } + goto error_return; } // for @@ -9654,7 +9519,7 @@ Lng32 SQLCLI_LOBddlInterface &rc, NULL, (char*)"ExpLOBInterfaceCreate", getLobErrStr(rc)); - goto error_return; + goto non_cli_error_return; } for (Lng32 i = 0; i < numLOBs; i++) @@ -9674,7 +9539,7 @@ Lng32 SQLCLI_LOBddlInterface &rc, NULL, (char*)"ExpLOBInterfaceCreate", getLobErrStr(rc)); - goto error_return; + goto non_cli_error_return; } // create LOB descriptor and LOB header tables @@ -9701,11 +9566,7 @@ Lng32 SQLCLI_LOBddlInterface NULL, 0,lobTrace); if (cliRC < 0) - { - cliInterface->retrieveSQLDiagnostics(myDiags); - - goto error_return; - } + goto error_return; } // for @@ -9726,11 +9587,7 @@ Lng32 SQLCLI_LOBddlInterface currContext.resetSqlParserFlags(0x1); if (cliRC < 0) - { - cliInterface->retrieveSQLDiagnostics(&diags); - - goto error_return; - } + goto error_return; // drop descriptor table for (Lng32 i = 0; i < numLOBs; i++) @@ -9760,11 +9617,7 @@ Lng32 SQLCLI_LOBddlInterface NULL, 0,lobTrace); if (cliRC < 0) - { - cliInterface->retrieveSQLDiagnostics(myDiags); - goto error_return; - } } // for //If all the descriptor tables got dropped correctly, drop the hdfs @@ -9782,7 +9635,7 @@ Lng32 SQLCLI_LOBddlInterface (ExeErrorCode)(8442), NULL, &cliRC , &rc, NULL, (char*)"ExpLOBInterfaceCreate", getLobErrStr(rc)); - goto error_return; + goto non_cli_error_return; } for (Lng32 i = 0; i < numLOBs; i++) @@ -9800,8 +9653,8 @@ Lng32 SQLCLI_LOBddlInterface (ExeErrorCode)(8442), NULL, &cliRC , &rc, NULL, (char*)"ExpLOBInterfaceDrop ", getLobErrStr(rc)); - goto error_return; - } + goto non_cli_error_return; + } }//for } break; @@ -9819,11 +9672,8 @@ Lng32 SQLCLI_LOBddlInterface currContext.resetSqlParserFlags(0x1); if (cliRC < 0) - { - cliInterface->retrieveSQLDiagnostics(&diags); - - goto error_return; - } + goto error_return; + //Initialize LOB interface Int32 rc= ExpLOBoper::initLOBglobal(exLobGlob,currContext.exHeap(),&currContext,hdfsServer,hdfsPort); @@ -9835,7 +9685,7 @@ Lng32 SQLCLI_LOBddlInterface (ExeErrorCode)(8442), NULL, &cliRC , &rc, NULL, (char*)"ExpLOBInterfaceCreate", getLobErrStr(rc)); - goto error_return; + goto non_cli_error_return; } // drop descriptor table for (Lng32 i = 0; i < numLOBs; i++) @@ -9853,7 +9703,7 @@ Lng32 SQLCLI_LOBddlInterface (ExeErrorCode)(8442), NULL, &cliRC , &rc, NULL, (char*)"ExpLOBInterfaceDrop ", getLobErrStr(rc)); - goto error_return; + goto non_cli_error_return; } // drop LOB descriptor and LOB header tables @@ -9880,11 +9730,7 @@ Lng32 SQLCLI_LOBddlInterface NULL, 0,lobTrace); if (cliRC < 0) - { - cliInterface->retrieveSQLDiagnostics(myDiags); - goto error_return; - } } // for @@ -9911,11 +9757,7 @@ Lng32 SQLCLI_LOBddlInterface currContext.resetSqlParserFlags(0x1); if (cliRC < 0) - { - cliInterface->retrieveSQLDiagnostics(myDiags); - goto error_return; - } cliRC = 0; Lng32 j = 0; @@ -9925,7 +9767,6 @@ Lng32 SQLCLI_LOBddlInterface cliRC = cliInterface->fetch(); if (cliRC < 0) { - cliInterface->retrieveSQLDiagnostics(myDiags); cliInterface->fetchRowsEpilogue(0); @@ -9971,7 +9812,6 @@ Lng32 SQLCLI_LOBddlInterface if (ccliRC < 0) { cliRC = ccliRC; - cliInterface->retrieveSQLDiagnostics(myDiags); goto error_return; } } @@ -9990,19 +9830,19 @@ Lng32 SQLCLI_LOBddlInterface } // switch error_return: + if (cliRC < 0) + { + if (myDiags == NULL) + myDiags = ComDiagsArea::allocate(currContext.exHeap()); + cliInterface->retrieveSQLDiagnostics(myDiags); + diags.mergeAfter(*myDiags); + myDiags->decrRefCount(); + } + non_cli_error_return: ExpLOBinterfaceCleanup(exLobGlob); NADELETEBASIC(query, currContext.exHeap()); NADELETEBASIC(hdfsServer,currContext.exHeap()); delete cliInterface; - - if (cliRC < 0) - { - if (myDiags->getNumber() > 0) - { - diags.mergeAfter(*myDiags); - } - } - myDiags->deAllocate(); if (cliRC < 0) return cliRC; else if (cliRC == 100) @@ -10358,7 +10198,6 @@ static Lng32 SeqGenCliInterfacePrepQry( const char * qryName, ExeCliInterface ** cliInterfaceArr, SequenceGeneratorAttributes* sga, - ComDiagsArea * myDiags, ContextCli &currContext, ComDiagsArea & diags, NAHeap *exHeap) @@ -10370,6 +10209,8 @@ static Lng32 SeqGenCliInterfacePrepQry( Int64 rowsAffected = 0; + ComDiagsArea *myDiags = NULL; + ExeCliInterface * cliInterface = NULL; ExeCliInterface * cqdCliInterface = NULL; @@ -10406,9 +10247,11 @@ static Lng32 SeqGenCliInterfacePrepQry( cliRC = cqdCliInterface->holdAndSetCQD("limit_max_numeric_precision", "ON"); if (cliRC < 0) { + if (myDiags == NULL) + myDiags = ComDiagsArea::allocate(exHeap); cqdCliInterface->retrieveSQLDiagnostics(myDiags); diags.mergeAfter(*myDiags); - + myDiags->decrRefCount(); return cliRC; } @@ -10418,11 +10261,12 @@ static Lng32 SeqGenCliInterfacePrepQry( stmtName); if (cliRC < 0) { + if (myDiags == NULL) + myDiags = ComDiagsArea::allocate(exHeap); cliInterface->retrieveSQLDiagnostics(myDiags); diags.mergeAfter(*myDiags); - + myDiags->decrRefCount(); cqdCliInterface->restoreCQD("limit_max_numeric_precision"); - return cliRC; } @@ -10438,7 +10282,6 @@ static Lng32 SeqGenCliInterfaceUpdAndValidate( SequenceGeneratorAttributes* sga, NABoolean recycleQry, NABoolean startLocalXn, - ComDiagsArea * myDiags, ContextCli &currContext, ComDiagsArea & diags, NAHeap *exHeap, @@ -10456,6 +10299,8 @@ static Lng32 SeqGenCliInterfaceUpdAndValidate( Int64 rowsAffected = 0; ExeCliInterface * cliInterface = NULL; + + ComDiagsArea *myDiags = NULL; char queryBuf[2000]; @@ -10469,7 +10314,7 @@ static Lng32 SeqGenCliInterfaceUpdAndValidate( "update %s.\"%s\".%s set upd_ts = cast(? as largeint not null) where seq_uid = %ld", SEQ_UPD_TS_QRY_IDX, "SEQ_UPD_TS_QRY_IDX", - cliInterfaceArr, sga, myDiags, currContext, diags, exHeap); + cliInterfaceArr, sga, currContext, diags, exHeap); if (cliRC < 0) return cliRC; } @@ -10487,9 +10332,11 @@ static Lng32 SeqGenCliInterfaceUpdAndValidate( ((char*)inputValues, inputValuesLen, NULL, NULL, &rowsAffected); if (cliRC < 0) { + if (myDiags == NULL) + myDiags = ComDiagsArea::allocate(exHeap); cliInterface->retrieveSQLDiagnostics(myDiags); diags.mergeAfter(*myDiags); - + myDiags->decrRefCount(); return cliRC; } @@ -10510,7 +10357,7 @@ static Lng32 SeqGenCliInterfaceUpdAndValidate( "select case when cast(? as largeint not null) = 1 then t.startVal else t.nextValue end, t.redefTS from (update %s.\"%s\".%s set next_value = (case when cast(? as largeint not null) = 1 then start_value + cast(? as largeint not null) else (case when next_value + cast(? as largeint not null) > max_value then max_value+1 else next_value + cast(? as largeint not null) end) end), num_calls = num_calls + 1 where seq_uid = %ld return old.start_value, old.next_value, old.redef_ts) t(startVal, nextValue, redefTS);", SEQ_PROCESS_QRY_IDX, "SEQ_PROCESS_QRY_IDX", - cliInterfaceArr, sga, myDiags, currContext, diags, exHeap); + cliInterfaceArr, sga, currContext, diags, exHeap); if (cliRC < 0) return cliRC; } @@ -10532,9 +10379,11 @@ static Lng32 SeqGenCliInterfaceUpdAndValidate( &rowsAffected); if (cliRC < 0) { + if (myDiags == NULL) + myDiags = ComDiagsArea::allocate(exHeap); cliInterface->retrieveSQLDiagnostics(myDiags); diags.mergeAfter(*myDiags); - + myDiags->decrRefCount(); if (diags.mainSQLCODE() == -EXE_NUMERIC_OVERFLOW) { cliRC = -EXE_SG_MAXVALUE_EXCEEDED; @@ -10575,7 +10424,7 @@ static Lng32 SeqGenCliInterfaceUpdAndValidate( "select upd_ts from %s.\"%s\".%s where seq_uid = %ld", SEQ_SEL_TS_QRY_IDX, "SEQ_SEL_TS_QRY_IDX", - cliInterfaceArr, sga, myDiags, currContext, diags, exHeap); + cliInterfaceArr, sga, currContext, diags, exHeap); if (cliRC < 0) return cliRC; } @@ -10585,9 +10434,11 @@ static Lng32 SeqGenCliInterfaceUpdAndValidate( (NULL, 0, (char*)outputValues, &outputValuesLen, &rowsAffected); if (cliRC < 0) { + if (myDiags == NULL) + myDiags = ComDiagsArea::allocate(exHeap); cliInterface->retrieveSQLDiagnostics(myDiags); diags.mergeAfter(*myDiags); - + myDiags->decrRefCount(); return cliRC; } @@ -10620,7 +10471,6 @@ static Lng32 SeqGenCliInterfaceUpdAndValidateMulti( ExeCliInterface ** cliInterfaceArr, SequenceGeneratorAttributes* sga, NABoolean recycleQry, - ComDiagsArea * myDiags, ContextCli &currContext, ComDiagsArea & diags, NAHeap *exHeap, @@ -10629,6 +10479,7 @@ static Lng32 SeqGenCliInterfaceUpdAndValidateMulti( { Lng32 cliRC = 0; Lng32 retCliRC = 0; + ComDiagsArea *myDiags = NULL; if (! cliInterfaceArr[SEQ_CQD_IDX]) cliInterfaceArr[SEQ_CQD_IDX] = new (currContext.exHeap()) @@ -10661,9 +10512,11 @@ static Lng32 SeqGenCliInterfaceUpdAndValidateMulti( cliRC = cqdCliInterface->beginWork(); if (cliRC < 0) { + if (myDiags != NULL) + myDiags = ComDiagsArea::allocate(exHeap); cqdCliInterface->retrieveSQLDiagnostics(myDiags); diags.mergeAfter(*myDiags); - + myDiags->decrRefCount(); retCliRC = cliRC; goto label_return; } @@ -10674,7 +10527,6 @@ static Lng32 SeqGenCliInterfaceUpdAndValidateMulti( sga, recycleQry, startLocalXn, - myDiags, currContext, diags, exHeap, @@ -10753,8 +10605,6 @@ Lng32 SQLCLI_SeqGenCliInterface ContextCli & currContext = *(cliGlobals->currContext()); ComDiagsArea & diags = currContext.diags(); - ComDiagsArea * myDiags = ComDiagsArea::allocate(currContext.exHeap()); - ExeCliInterface ** cliInterfaceArr = NULL; if (inCliInterfaceArr && (*inCliInterfaceArr)) { @@ -10782,14 +10632,12 @@ Lng32 SQLCLI_SeqGenCliInterface cliInterfaceArr, sga, FALSE, - myDiags, currContext, diags, currContext.exHeap(), nextValue, endValue); if (cliRC < 0) { - myDiags->deAllocate(); return cliRC; } @@ -10800,19 +10648,15 @@ Lng32 SQLCLI_SeqGenCliInterface cliInterfaceArr, sga, TRUE, - myDiags, currContext, diags, currContext.exHeap(), nextValue, endValue); if (cliRC < 0) { - myDiags->deAllocate(); return cliRC; } } - - myDiags->deAllocate(); sga->setSGNextValue(nextValue); sga->setSGEndValue(endValue); http://git-wip-us.apache.org/repos/asf/trafodion/blob/b97982c4/core/sql/cli/Context.cpp ---------------------------------------------------------------------- diff --git a/core/sql/cli/Context.cpp b/core/sql/cli/Context.cpp index cdf5909..5f369f8 100644 --- a/core/sql/cli/Context.cpp +++ b/core/sql/cli/Context.cpp @@ -2525,11 +2525,12 @@ void ContextCli::createMxcmpSession() { char *dummyReply = NULL; ULng32 dummyLen; + ComDiagsArea *diagsArea = NULL; cmpStatus = CmpCommon::context()->compileDirect(pMessage, (ULng32) sizeof(userMessage), &exHeap_, SQLCHARSETCODE_UTF8, EXSQLCOMP::DATABASE_USER, dummyReply, dummyLen, getSqlParserFlags(), - NULL, 0); + NULL, 0, diagsArea); if (cmpStatus != 0) { char emsText[120]; @@ -2544,6 +2545,11 @@ void ContextCli::createMxcmpSession() exHeap_.deallocateMemory((void*)dummyReply); dummyReply = NULL; } + if (diagsArea != NULL) + { + diagsArea->decrRefCount(); + diagsArea = NULL; + } } // if there is an error using embedded compiler or we are already in the @@ -2725,11 +2731,12 @@ void ContextCli::endMxcmpSession(NABoolean cleanupEsps, { char *dummyReply = NULL; ULng32 dummyLen; + ComDiagsArea *diagsArea = NULL; cmpStatus = CmpCommon::context()->compileDirect((char *) &flags, (ULng32) sizeof(Lng32), &exHeap_, SQLCHARSETCODE_UTF8, EXSQLCOMP::END_SESSION, dummyReply, dummyLen, getSqlParserFlags(), - NULL, 0); + NULL, 0, diagsArea); if (cmpStatus != 0) { char emsText[120]; @@ -2744,6 +2751,11 @@ void ContextCli::endMxcmpSession(NABoolean cleanupEsps, exHeap_.deallocateMemory((void*)dummyReply); dummyReply = NULL; } + if (diagsArea != NULL) + { + diagsArea->decrRefCount(); + diagsArea = NULL; + } } // if there is an error using embedded compiler or we are already in the @@ -3033,7 +3045,7 @@ ExSqlComp::ReturnStatus ContextCli::sendXnMsgToArkcmp CmpMessageObj::MessageTypeEnum(xnMsgType), dummyReply, dummyLength, currCtxt->getSqlParserFlags(), - NULL, 0); + NULL, 0, diagsArea); if (cmpRet != 0) { char emsText[120]; @@ -3116,7 +3128,7 @@ Lng32 ContextCli::setSecInvalidKeys( ComDiagsArea *tempDiagsArea = &diagsArea_; tempDiagsArea->clear(); - IpcServer *ssmpServer = ssmpManager_->getSsmpServer( + IpcServer *ssmpServer = ssmpManager_->getSsmpServer(exHeap(), cliGlobals->myNodeName(), cliGlobals->myCpu(), tempDiagsArea); if (ssmpServer == NULL) @@ -3284,7 +3296,7 @@ ExStatisticsArea *ContextCli::getMergedStats( } ComDiagsArea *tempDiagsArea = &diagsArea_; ExSsmpManager *ssmpManager = cliGlobals->getSsmpManager(); - IpcServer *ssmpServer = ssmpManager->getSsmpServer(nodeName, + IpcServer *ssmpServer = ssmpManager->getSsmpServer(exHeap(), nodeName, (cpu == -1 ? cliGlobals->myCpu() : cpu), tempDiagsArea); if (ssmpServer == NULL) return NULL; // diags are in diagsArea_ http://git-wip-us.apache.org/repos/asf/trafodion/blob/b97982c4/core/sql/cli/ExSqlComp.cpp ---------------------------------------------------------------------- diff --git a/core/sql/cli/ExSqlComp.cpp b/core/sql/cli/ExSqlComp.cpp index 3a514b0..01f8396 100644 --- a/core/sql/cli/ExSqlComp.cpp +++ b/core/sql/cli/ExSqlComp.cpp @@ -634,7 +634,7 @@ ExSqlComp::ReturnStatus ExSqlComp::resendControls(NABoolean ctxSw) // Genesis (ULng32) sizeof(userMessage)); } - ComDiagsArea loopDiags(h_); + ComDiagsArea *loopDiags = NULL; ExControlArea *ca = ctxt->getControlArea(); Queue *q = ca->getControlList(); @@ -797,10 +797,14 @@ ExSqlComp::ReturnStatus ExSqlComp::resendControls(NABoolean ctxSw) // Genesis } else { - loopDiags.mergeAfter(*diagArea_); - diagArea_->clear(); + if (diagArea_->getNumber() > 0) + { + if (loopDiags == NULL) + loopDiags = ComDiagsArea::allocate(h_); + loopDiags->mergeAfter(*diagArea_); + diagArea_->clear(); + } } - ret = SUCCESS; } else @@ -834,10 +838,13 @@ ExSqlComp::ReturnStatus ExSqlComp::resendControls(NABoolean ctxSw) // Genesis } // control list is NOT empty } // if (ret != ERROR) // - if (ret != SUCCESS || diagArea_->getNumber() || loopDiags.getNumber()) + if (ret != SUCCESS || diagArea_->getNumber() || loopDiags != NULL ) { - diagArea_->mergeAfter(loopDiags); - loopDiags.clear(); + if (loopDiags != NULL) + { + diagArea_->mergeAfter(*loopDiags); + loopDiags->decrRefCount(); + } if (ret != ERROR) ret = diagArea_->getNumber(DgSqlCode::ERROR_) ? ERROR : WARNING; if (ret == ERROR) http://git-wip-us.apache.org/repos/asf/trafodion/blob/b97982c4/core/sql/cli/Statement.cpp ---------------------------------------------------------------------- diff --git a/core/sql/cli/Statement.cpp b/core/sql/cli/Statement.cpp index 09f4118..1aeb708 100644 --- a/core/sql/cli/Statement.cpp +++ b/core/sql/cli/Statement.cpp @@ -1687,7 +1687,7 @@ RETCODE Statement::prepare2(char *source, ComDiagsArea &diagsArea, //!aqRetry && cliGlobals_->isEmbeddedArkcmpInitialized()) { Int32 compStatus; - ComDiagsArea *da = ComDiagsArea::allocate(&heap_); + ComDiagsArea *da = NULL; // clean up diags area of regular arkcmp, it could contain // old errors from last use @@ -1698,14 +1698,17 @@ RETCODE Statement::prepare2(char *source, ComDiagsArea &diagsArea, compStatus = CmpCommon::context()->compileDirect( (char *)data, dataLen, // use arkcmp heap to store the plan + // check why indexIntoCompilerArray is used here? cliGlobals_->getArkcmp(indexIntoCompilerArray)->getHeap(), charset, op, fetched_gen_code, fetched_gen_code_len, context_->getSqlParserFlags(), NULL, 0, da); - - diagsArea.mergeAfter(*da); - da->decrRefCount(); + if (da != NULL) + { + diagsArea.mergeAfter(*da); + da->decrRefCount(); + } if (compStatus == ExSqlComp::SUCCESS) { http://git-wip-us.apache.org/repos/asf/trafodion/blob/b97982c4/core/sql/executor/ExCancel.cpp ---------------------------------------------------------------------- diff --git a/core/sql/executor/ExCancel.cpp b/core/sql/executor/ExCancel.cpp index 32b5c53..b425ca4 100755 --- a/core/sql/executor/ExCancel.cpp +++ b/core/sql/executor/ExCancel.cpp @@ -249,14 +249,13 @@ ExWorkProcRetcode ExCancelTcb::work() break; } } - ComDiagsArea *tempDiagsArea = - ComDiagsArea::allocate(getGlobals()->getDefaultHeap()); - tempDiagsArea->clear(); + + ComDiagsArea *tempDiagsArea = NULL; ContextCli *context = getGlobals()->castToExExeStmtGlobals()-> castToExMasterStmtGlobals()->getStatement()->getContext(); ExSsmpManager *ssmpManager = context->getSsmpManager(); - cbServer_ = ssmpManager->getSsmpServer( + cbServer_ = ssmpManager->getSsmpServer((NAHeap *)getGlobals()->getDefaultHeap(), nodeName_, cpu_, tempDiagsArea); if (cbServer_ == NULL) { @@ -266,8 +265,6 @@ ExWorkProcRetcode ExCancelTcb::work() step_ = DONE; break; } - else - tempDiagsArea->decrRefCount(); //Create the stream on the IpcHeap, since we don't dispose // of it immediately. We just add it to the list of completed http://git-wip-us.apache.org/repos/asf/trafodion/blob/b97982c4/core/sql/executor/ExExeUtilCli.cpp ---------------------------------------------------------------------- diff --git a/core/sql/executor/ExExeUtilCli.cpp b/core/sql/executor/ExExeUtilCli.cpp index 3effdb6..be80cf7 100644 --- a/core/sql/executor/ExExeUtilCli.cpp +++ b/core/sql/executor/ExExeUtilCli.cpp @@ -2088,17 +2088,17 @@ Lng32 ExeCliInterface::deleteContext(char* contextHandle) // in buf contains con return SQL_EXEC_DeleteContext(*(SQLCTX_HANDLE*)contextHandle); } -Lng32 ExeCliInterface::retrieveSQLDiagnostics(ComDiagsArea * toDiags) +Lng32 ExeCliInterface::retrieveSQLDiagnostics(ComDiagsArea *toDiags) { Lng32 retcode; - if (diagsArea_) + if (diagsArea_ != NULL) { diagsArea_->clear(); diagsArea_->deAllocate(); } - if (toDiags) + if (toDiags != NULL) { retcode = SQL_EXEC_MergeDiagnostics_Internal(*toDiags); SQL_EXEC_ClearDiagnostics(NULL); http://git-wip-us.apache.org/repos/asf/trafodion/blob/b97982c4/core/sql/executor/ExExeUtilCli.h ---------------------------------------------------------------------- diff --git a/core/sql/executor/ExExeUtilCli.h b/core/sql/executor/ExExeUtilCli.h index 9068602..8c1aa9b 100644 --- a/core/sql/executor/ExExeUtilCli.h +++ b/core/sql/executor/ExExeUtilCli.h @@ -245,7 +245,7 @@ private: Lng32 currentContext(char* contextHandle); // out buf will return context handle Lng32 deleteContext(char* contextHandle); // in buf contains context handle - Lng32 retrieveSQLDiagnostics(ComDiagsArea * toDiags); + Lng32 retrieveSQLDiagnostics(ComDiagsArea *toDiags); CollHeap * getHeap() { return heap_; } http://git-wip-us.apache.org/repos/asf/trafodion/blob/b97982c4/core/sql/executor/ExExplain.cpp ---------------------------------------------------------------------- diff --git a/core/sql/executor/ExExplain.cpp b/core/sql/executor/ExExplain.cpp index b0e2a90..ceaead8 100644 --- a/core/sql/executor/ExExplain.cpp +++ b/core/sql/executor/ExExplain.cpp @@ -1527,7 +1527,7 @@ RtsExplainFrag *ExExplainTcb::sendToSsmp() return NULL; } - IpcServer *ssmpServer = ssmpManager->getSsmpServer(nodeName, cpu, diagsArea_); + IpcServer *ssmpServer = ssmpManager->getSsmpServer((NAHeap *)getHeap(), nodeName, cpu, diagsArea_); if (ssmpServer == NULL) return NULL; // diags are in diagsArea_ http://git-wip-us.apache.org/repos/asf/trafodion/blob/b97982c4/core/sql/executor/ExStats.cpp ---------------------------------------------------------------------- diff --git a/core/sql/executor/ExStats.cpp b/core/sql/executor/ExStats.cpp index 7093c44..af762c9 100644 --- a/core/sql/executor/ExStats.cpp +++ b/core/sql/executor/ExStats.cpp @@ -8164,7 +8164,7 @@ ExStatisticsArea *ExStatsTcb::sendToSsmp() cpu = cliGlobals->myCpu(); else cpu = cpu_; - IpcServer *ssmpServer = ssmpManager->getSsmpServer(nodeName_, cpu, diagsArea_); + IpcServer *ssmpServer = ssmpManager->getSsmpServer((NAHeap *)getHeap(), nodeName_, cpu, diagsArea_); if (ssmpServer == NULL) return NULL; // diags are in diagsArea_ http://git-wip-us.apache.org/repos/asf/trafodion/blob/b97982c4/core/sql/executor/ex_control.cpp ---------------------------------------------------------------------- diff --git a/core/sql/executor/ex_control.cpp b/core/sql/executor/ex_control.cpp index 3684b1f..4a23e30 100644 --- a/core/sql/executor/ex_control.cpp +++ b/core/sql/executor/ex_control.cpp @@ -197,7 +197,7 @@ short ExControlTcb::work() { NAHeap *arkcmpHeap = currCtxt->exHeap(); - ComDiagsArea *da = ComDiagsArea::allocate(getHeap()); + ComDiagsArea *da = NULL; cmpStatus = CmpCommon::context()->compileDirect( (char *) data, dataLen, arkcmpHeap, SQLCHARSETCODE_UTF8, @@ -217,11 +217,12 @@ short ExControlTcb::work() // da->clear(); getHeap()->deallocateMemory(emsText); + if (da != NULL) + da->decrRefCount(); } else saveControl = TRUE; // need to save control to exe ControlInfoTable - da->decrRefCount(); if (dummyReply != NULL) { arkcmpHeap->deallocateMemory((void*)dummyReply); http://git-wip-us.apache.org/repos/asf/trafodion/blob/b97982c4/core/sql/executor/ex_ddl.cpp ---------------------------------------------------------------------- diff --git a/core/sql/executor/ex_ddl.cpp b/core/sql/executor/ex_ddl.cpp index 36772a2..45673ef 100644 --- a/core/sql/executor/ex_ddl.cpp +++ b/core/sql/executor/ex_ddl.cpp @@ -258,8 +258,6 @@ short ExDDLTcb::work() const char *parentQid = masterGlob->getStatement()-> getUniqueStmtId(); CmpCommon::context()->sqlSession()->setParentQid(parentQid); - if (cpDiagsArea == NULL) - cpDiagsArea = ComDiagsArea::allocate(getHeap()); // Despite its name, the compileDirect method is where // the DDL is actually performed. Int32 cpStatus = CmpCommon::context()->compileDirect( @@ -606,8 +604,6 @@ short ExDDLwithStatusTcb::work() getUniqueStmtId(); CmpCommon::context()->sqlSession()->setParentQid(parentQid); - if (cpDiagsArea == NULL) - cpDiagsArea = ComDiagsArea::allocate(getHeap()); cmpStatus = CmpCommon::context()->compileDirect( data_, dataLen_, currContext->exHeap(), @@ -987,8 +983,6 @@ short ExDescribeTcb::work() getUniqueStmtId(); CmpCommon::context()->sqlSession()->setParentQid(parentQid); - if (da == NULL) - da = ComDiagsArea::allocate(arkcmpHeap); compStatus = CmpCommon::context()->compileDirect( describeTdb().query_, describeTdb().queryLen_, http://git-wip-us.apache.org/repos/asf/trafodion/blob/b97982c4/core/sql/executor/ex_root.cpp ---------------------------------------------------------------------- diff --git a/core/sql/executor/ex_root.cpp b/core/sql/executor/ex_root.cpp index 3b3a4d0..38654b3 100644 --- a/core/sql/executor/ex_root.cpp +++ b/core/sql/executor/ex_root.cpp @@ -2235,6 +2235,7 @@ Int32 ex_root_tcb::cancel(ExExeStmtGlobals * glob, ComDiagsArea *&diagsArea, } else { +/* // redrive the scheduler. // Fix for CR 6701 - some ExExeUtil operators call back // in to the CLI and explicitly clear the curr context @@ -2246,13 +2247,15 @@ Int32 ex_root_tcb::cancel(ExExeStmtGlobals * glob, ComDiagsArea *&diagsArea, ContextCli *context = statement->getContext(); ComDiagsArea *savedContextDiags = context->diags().copy(); context->diags().clear(); +*/ schedRetcode = glob->getScheduler()->work(); - +/* savedContextDiags->mergeAfter(context->diags()); context->diags().clear(); context->diags().mergeAfter(*savedContextDiags); savedContextDiags->decrRefCount(); +*/ } } if (!getQueueDiags) @@ -2641,6 +2644,7 @@ void ex_root_tcb::registerCB(ComDiagsArea *&diagsArea) SessionDefaults *sessionDefaults = context->getSessionDefaults(); if (sessionDefaults) { + // Note that it will be required that if a session does not // allow queries to be canceled, then it also will not be // possible to suspend the queries. @@ -2659,15 +2663,11 @@ void ex_root_tcb::registerCB(ComDiagsArea *&diagsArea) return; } } - NABoolean diagsAreaAllocated = FALSE; - - if (diagsArea == NULL) - { - diagsAreaAllocated = TRUE; - diagsArea = ComDiagsArea::allocate(getHeap()); - } + Lng32 fromCond = 0; + if (diagsArea != NULL) + fromCond = diagsArea->mark(); ExSsmpManager *ssmpManager = context->getSsmpManager(); - cbServer_ = ssmpManager->getSsmpServer( + cbServer_ = ssmpManager->getSsmpServer((NAHeap *)getHeap(), cliGlobals->myNodeName(), cliGlobals->myCpu(), diagsArea); if (cbServer_ == NULL || cbServer_->getControlConnection() == NULL) @@ -2675,17 +2675,9 @@ void ex_root_tcb::registerCB(ComDiagsArea *&diagsArea) // We could not get a phandle for the cancel broker. However, // let the query run (on the assumption that it will not need to // be canceled) and convert any error conditions to warnings. - - // tbd - figure a way retry registration later, as the query progresses. - if (diagsArea != NULL) - NegateAllErrors(diagsArea); + diagsArea->negateErrors(fromCond); return; } - else if (diagsAreaAllocated) - { - diagsArea->decrRefCount(); - diagsArea = NULL; - } // The stream's actOnSend method will delete (or call decrRefCount()) // for this object. http://git-wip-us.apache.org/repos/asf/trafodion/blob/b97982c4/core/sql/export/ComDiags.h ---------------------------------------------------------------------- diff --git a/core/sql/export/ComDiags.h b/core/sql/export/ComDiags.h index fa9b1e5..da54f7d 100644 --- a/core/sql/export/ComDiags.h +++ b/core/sql/export/ComDiags.h @@ -837,7 +837,7 @@ public: // These members provide set and get operations on the data // of a ComDiagsArea that is defined in ANSI table 21, in subclause - // 18.1. See also, ``Creating Errors Korrectly.'' + // 18.1. See also, ``Creating Errors Correctly.'' Lng32 getNumber () const; Lng32 getNumber (DgSqlCode::ErrorOrWarning) const; @@ -1018,6 +1018,12 @@ public: while (getNumber(DgSqlCode::ERROR_)) negateCondition(0); } + + void negateErrors (Lng32 fromCondition) + { + while (getNumber(DgSqlCode::ERROR_) > fromCondition) + negateCondition(fromCondition); + } void negateAllWarnings () { http://git-wip-us.apache.org/repos/asf/trafodion/blob/b97982c4/core/sql/optimizer/OptimizerSimulator.cpp ---------------------------------------------------------------------- diff --git a/core/sql/optimizer/OptimizerSimulator.cpp b/core/sql/optimizer/OptimizerSimulator.cpp index d611098..83e69e6 100644 --- a/core/sql/optimizer/OptimizerSimulator.cpp +++ b/core/sql/optimizer/OptimizerSimulator.cpp @@ -1882,7 +1882,7 @@ short OptimizerSimulator::fetchAllRowsFromMetaContext(Queue * &q, const char* qu retcode = cliInterface_->fetchAllRows(queue_, query, 0, FALSE, FALSE, TRUE); //retrieve idag area runing the query above, //if there's any error, we can get the detail. - cliInterface_->retrieveSQLDiagnostics(0); + cliInterface_->retrieveSQLDiagnostics(CmpCommon::diags()); cmpSBD_->switchBackCompiler(); http://git-wip-us.apache.org/repos/asf/trafodion/blob/b97982c4/core/sql/runtimestats/ssmpipc.cpp ---------------------------------------------------------------------- diff --git a/core/sql/runtimestats/ssmpipc.cpp b/core/sql/runtimestats/ssmpipc.cpp index 857913a..9831d6f 100755 --- a/core/sql/runtimestats/ssmpipc.cpp +++ b/core/sql/runtimestats/ssmpipc.cpp @@ -72,7 +72,7 @@ ExSsmpManager::~ExSsmpManager() } } -IpcServer *ExSsmpManager::getSsmpServer(char *nodeName, short cpuNum, +IpcServer *ExSsmpManager::getSsmpServer(NAHeap *heap, char *nodeName, short cpuNum, ComDiagsArea *&diagsArea) { char ssmpProcessName[50]; @@ -101,6 +101,8 @@ IpcServer *ExSsmpManager::getSsmpServer(char *nodeName, short cpuNum, // We need to keep 2 entries free - To send QueryFinishedMessage and to get the response for query started message if (cbGCTS->numReceiveCallbacksPending()+2 >= cbGCTS->getNowaitDepth()) { + if (diagsArea == NULL) + diagsArea = ComDiagsArea::allocate(heap); *diagsArea << DgSqlCode(-2026) << DgString0(tmpProcessName) << DgInt0(GetCliGlobals()->myCpu()) http://git-wip-us.apache.org/repos/asf/trafodion/blob/b97982c4/core/sql/runtimestats/ssmpipc.h ---------------------------------------------------------------------- diff --git a/core/sql/runtimestats/ssmpipc.h b/core/sql/runtimestats/ssmpipc.h index dce7bce..d3e5a9b 100644 --- a/core/sql/runtimestats/ssmpipc.h +++ b/core/sql/runtimestats/ssmpipc.h @@ -58,7 +58,7 @@ class ExSsmpManager public: ExSsmpManager(IpcEnvironment *env); ~ExSsmpManager(); - IpcServer *getSsmpServer(char *nodeName, short cpuNum, ComDiagsArea *&diagsArea); + IpcServer *getSsmpServer(NAHeap *heap, char *nodeName, short cpuNum, ComDiagsArea *&diagsArea); IpcEnvironment *getIpcEnvironment() { return env_; } void removeSsmpServer(char *nodeName, short cpuNum); void cleanupDeletedSsmpServers(); http://git-wip-us.apache.org/repos/asf/trafodion/blob/b97982c4/core/sql/sqlci/Param.cpp ---------------------------------------------------------------------- diff --git a/core/sql/sqlci/Param.cpp b/core/sql/sqlci/Param.cpp index be09697..62b54af 100644 --- a/core/sql/sqlci/Param.cpp +++ b/core/sql/sqlci/Param.cpp @@ -50,6 +50,8 @@ #include "NLSConversion.h" #include "nawstring.h" +extern NAHeap sqlci_Heap; + short convDoItMxcs(char * source, Lng32 sourceLen, short sourceType, @@ -242,7 +244,7 @@ short Param::convertValue(SqlciEnv * sqlci_env, short targetType, Lng32 targetPrecision, Lng32 targetScale, Lng32 vcIndLen, - ComDiagsArea* diags) { + ComDiagsArea *&diags) { // get rid of the old converted value if (converted_value) { @@ -418,7 +420,7 @@ short Param::convertValue(SqlciEnv * sqlci_env, short targetType, targetScale, VCLen, VCLenSize, - 0, + &sqlci_Heap, &diags); if ( ok != ex_expr::EXPR_OK) @@ -454,7 +456,7 @@ short Param::convertValue(SqlciEnv * sqlci_env, short targetType, targetScale, VCLen, VCLenSize, - 0, + &sqlci_Heap, &diags, CONV_UNKNOWN, NULL, http://git-wip-us.apache.org/repos/asf/trafodion/blob/b97982c4/core/sql/sqlci/Param.h ---------------------------------------------------------------------- diff --git a/core/sql/sqlci/Param.h b/core/sql/sqlci/Param.h index 2c4250a..73945e8 100644 --- a/core/sql/sqlci/Param.h +++ b/core/sql/sqlci/Param.h @@ -108,7 +108,7 @@ public: short convertValue(SqlciEnv *, short targetType, Lng32 &targetLength, Lng32 targetPrecision, Lng32 targetScale, Lng32 vcIndLen, - ComDiagsArea* diags = 0); + ComDiagsArea*&diags); void setName(const char * name_); void setValue(const char*, CharInfo::CharSet cs = CharInfo::UnknownCharSet); http://git-wip-us.apache.org/repos/asf/trafodion/blob/b97982c4/core/sql/sqlci/SqlCmd.cpp ---------------------------------------------------------------------- diff --git a/core/sql/sqlci/SqlCmd.cpp b/core/sql/sqlci/SqlCmd.cpp index bb79ff4..e645af4 100644 --- a/core/sql/sqlci/SqlCmd.cpp +++ b/core/sql/sqlci/SqlCmd.cpp @@ -146,10 +146,30 @@ void SqlCmd::clearCLIDiagnostics() volatile Int32 breakReceived = 0; -void HandleCLIError(Lng32 &error, SqlciEnv *sqlci_env, +void HandleCLIError(SQLSTMT_ID *stmt, Lng32 &error, SqlciEnv *sqlci_env, NABoolean displayErr, NABoolean * isEOD, Int32 prepcode) { + Int64 diagsCondCount = 0; + if (error == 100) + diagsCondCount = getDiagsCondCount(stmt); + NABoolean getWarningWithEOF = (diagsCondCount > 0); + HandleCLIError(error, sqlci_env, displayErr, isEOD, prepcode, getWarningWithEOF); +} + +void HandleCLIError(Lng32 &error, SqlciEnv *sqlci_env, + NABoolean displayErr, NABoolean * isEOD, + Int32 prepcode, NABoolean getWarningsWithEOF) +{ + if (error == 100) + { + if (isEOD != NULL) + *isEOD = 1; + if (! getWarningsWithEOF) { + SqlCmd::clearCLIDiagnostics(); + return; + } + } if (isEOD) *isEOD = 0; @@ -366,7 +386,7 @@ void HandleCLIError(Lng32 &error, SqlciEnv *sqlci_env, #endif outtext += pfxl; - #ifdef USE_WCHAR +#ifdef USE_WCHAR if (showSQLSTATE) { $$do something here$$ @@ -429,7 +449,8 @@ void HandleCLIError(Lng32 &error, SqlciEnv *sqlci_env, } // HandleCLIError -void handleLocalError(ComDiagsArea &diags, SqlciEnv *sqlci_env) + +void handleLocalError(ComDiagsArea *diags, SqlciEnv *sqlci_env) { Logfile *log = sqlci_env->get_logfile(); @@ -440,10 +461,10 @@ void handleLocalError(ComDiagsArea &diags, SqlciEnv *sqlci_env) // when HandleCLIError() is called with a error after a CLI call. // Soln :10-021203-3433 - if (diags.getNumber(DgSqlCode::ERROR_)) { + if (diags->getNumber(DgSqlCode::ERROR_)) { worstcode = SQL_Error; } - else if (diags.getNumber(DgSqlCode::WARNING_)) { + else if (diags->getNumber(DgSqlCode::WARNING_)) { worstcode = SQL_Warning; } @@ -451,7 +472,7 @@ void handleLocalError(ComDiagsArea &diags, SqlciEnv *sqlci_env) lastLineWasABlank = TRUE; ostringstream errMsg; - NADumpDiags(errMsg, &diags, TRUE/*newline*/, 0, NULL, log->isVerbose(), + NADumpDiags(errMsg, diags, TRUE/*newline*/, 0, NULL, log->isVerbose(), sqlci_env->getTerminalCharset()); errMsg << ends; @@ -459,6 +480,31 @@ void handleLocalError(ComDiagsArea &diags, SqlciEnv *sqlci_env) log->WriteAllWithoutEOL(errMsg.str().c_str()); } +Int64 getRowsAffected(SQLSTMT_ID *stmt) +{ + Int32 rc; + rc = SQL_EXEC_GetDiagnosticsStmtInfo2(stmt, + SQLDIAG_ROW_COUNT, &rowsAffected, + NULL, 0, NULL); + if (rc == 0) + return rowsAffected; + else + return -1; +} + +Int64 getDiagsCondCount(SQLSTMT_ID *stmt) +{ + Int32 rc; + Int64 diagsCondCount; + rc = SQL_EXEC_GetDiagnosticsStmtInfo2(stmt, + SQLDIAG_NUMBER, &diagsCondCount, + NULL, 0, NULL); + if (rc == 0) + return 0; + else + return diagsCondCount; +} + static char * upshiftStr(char * inStr, char * outStr, UInt32 len) { for (UInt32 i = 0; i < len; i++) @@ -1384,7 +1430,7 @@ short SqlCmd::doDescribeInput(SqlciEnv * sqlci_env, Lng32 retcode = 0; Int32 num_named_params = 0; SqlciList<Param> *unnamed_param_list = NULL; - ComDiagsArea diags(&sqlci_Heap); + ComDiagsArea *diags = NULL; SQLDESC_ID * input_desc = prep_stmt->getInputDesc(); @@ -1546,21 +1592,27 @@ short SqlCmd::doDescribeInput(SqlciEnv * sqlci_env, NABoolean error = FALSE; Lng32 inLength = length; - Int32 previousEntry = diags.getNumber(); + + Int32 previousEntry = 0; + + if (diags != NULL) + previousEntry = diags->getNumber(DgSqlCode::ERROR_); if ( DFS2REC::isAnyCharacter(datatype) ) scale = (Lng32)charset; // pass in target charset in argument 'scale' retcode = param->convertValue(sqlci_env, datatype, length, - precision, scale, vcIndLen, &diags); - Int32 newestEntry = diags.getNumber(); + precision, scale, vcIndLen, diags); + Int32 newestEntry = 0; + if (diags != NULL) + newestEntry = diags->getNumber(DgSqlCode::ERROR_); //if the convertValue gets a string overflow warning, convert //it to error for non characters and it remains warning for characters if (newestEntry > previousEntry) { - if (diags[newestEntry].getSQLCODE() == EXE_STRING_OVERFLOW ){ + if (diags->getErrorEntry(newestEntry)->getSQLCODE() == EXE_STRING_OVERFLOW ){ if (!DFS2REC::isAnyCharacter(datatype)) { - diags.negateCondition(newestEntry-1); + diags->negateCondition(newestEntry-1); error = TRUE; } } @@ -1665,7 +1717,9 @@ short SqlCmd::doDescribeInput(SqlciEnv * sqlci_env, NAString srcval(param->getDisplayValue(sqlci_env->getTerminalCharset())); if (srcval.isNull()) srcval = "''"; // empty string literal - diags << DgSqlCode(-SQLCI_PARAM_BAD_CONVERT) + if (diags == NULL) + diags = ComDiagsArea::allocate(&sqlci_Heap); + *diags << DgSqlCode(-SQLCI_PARAM_BAD_CONVERT) << DgString0(Param::getExternalName(param_name)) << DgString1(srcval) << DgString2(tgttype); @@ -1673,7 +1727,9 @@ short SqlCmd::doDescribeInput(SqlciEnv * sqlci_env, } // not null param } // if param else { - diags << DgSqlCode(-SQLCI_PARAM_NOT_FOUND) + if (diags == NULL) + diags = ComDiagsArea::allocate(&sqlci_Heap); + *diags << DgSqlCode(-SQLCI_PARAM_NOT_FOUND) << DgString0(Param::getExternalName(param_name)); } @@ -1701,16 +1757,18 @@ short SqlCmd::doDescribeInput(SqlciEnv * sqlci_env, if (numUnnamedParams > 0 && numUnnamedParams > num_input_entries - num_named_params) { + if (diags == NULL) + diags = ComDiagsArea::allocate(&sqlci_Heap); // Warning only, so continue processing after this! - diags << DgSqlCode(+SQLCI_EXTRA_PARAMS_SUPPLIED) // + (i.e. warning) + *diags << DgSqlCode(+SQLCI_EXTRA_PARAMS_SUPPLIED) // + (i.e. warning) << DgInt0(numUnnamedParams) << DgInt1(num_input_entries - num_named_params); } - if (diags.getNumber()) + if (diags != NULL) { handleLocalError(diags, sqlci_env); - if (diags.getNumber(DgSqlCode::ERROR_)) { + if (diags->getNumber(DgSqlCode::ERROR_)) { return SQL_Error; } } @@ -1782,7 +1840,6 @@ short SqlCmd::doExec(SqlciEnv * sqlci_env, CharInfo::CharSet* unnamedParamCharSetArray, NABoolean handleError) { - ComDiagsArea diags(&sqlci_Heap); Lng32 retcode = 0; rowsAffected = 0; SqlciList<Param> *unnamed_param_list = NULL; @@ -1809,8 +1866,11 @@ short SqlCmd::doExec(SqlciEnv * sqlci_env, if (unnamed_param_list) delete unnamed_param_list; + if (retcode > 0) + getRowsAffected(stmt); return (short)retcode; } // SqlCmd::doExec + short SqlCmd::doFetch(SqlciEnv * sqlci_env, SQLSTMT_ID * stmt, PrepStmt * prep_stmt, NABoolean firstFetch, @@ -1827,7 +1887,7 @@ short SqlCmd::doFetch(SqlciEnv * sqlci_env, SQLSTMT_ID * stmt, NABoolean isEOD = 0; if (handleError) - HandleCLIError(retcode, sqlci_env, TRUE, &isEOD,prepcode); + HandleCLIError(stmt, retcode, sqlci_env, TRUE, &isEOD,prepcode); if (isEOD) retcode = SQL_Eof; @@ -1871,7 +1931,8 @@ short SqlCmd::doClearExecFetchClose(SqlciEnv * sqlci_env, if (handleError) HandleCLIError(retcode, sqlci_env, TRUE); - + if (retcode > 0) + getRowsAffected(stmt); return (short)retcode; } @@ -2047,7 +2108,6 @@ short SqlCmd::do_execute(SqlciEnv * sqlci_env, CharInfo::CharSet* unnamedParamCharSetArray, Int32 prepcode) { - ComDiagsArea diags(&sqlci_Heap); Lng32 retcode = 0; //short ret; Logfile *log = sqlci_env->get_logfile(); @@ -2317,6 +2377,7 @@ short SqlCmd::do_execute(SqlciEnv * sqlci_env, } HandleCLIError(retcode, sqlci_env); } + getRowsAffected(stmt); } // retcode >= 0 @@ -3754,7 +3815,8 @@ short Cursor::close(SqlciEnv * sqlci_env, char * donemsg, retcode = SQL_EXEC_CloseStmt(cursor->cursorStmtId()); HandleCLIError(retcode, sqlci_env); - + if (retcode > 0) + getRowsAffected(cursor->cursorStmtId()); if (donemsg) sprintf(donemsg, OP_COMPLETE_MESSAGE); http://git-wip-us.apache.org/repos/asf/trafodion/blob/b97982c4/core/sql/sqlci/SqlciCmd.cpp ---------------------------------------------------------------------- diff --git a/core/sql/sqlci/SqlciCmd.cpp b/core/sql/sqlci/SqlciCmd.cpp index 665c337..621022f 100644 --- a/core/sql/sqlci/SqlciCmd.cpp +++ b/core/sql/sqlci/SqlciCmd.cpp @@ -991,7 +991,7 @@ short ParserFlags::process(SqlciEnv * sqlci_env) // Return - "not authorized" error ComDiagsArea diags; diags << DgSqlCode(-1017); - handleLocalError(diags, sqlci_env); + handleLocalError(&diags, sqlci_env); return -1; } @@ -1003,7 +1003,7 @@ short ParserFlags::process(SqlciEnv * sqlci_env) // Please use "RESET PARSERFLAGS <value>" to reset the flags. ComDiagsArea diags; diags << DgSqlCode(3190); - handleLocalError(diags, sqlci_env); + handleLocalError(&diags, sqlci_env); } retCode = SQL_EXEC_SetParserFlagsForExSqlComp_Internal2(param); } @@ -1020,7 +1020,7 @@ short ParserFlags::process(SqlciEnv * sqlci_env) // You are not authorized to perform this operation. ComDiagsArea diags; diags << DgSqlCode(retCode); - handleLocalError(diags, sqlci_env); + handleLocalError(&diags, sqlci_env); } return 0; } http://git-wip-us.apache.org/repos/asf/trafodion/blob/b97982c4/core/sql/sqlci/sqlcmd.h ---------------------------------------------------------------------- diff --git a/core/sql/sqlci/sqlcmd.h b/core/sql/sqlci/sqlcmd.h index 5e48c84..b7d40f9 100644 --- a/core/sql/sqlci/sqlcmd.h +++ b/core/sql/sqlci/sqlcmd.h @@ -57,9 +57,15 @@ extern void HandleCLIErrorInit(); extern void HandleCLIError(Lng32 &err, SqlciEnv *sqlci_env, NABoolean displayErr = TRUE, NABoolean * isEOD = NULL, + Int32 prepcode = 0, NABoolean getWarningsWithEOF = FALSE); +extern void HandleCLIError(SQLSTMT_ID *stmt, Lng32 &err, SqlciEnv *sqlci_env, + NABoolean displayErr = TRUE, + NABoolean * isEOD = NULL, Int32 prepcode = 0); -void handleLocalError(ComDiagsArea &diags, SqlciEnv *sqlci_env); +void handleLocalError(ComDiagsArea *diags, SqlciEnv *sqlci_env); +Int64 getRowsAffected(SQLSTMT_ID *stmt); +Int64 getDiagsCondCount(SQLSTMT_ID *stmt); // for unnamed parameters #define MAX_NUM_UNNAMED_PARAMS 128 #define MAX_LEN_UNNAMED_PARAM 300 http://git-wip-us.apache.org/repos/asf/trafodion/blob/b97982c4/core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp ---------------------------------------------------------------------- diff --git a/core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp b/core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp index e767cec..219b2e8 100644 --- a/core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp +++ b/core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp @@ -177,13 +177,13 @@ short CmpSeabaseDDL::switchCompiler(Int32 cntxtType) short CmpSeabaseDDL::switchBackCompiler() { - ComDiagsArea * tempDiags = NULL; + + Lng32 diagsMark = 0; if (cmpSwitched_) - { - tempDiags = ComDiagsArea::allocate(heap_); - tempDiags->mergeAfter(*CmpCommon::diags()); - } - + { + if (CmpCommon::diags() != NULL) + diagsMark = CmpCommon::diags()->mark(); + } // do restore here even though switching may not have happened, i.e. // when switchToCompiler() was not called by the embedded CI, see above. restoreAllControlsAndFlags(); @@ -191,11 +191,7 @@ short CmpSeabaseDDL::switchBackCompiler() if (cmpSwitched_) { // ignore new (?) from restore call but restore old diags - CmpCommon::diags()->clear(); - CmpCommon::diags()->mergeAfter(*tempDiags); - tempDiags->clear(); - tempDiags->deAllocate(); - + CmpCommon::diags()->rewind(diagsMark, TRUE); // switch back to the original commpiler, ignore return error SQL_EXEC_SWITCH_BACK_COMPILER();
