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 Tue, 16 Oct 2018 23:43:26 GMT
Github user sandhyasun commented on a diff in the pull request:

    https://github.com/apache/trafodion/pull/1721#discussion_r225742582
  
    --- Diff: core/sql/sqlcomp/CmpSeabaseDDLroutine.cpp ---
    @@ -563,32 +795,332 @@ void CmpSeabaseDDL::dropSeabaseLibrary(StmtDDLDropLibrary * dropLibraryNode,
       processReturn();
       return;
     }
    -
    -void  CmpSeabaseDDL::alterSeabaseLibrary(StmtDDLAlterLibrary  *alterLibraryNode,
    -					 NAString &currCatName, 
    -					 NAString &currSchName)
    +void CmpSeabaseDDL::dropSeabaseLibrary(StmtDDLDropLibrary * dropLibraryNode,
    +                                       NAString &currCatName, 
    +                                       NAString &currSchName)
     {
    -  Lng32 cliRC;
    -  Lng32 retcode;
    -  
    -  NAString libraryName = alterLibraryNode->getLibraryName();
    -  NAString libFileName = alterLibraryNode->getFilename();
    -  
    -  ComObjectName libName(libraryName, COM_TABLE_NAME);
    +  Lng32 cliRC = 0;
    +  Lng32 retcode = 0;
    +
    +  BindWA bindWA(ActiveSchemaDB(), CmpCommon::context(), FALSE/*inDDL*/);
    +  NARoutineDB *pRoutineDBCache  = ActiveSchemaDB()->getNARoutineDB();
    +  const NAString &objName = dropLibraryNode->getLibraryName();
    +
    +  ComObjectName libraryName(objName);
       ComAnsiNamePart currCatAnsiName(currCatName);
       ComAnsiNamePart currSchAnsiName(currSchName);
    -  libName.applyDefaults(currCatAnsiName, currSchAnsiName);
    -  
    -  NAString catalogNamePart = libName.getCatalogNamePartAsAnsiString();
    -  NAString schemaNamePart = libName.getSchemaNamePartAsAnsiString(TRUE);
    -  NAString libNamePart = libName.getObjectNamePartAsAnsiString(TRUE);
    -  const NAString extLibName = libName.getExternalName(TRUE);
    -  
    -  ExeCliInterface cliInterface(STMTHEAP, 0, NULL,
    -			       CmpCommon::context()->sqlSession()->getParentQid());
    -  
    +  libraryName.applyDefaults(currCatAnsiName, currSchAnsiName);
    +
    +  const NAString catalogNamePart = libraryName.
    +    getCatalogNamePartAsAnsiString();
    +  const NAString schemaNamePart = libraryName.
    +    getSchemaNamePartAsAnsiString(TRUE);
    +  const NAString objectNamePart = libraryName.
    +    getObjectNamePartAsAnsiString(TRUE);
    +  const NAString extLibraryName = libraryName.getExternalName(TRUE);
    +
    +  ExeCliInterface cliInterface(STMTHEAP, 0, NULL, 
    +    CmpCommon::context()->sqlSession()->getParentQid());
    +
    +  ExpHbaseInterface * ehi = allocEHI();
    +  if (ehi == NULL)
    +    return;
    +
       retcode = existsInSeabaseMDTable(&cliInterface, 
    -				   catalogNamePart, schemaNamePart, libNamePart,
    +				   catalogNamePart, schemaNamePart, 
    +                                   objectNamePart,
    +				   COM_LIBRARY_OBJECT, TRUE, FALSE);
    +  if (retcode < 0)
    +    {
    +      deallocEHI(ehi); 
    +      processReturn();
    +      return;
    +    }
    +
    +  if (retcode == 0) // does not exist
    +    {
    +      *CmpCommon::diags() << DgSqlCode(-1389)
    +			  << DgString0(extLibraryName);
    +      deallocEHI(ehi); 
    +      processReturn();
    +      return;
    +    }
    +
    +  Int32 objectOwnerID = 0;
    +  Int32 schemaOwnerID = 0;
    +  Int64 objectFlags = 0;
    +  Int64 objUID = getObjectInfo(&cliInterface,
    +			      catalogNamePart.data(), schemaNamePart.data(), 
    +			      objectNamePart.data(), COM_LIBRARY_OBJECT,
    +                              objectOwnerID,schemaOwnerID,objectFlags);
    +  if (objUID < 0 || objectOwnerID == 0 || schemaOwnerID == 0)
    +    {
    +      deallocEHI(ehi); 
    +      processReturn();
    +      return;
    +    }
    +
    +  if (!isDDLOperationAuthorized(SQLOperation::DROP_LIBRARY,
    +                                objectOwnerID,
    +                                schemaOwnerID))
    +  {
    +     *CmpCommon::diags() << DgSqlCode(-CAT_NOT_AUTHORIZED);
    +     processReturn ();
    +     return;
    +  }
    +  
    +  Queue * usingRoutinesQueue = NULL;
    +  cliRC = getUsingRoutines(&cliInterface, objUID, usingRoutinesQueue);
    +  if (cliRC < 0)
    +    {
    +      deallocEHI(ehi); 
    +      processReturn();
    +      return;
    +    }
    +  // If RESTRICT and the library is being used, return an error
    +  if (cliRC != 100 && dropLibraryNode->getDropBehavior() == COM_RESTRICT_DROP_BEHAVIOR)

    +    {
    +      *CmpCommon::diags() << DgSqlCode(-CAT_DEPENDENT_ROUTINES_EXIST);
    +
    +      deallocEHI(ehi); 
    +      processReturn();
    +      return;
    +    }
    +    
    +  usingRoutinesQueue->position();
    +  for (size_t i = 0; i < usingRoutinesQueue->numEntries(); i++)
    +  { 
    +     OutputInfo * rou = (OutputInfo*)usingRoutinesQueue->getNext(); 
    +     
    +     char * routineName = rou->get(0);
    +     ComObjectType objectType = PrivMgr::ObjectLitToEnum(rou->get(1));
    +
    +     if (dropSeabaseObject(ehi, routineName,
    +                           currCatName, currSchName, objectType,
    +                           dropLibraryNode->ddlXns(),
    +                           TRUE, FALSE))
    +     {
    +       deallocEHI(ehi); 
    +       processReturn();
    +       return;
    +     }
    +
    +     // Remove routine from DBRoutinCache
    +     ComObjectName objectName(routineName);
    +     QualifiedName qualRoutineName(objectName, STMTHEAP);
    +     NARoutineDBKey key(qualRoutineName, STMTHEAP);
    +     NARoutine *cachedNARoutine = pRoutineDBCache->get(&bindWA, &key);
    +
    +     if (cachedNARoutine)
    +     {
    +       Int64 routineUID = *(Int64*)rou->get(2);
    +       pRoutineDBCache->removeNARoutine(qualRoutineName,
    +                                        ComQiScope::REMOVE_FROM_ALL_USERS,
    +                                        routineUID,
    +                                        dropLibraryNode->ddlXns(), FALSE);
    +     }
    +
    +   }
    + 
    +  // can get a slight perf. gain if we pass in objUID
    +  if (dropSeabaseObject(ehi, objName,
    +                        currCatName, currSchName, COM_LIBRARY_OBJECT,
    +                        dropLibraryNode->ddlXns(),
    +                        TRUE, FALSE))
    +    {
    +      deallocEHI(ehi); 
    +      processReturn();
    +      return;
    +    }
    +
    +  deallocEHI(ehi);      
    +  processReturn();
    +  return;
    +}
    +
    +void  CmpSeabaseDDL::alterSeabaseLibrary2(StmtDDLAlterLibrary  *alterLibraryNode,
    +					 NAString &currCatName, 
    +					 NAString &currSchName)
    +{
    +  Lng32 cliRC;
    +  Lng32 retcode;
    +  
    +  NAString libraryName = alterLibraryNode->getLibraryName();
    +  NAString libFileName = alterLibraryNode->getFilename();
    +  
    +  ComObjectName libName(libraryName, COM_TABLE_NAME);
    +  ComAnsiNamePart currCatAnsiName(currCatName);
    +  ComAnsiNamePart currSchAnsiName(currSchName);
    +  libName.applyDefaults(currCatAnsiName, currSchAnsiName);
    +  
    +  NAString catalogNamePart = libName.getCatalogNamePartAsAnsiString();
    +  NAString schemaNamePart = libName.getSchemaNamePartAsAnsiString(TRUE);
    +  NAString libNamePart = libName.getObjectNamePartAsAnsiString(TRUE);
    +  const NAString extLibName = libName.getExternalName(TRUE);
    +  
    +  ExeCliInterface cliInterface(STMTHEAP, 0, NULL,
    +			       CmpCommon::context()->sqlSession()->getParentQid());
    +  
    +  retcode = existsInSeabaseMDTable(&cliInterface, 
    +				   catalogNamePart, schemaNamePart, libNamePart,
    +				   COM_LIBRARY_OBJECT, TRUE, FALSE);
    +  if (retcode < 0)
    +    {
    +      processReturn();
    +      return;
    +    }
    +  
    +  if (retcode == 0) // does not exist
    +    {
    +      CmpCommon::diags()->clear();
    +      *CmpCommon::diags() << DgSqlCode(-1389)
    +			  << DgString0(extLibName);
    +      processReturn();
    +      return;
    +    }
    +  
    +  // strip blank spaces
    +  libFileName = libFileName.strip(NAString::both, ' ');
    +  if (validateLibraryFileExists(libFileName, FALSE))
    +    {
    +      processReturn();
    +      return;
    +    }
    +  
    +  Int32 objectOwnerID = 0;
    +  Int32 schemaOwnerID = 0;
    +  Int64 objectFlags = 0;
    +  Int64 libUID = getObjectInfo(&cliInterface,
    +			       catalogNamePart.data(), schemaNamePart.data(),
    +			       libNamePart.data(), COM_LIBRARY_OBJECT,
    +			       objectOwnerID,schemaOwnerID,objectFlags);
    +  
    +  // Check for error getting metadata information
    +  if (libUID == -1 || objectOwnerID == 0)
    +    {
    +      if (CmpCommon::diags()->getNumber(DgSqlCode::ERROR_) == 0)
    +	SEABASEDDL_INTERNAL_ERROR("getting object UID and owner for alter library");
    +      processReturn();
    +      return;
    +    }
    +  
    +  // Verify that the current user has authority to perform operation
    +  if (!isDDLOperationAuthorized(SQLOperation::ALTER_LIBRARY,
    +				objectOwnerID,schemaOwnerID))
    +    {
    +      *CmpCommon::diags() << DgSqlCode(-CAT_NOT_AUTHORIZED);
    +      processReturn();
    +      return;
    +    }
    +  
    +  Int64 redefTime = NA_JulianTimestamp();
    +    size_t lastSlash = libFileName.last('/');
    +  NAString libNameNoPath;
    +  if (lastSlash != NA_NPOS)
    +    libNameNoPath = libFileName(lastSlash+1, libFileName.length()-lastSlash-1);
    +  else
    +    {
    +      *CmpCommon::diags() << DgSqlCode(-1382)
    +                        << DgString0(libFileName);
    +      processReturn();
    +      return;
    +      
    +    }
    +  char buf[2048]; // filename max length is 512. Additional bytes for long
    +  // library names.
    +  str_sprintf(buf, "update %s.\"%s\".%s set library_filename = '%s' , library_storage
= filetolob('%s') where library_uid = %ld",
    --- End diff --
    
    Maybe a small window where the alter of the library has finished and another process has
started executing but  not yet extracted the library to cache.  Not sure what we can do about
that. If the library is already cached it'll just use the old copy.  I think we'll need to
simulate this and address it separately.. If needed we may need to maintain the old version
of the library. 


---

Mime
View raw message