trafodion-codereview mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sandhyasun <...@git.apache.org>
Subject [GitHub] trafodion pull request #1721: [TRAFODION-3216]UDR libraries need to be store...
Date Mon, 15 Oct 2018 20:15:40 GMT
Github user sandhyasun commented on a diff in the pull request:

    https://github.com/apache/trafodion/pull/1721#discussion_r225301536
  
    --- Diff: core/sql/sqlcomp/CmpSeabaseDDLroutine.cpp ---
    @@ -1925,3 +2730,568 @@ short CmpSeabaseDDL::createSeabaseLibmgrCPPLib(ExeCliInterface
* cliInterface)
         }
       return 0;
     }
    +
    +short CmpSeabaseDDL::upgradeLibraries(ExeCliInterface * cliInterface,
    +                                  CmpDDLwithStatusInfo *mdui)
    +{
    +Lng32 cliRC = 0;
    +
    +  while (1) // exit via return stmt in switch
    +    {
    +      switch (mdui->subStep())
    +        {
    +        case 0:
    +          {
    +            mdui->setMsg("Upgrade Libraries: Started");
    +            mdui->subStep()++;
    +            mdui->setEndStep(FALSE);
    +        
    +            return 0;
    +          }
    +          break;
    +      
    +        case 1:
    +          {
    +            mdui->setMsg("  Start: Drop Old Libraries");
    +            mdui->subStep()++;
    +            mdui->setEndStep(FALSE);
    +        
    +            return 0;
    +          }
    +          break;
    +
    +        case 2:
    +          {
    +            // drop old libraries
    +            if (dropLibraries(cliInterface, TRUE/*old */))
    +              return -3;  // error, but no recovery needed 
    +        
    +            mdui->setMsg("  End:   Drop Old Libraries");
    +            mdui->subStep()++;
    +            mdui->setEndStep(FALSE);
    +        
    +            return 0;
    +          }
    +          break;
    +
    +        case 3:
    +          {
    +            mdui->setMsg("  Start: Rename Current Libraries");
    +            mdui->subStep()++;
    +            mdui->setEndStep(FALSE);
    +        
    +            return 0;
    +          }
    +          break;
    +        
    +        case 4:
    +          {
    +            // rename current libraries tables to *_OLD_LIBRARIES
    +            if (alterRenameLibraries(cliInterface, TRUE))
    +              return -2;  // error, need to undo the rename only
    +
    +            mdui->setMsg("  End:   Rename Current Libraries");
    +            mdui->subStep()++;
    +            mdui->setEndStep(FALSE);
    +        
    +            return 0;
    +          }
    +          break;
    +
    +        case 5:
    +          {
    +            mdui->setMsg("  Start: Create New Libraries");
    +            mdui->subStep()++;
    +            mdui->setEndStep(FALSE);
    +        
    +            return 0;
    +          }
    +          break;
    +         
    +        case 6:
    +          {
    +            // create new libraries
    +            if (createLibraries(cliInterface))
    +              return -1;  // error, need to drop new libraies then undo rename
    +        
    +            mdui->setMsg("  End:   Create New Libraries");
    +            mdui->subStep()++;
    +            mdui->setEndStep(FALSE);
    +  
    +            return 0;
    +          }
    +          break;
    +
    +        case 7:
    +          {
    +            mdui->setMsg("  Start: Copy Old Libraries Contents ");
    +            mdui->subStep()++;
    +            mdui->setEndStep(FALSE);
    +        
    +            return 0;
    +          }
    +          break;
    +
    +        case 8:
    +          {
    +            // copy old contents into new 
    +           
    +            if (copyOldLibrariesToNew(cliInterface))
    +              {
    +                mdui->setMsg(" Copy Old Libraries failed ! Drop  and recreate the
following :   ");
    +                //return -1;  // error, need to drop new libraries then undo rename
    +              }
    +        
    +            mdui->setMsg("  End:   Copy Old Libraries Contents ");
    +            mdui->subStep()++;
    +            mdui->setEndStep(FALSE);
    +         
    +            return 0;
    +          }
    +          break;
    +
    +        case 9:
    +          {
    +            mdui->setMsg("Upgrade Libraries: Done except for cleaning up");
    +            mdui->setSubstep(0);
    +            mdui->setEndStep(TRUE);
    +        
    +            return 0;
    +          }
    +          break;
    +
    +        default:
    +          return -1;
    +        }
    +    } // while
    +
    +  return 0;
    +}
    +
    +short CmpSeabaseDDL::upgradeLibrariesComplete(ExeCliInterface * cliInterface,
    +                                              CmpDDLwithStatusInfo *mdui)
    +{
    +  switch (mdui->subStep())
    +    {
    +    case 0:
    +      {
    +        mdui->setMsg("Upgrade Libraries: Drop old libraries");
    +        mdui->subStep()++;
    +        mdui->setEndStep(FALSE);
    +        
    +        return 0;
    +      }
    +      break;
    +    case 1:
    +      {
    +        // drop old libraries; ignore errors
    +        dropLibraries(cliInterface, TRUE/*old repos*/, FALSE/*no schema drop*/);
    +        
    +        mdui->setMsg("Upgrade Libraries: Drop Old Libraries done");
    +        mdui->setEndStep(TRUE);
    +        mdui->setSubstep(0);
    +         
    +        return 0;
    +      }
    +      break;
    +
    +    default:
    +      return -1;
    +    }
    +
    +return 0;
    +}
    +
    +
    +short CmpSeabaseDDL::upgradeLibrariesUndo(ExeCliInterface * cliInterface,
    +                                  CmpDDLwithStatusInfo *mdui)
    +{
    +  Lng32 cliRC = 0;
    +
    +  while (1) // exit via return stmt in switch
    +    {
    +      switch (mdui->subStep())
    +        {
    +        // error return codes from upgradeLibraries can be mapped to
    +        // the right recovery substep by this formula: substep = -(retcode + 1)
    +        case 0: // corresponds to -1 return code from upgradeRepos (or
    +                // to full recovery after some error after upgradeRepos)
    +        case 1: // corresponds to -2 return code from upgradeRepos
    +        case 2: // corresponds to -3 return code from upgradeRepos
    +          {
    +            mdui->setMsg("Upgrade Libraries: Restoring Old Libraries");
    +            mdui->setSubstep(2*mdui->subStep()+3); // go to appropriate case
    +            mdui->setEndStep(FALSE);
    +        
    +            return 0;
    +          }
    +          break;
    +
    +        case 3:
    +          {
    +            mdui->setMsg(" Start: Drop New Libraries");
    +            mdui->subStep()++;
    +            mdui->setEndStep(FALSE);
    +        
    +            return 0;
    +          }
    +          break;
    +
    +        case 4:
    +          {
    +            // drop new Libraries; ignore errors
    +            dropLibraries(cliInterface, FALSE/*new repos*/, 
    +                          TRUE /* don't drop new tables that haven't been upgraded */);
    +            cliInterface->clearGlobalDiags();
    +            mdui->setMsg(" End: Drop New Libraries");
    +            mdui->subStep()++;
    +            mdui->setEndStep(FALSE);
    +        
    +            return 0;
    +          }
    +          break;
    +
    +        case 5:
    +          {
    +            mdui->setMsg(" Start: Rename Old Libraries back to New");
    +            mdui->subStep()++;
    +            mdui->setEndStep(FALSE);
    +        
    +            return 0;
    +          }
    +          break;
    + 
    +        case 6:
    +          {
    +            // rename old Libraries to current; ignore errors
    +            alterRenameLibraries(cliInterface, FALSE);
    +            cliInterface->clearGlobalDiags();
    +            mdui->setMsg(" End: Rename Old Libraries back to New");
    +            mdui->subStep()++;
    +            mdui->setEndStep(FALSE);
    +        
    +            return 0;
    +          }
    +          break;
    +
    +        case 7:
    +          {
    +            mdui->setMsg("Upgrade Libraries: Restore done");
    +            mdui->setSubstep(0);
    +            mdui->setEndStep(TRUE);
    +        
    +            return 0;
    +          }
    +          break;
    +
    +        default:
    +          return -1;
    +        }
    +    } // while
    +
    +  return 0;
    +
    +}
    +
    +short CmpSeabaseDDL::createLibraries(ExeCliInterface * cliInterface)
    +{
    + Lng32 cliRC = 0;
    +
    +  char queryBuf[20000];
    +
    +  NABoolean xnWasStartedHere = FALSE;
    +
    +
    +  for (Int32 i = 0; i < sizeof(allLibrariesUpgradeInfo)/sizeof(MDUpgradeInfo); i++)
    +    {
    +      const MDUpgradeInfo &lti = allLibrariesUpgradeInfo[i];
    +
    +      if (! lti.newName)
    +        continue;
    +
    +      for (Int32 j = 0; j < NUM_MAX_PARAMS; j++)
    +	{
    +	  param_[j] = NULL;
    +	}
    +
    +      const QString * qs = NULL;
    +      Int32 sizeOfqs = 0;
    +
    +      qs = lti.newDDL;
    +      sizeOfqs = lti.sizeOfnewDDL; 
    +
    +      Int32 qryArraySize = sizeOfqs / sizeof(QString);
    +      char * gluedQuery;
    +      Lng32 gluedQuerySize;
    +      glueQueryFragments(qryArraySize,  qs,
    +			 gluedQuery, gluedQuerySize);
    +
    + 
    +      param_[0] = getSystemCatalog();
    +      param_[1] = SEABASE_MD_SCHEMA;
    +
    +      str_sprintf(queryBuf, gluedQuery, param_[0], param_[1]);
    +      NADELETEBASICARRAY(gluedQuery, STMTHEAP);
    +
    +      if (beginXnIfNotInProgress(cliInterface, xnWasStartedHere))
    +        goto label_error;
    +      
    +      cliRC = cliInterface->executeImmediate(queryBuf);
    +      if (cliRC == -1390)  // table already exists
    +	{
    +	  // ignore error.
    +          cliRC = 0;
    +	}
    +      else if (cliRC < 0)
    +	{
    +	  cliInterface->retrieveSQLDiagnostics(CmpCommon::diags());
    +	}
    +
    +      if (endXnIfStartedHere(cliInterface, xnWasStartedHere, cliRC) < 0)
    +        goto label_error;
    +      
    +    } // for
    +  
    +  
    +  return 0;
    +
    +  label_error:
    +   
    +   return -1;
    +}
    +
    +short CmpSeabaseDDL::dropLibraries(ExeCliInterface * cliInterface,
    +                               NABoolean oldLibrary,
    +                               NABoolean inRecovery)
    +{
    + Lng32 cliRC = 0;
    +  NABoolean xnWasStartedHere = FALSE;
    +  char queryBuf[1000];
    +
    +  for (Int32 i = 0; i < sizeof(allLibrariesUpgradeInfo)/sizeof(MDUpgradeInfo); i++)
    +    {
    +      const MDUpgradeInfo &lti = allLibrariesUpgradeInfo[i];
    +
    +      // If we are dropping the new repository as part of a recovery action,
    +      // and there is no "old" table (because the table didn't change in this
    +      // upgrade), then don't drop the new table. (If we did, we would be 
    +      // dropping the existing data.)
    +      if (!oldLibrary && inRecovery && !lti.oldName)
    +        continue;
    +
    +      if ((oldLibrary  && !lti.oldName) || (NOT oldLibrary && ! lti.newName))
    +        continue;
    +
    +      str_sprintf(queryBuf, "drop table %s.\"%s\".%s cascade; ",
    +                  getSystemCatalog(), SEABASE_MD_SCHEMA,
    +                  (oldLibrary ? lti.oldName : lti.newName));
    +    
    +      if (beginXnIfNotInProgress(cliInterface, xnWasStartedHere))
    +        {
    +          cliInterface->retrieveSQLDiagnostics(CmpCommon::diags());
    +          return -1;
    +        }    
    +
    +      cliRC = cliInterface->executeImmediate(queryBuf);
    +      if (cliRC == -1389)  // table doesn't exist
    +	{
    +	  // ignore the error.
    +          cliRC = 0;
    +	}
    +      else if (cliRC < 0)
    +        {
    +          cliInterface->retrieveSQLDiagnostics(CmpCommon::diags());
    +        }
    + 
    +      if (endXnIfStartedHere(cliInterface, xnWasStartedHere, cliRC) < 0)
    +        {
    +          cliInterface->retrieveSQLDiagnostics(CmpCommon::diags());
    +          return -1;
    +        }
    + 
    +      if (cliRC < 0)
    +        {
    +          return -1;  
    +        }
    +
    +    }
    +
    +
    +  return 0;
    +}
    +
    +short CmpSeabaseMDupgrade::dropLibrariesTables(ExpHbaseInterface *ehi,
    +                                           NABoolean oldLibraries)
    +{
    +  Lng32 retcode = 0;
    +  Lng32 errcode = 0;
    +
    +  for (Int32 i = 0; i < sizeof(allLibrariesUpgradeInfo)/sizeof(MDUpgradeInfo); i++)
    +    {
    +      const MDUpgradeInfo &lti = allLibrariesUpgradeInfo[i];
    +
    +      if ((NOT oldLibraries) && (!lti.newName))
    +	continue;
    +
    +      HbaseStr hbaseTable;
    +      NAString extNameForHbase = TRAFODION_SYSCAT_LIT;
    +      extNameForHbase += ".";
    +      extNameForHbase += SEABASE_MD_SCHEMA;
    +      extNameForHbase +=  ".";
    +
    +      if (oldLibraries)
    +	{
    +          if (!lti.oldName)
    +            continue;
    +          
    +          extNameForHbase += lti.oldName;
    +	}
    +      else
    +	extNameForHbase += lti.newName;
    +      
    +      hbaseTable.val = (char*)extNameForHbase.data();
    +      hbaseTable.len = extNameForHbase.length();
    +      
    +      retcode = dropHbaseTable(ehi, &hbaseTable, FALSE, FALSE);
    +      if (retcode < 0)
    +	{
    +	  errcode = -1;
    +	}
    +      
    +    } // for
    +  
    +  return errcode;
    +}
    +
    +
    +short CmpSeabaseDDL::alterRenameLibraries(ExeCliInterface * cliInterface,
    +                                          NABoolean newToOld)
    +{
    + Lng32 cliRC = 0;
    +
    +  char queryBuf[10000];
    +
    +  NABoolean xnWasStartedHere = FALSE;
    +
    +  // alter table rename cannot run inside of a transaction.
    +  // return an error if a xn is in progress
    +  if (xnInProgress(cliInterface))
    +    {
    +      *CmpCommon::diags() << DgSqlCode(-20123);
    +      return -1;
    +    }
    +
    +  for (Int32 i = 0; i < sizeof(allLibrariesUpgradeInfo)/sizeof(MDUpgradeInfo); i++)
    +    {
    +      const MDUpgradeInfo &lti = allLibrariesUpgradeInfo[i];
    +
    +      if ((! lti.newName) || (! lti.oldName) || (NOT lti.upgradeNeeded))
    +        continue;
    +
    +      if (newToOld)
    +        str_sprintf(queryBuf, "alter table %s.\"%s\".%s rename to %s ; ",
    +                    getSystemCatalog(), SEABASE_MD_SCHEMA, lti.newName, lti.oldName);
    +      else
    +        str_sprintf(queryBuf, "alter table %s.\"%s\".%s rename to %s ; ",
    +                    getSystemCatalog(), SEABASE_MD_SCHEMA, lti.oldName, lti.newName);
    +        
    +      cliRC = cliInterface->executeImmediate(queryBuf);
    +      if (cliRC == -1389 || cliRC == -1390)
    +        {
    +          // ignore.
    +          cliRC = 0;
    +        }
    +      else if (cliRC < 0)
    +	{
    +	  cliInterface->retrieveSQLDiagnostics(CmpCommon::diags());
    +	}
    +    }
    +
    +  return 0;
    +}
    +
    +short CmpSeabaseDDL::copyOldLibrariesToNew(ExeCliInterface * cliInterface)
    +{
    +  Lng32 cliRC = 0;
    +  NAString failedLibraries;
    +
    +  char queryBuf[10000];
    +  for (Int32 i = 0; i < sizeof(allLibrariesUpgradeInfo)/sizeof(MDUpgradeInfo); i++)
    +    {
    +      const MDUpgradeInfo lti = allLibrariesUpgradeInfo[i];
    +
    +      if ((! lti.newName) || (! lti.oldName) || (NOT lti.upgradeNeeded))
    +        continue;
    +      // Update all existing libraries  so the blob contains the library
    +      char * sbuf = new(STMTHEAP) char[200];
    +      char * ubuf = new(STMTHEAP) char[500];
    +      NABoolean libsToUpgrade = TRUE;
    +      Queue *userLibsQ = NULL;
    +      str_sprintf(sbuf, "select library_filename,library_uid from %s.\"%s\".%s"
    +                  " for read uncommitted access",
    +                  getSystemCatalog(), SEABASE_MD_SCHEMA, lti.oldName); 
    +      cliRC = cliInterface->fetchAllRows(userLibsQ,sbuf, 0, FALSE,FALSE,TRUE/*no exec*/);
    +      if (cliRC < 0)
    +        {
    +          cliInterface->retrieveSQLDiagnostics(CmpCommon::diags());
    +          return -1;
    +        }
    +
    +    
    +     
    +      str_sprintf(queryBuf, "upsert using load into %s.\"%s\".%s %s%s%s select %s from
%s.\"%s\".%s SRC %s;",
    +                  TRAFODION_SYSCAT_LIT,
    +                  SEABASE_MD_SCHEMA,
    +                  lti.newName, 
    +                  (lti.insertedCols ? "(" : ""),
    +                  (lti.insertedCols ? lti.selectedCols : ""), // insert only the original
column values
    +                  (lti.insertedCols ? ")" : ""),
    +                  (lti.selectedCols ? lti.selectedCols : "*"),
    +                  TRAFODION_SYSCAT_LIT,
    +                  SEABASE_MD_SCHEMA,
    +                  lti.oldName,
    +                  (lti.wherePred ? lti.wherePred : ""));
    +
    +      cliRC = cliInterface->executeImmediate(queryBuf);
    +      if (cliRC < 0)
    +        {
    +          cliInterface->retrieveSQLDiagnostics(CmpCommon::diags());
    +          return -1;
    +        }
    +
    +      //update contents into  the new library table so the libname doesn't contain the
path and the 
    +      //lib contents get loaded into the blob column.
    +      userLibsQ->position();
    +      for (size_t i = 0; i < userLibsQ->numEntries(); i++)
    --- End diff --
    
    Included the system libraries in this upgrade. So they will also have an entry in the
blob volumn. There is one exception to this - validateRoutine that would show up as a "failed"
upgrade but it doesn't prevent the upgrade operation. 


---

Mime
View raw message