You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@trafodion.apache.org by "ASF GitHub Bot (JIRA)" <ji...@apache.org> on 2018/10/01 20:37:01 UTC

[jira] [Commented] (TRAFODION-3216) UDR libraries need to be stored in metadata table as a blob

    [ https://issues.apache.org/jira/browse/TRAFODION-3216?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16634607#comment-16634607 ] 

ASF GitHub Bot commented on TRAFODION-3216:
-------------------------------------------

Github user zellerh commented on a diff in the pull request:

    https://github.com/apache/trafodion/pull/1721#discussion_r221740561
  
    --- 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 --
    
    This brings up a question: It looks like we overwrite the LIBRARIES row when we alter a library. That means that if the old library is not already cached, it will no longer be available. Initially, I thought that we might keep the old version available in the metadata, but maybe that's too complicated. Do you think we could run into an error in the following situation:
    
    ```
    Process a: prepare s from call sp1();
    Process b: alter library lib1 .... ; -- lib1 is the library for sp1
    Process a: execute s;
    ```
    
    Now, if we assume that the jar file for lib1 is not yet in the cache, executing s will try to extract it, but it won't find it in the metadata anymore - assuming that updating the table will invalidate the LOB handle we used for the previous version?


> UDR libraries need to be stored in metadata table as a blob
> -----------------------------------------------------------
>
>                 Key: TRAFODION-3216
>                 URL: https://issues.apache.org/jira/browse/TRAFODION-3216
>             Project: Apache Trafodion
>          Issue Type: Improvement
>          Components: sql-general
>    Affects Versions: 2.4
>            Reporter: Sandhya Sundaresan
>            Assignee: Sandhya Sundaresan
>            Priority: Major
>             Fix For: 2.4
>
>         Attachments: Support for LOB storage in metadata for UDR libraries.docx
>
>
> This is one of many  infrastructure changes for SPJs that was planned. 
>  * {color:#0070c0}Store UDR libraries in BLOBs   {color}
>  * {color:#0070c0}Add BLOB column to library metadata table{color}
>  * {color:#0070c0}Change CREATE LIBRARY command to store library in BLOB{color}
>  * {color:#0070c0}Change library file names to include the timestamp (so updating a library changes the name){color}
>  * {color:#0070c0}Add a cache for libraries (a new directory, $TRAF_HOME/udr/public/lib){color}
>  * {color:#0070c0}Change UDR code to read library from the metadata table when not in cache{color}
>  * {color:#0070c0}Upgrade support{color}
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)