trafodion-codereview mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From DaveBirdsall <...@git.apache.org>
Subject [GitHub] incubator-trafodion pull request: [TRAFODION-1473] External file s...
Date Thu, 24 Sep 2015 18:11:37 GMT
Github user DaveBirdsall commented on a diff in the pull request:

    https://github.com/apache/incubator-trafodion/pull/89#discussion_r40352013
  
    --- Diff: core/sql/exp/ExpLOBaccess.cpp ---
    @@ -1599,203 +1627,290 @@ Ex_Lob_Error ExLob::readDataToMem(char *memAddr,
         return LOB_DESC_READ_ERROR;
       }
     
    - 
    -
    -
    -      if (!fdData_ || (openFlags_ != O_RDONLY)) 
    -	{
    -	  hdfsCloseFile(fs_, fdData_);
    -	  fdData_=NULL;
    -	  openFlags_ = O_RDONLY;
    -	  fdData_ = hdfsOpenFile(fs_, lobDataFile_, openFlags_, 0, 0, 0);
    -	  if (!fdData_) {
    -	    openFlags_ = -1;
    -	    return LOB_DATA_FILE_OPEN_ERROR;
    -	  }
    -	}
    -     
    -      if (!multipleChunks)
    -	{
    -	  if ((bytesRead = hdfsPread(fs_, fdData_, desc.getOffset() + offset, 
    -				     memAddr, sizeToRead)) == -1) {
    -	  
    -	    return LOB_DATA_READ_ERROR;
    -	  }
    -
    -      
    -	  operLen = bytesRead;
    -	  return LOB_OPER_OK;
    -	}
    -      else
    -	{
    -	  //handle reading the multiple chunks like a cursor
    -	  err = readCursor(memAddr,size, getRequest()->getHandleIn(),
    -			   getRequest()->getHandleInLen(), operLen);
    -	 
    -	 
    -	  if (err==LOB_OPER_OK)
    -	    closeCursor(getRequest()->getHandleIn(), 
    -			getRequest()->getHandleInLen());
    -	  else
    -	    return err;
    -	}
    -      return LOB_OPER_OK;
    -}
    -/*
    -Ex_Lob_Error ExLob::readDataFromFile(char *memAddr, Int64 len, Int64 &operLen)
    -{
    -   int bytesRead;
    -
    -#ifdef SQ_USE_HDFS
    -   if (!fdData_ || (openFlags_ != O_RDONLY)) 
    -   {
    +  if (fdData_)// we may have a stale handle. close and open to refresh 
    +    {
           hdfsCloseFile(fs_, fdData_);
           fdData_=NULL;
           openFlags_ = O_RDONLY;
           fdData_ = hdfsOpenFile(fs_, lobDataFile_, openFlags_, 0, 0, 0);
           if (!fdData_) {
    -         openFlags_ = -1;
    -         return LOB_DATA_FILE_OPEN_ERROR;
    +	openFlags_ = -1;
    +	return LOB_DATA_FILE_OPEN_ERROR;
    +      }
    +    }
    +  else
    +    {
    +      fdData_ = hdfsOpenFile(fs_, lobDataFile_, openFlags_, 0, 0, 0);
    +      if (!fdData_) {
    +	openFlags_ = -1;
    +	return LOB_DATA_FILE_OPEN_ERROR;
    +      }
    +    }
    +  
    +  if (!multipleChunks)
    +    {
    +      if ((bytesRead = hdfsPread(fs_, fdData_, offset, 
    +				 memAddr, size)) == -1) {
    +	  
    +	return LOB_DATA_READ_ERROR;
           }
    -   }
    -   bytesRead = hdfsPread(fs_, fdData_, 0, memAddr, len);
    -#else
    -   bytesRead = pread(fdData_, memAddr, len, 0); 
    -#endif
     
    -   if (bytesRead == -1) {
    -      operLen = 0;
    -      return LOB_DATA_READ_ERROR;
    -   } else {
    +      
           operLen = bytesRead;
    -   }
    -
    -   return LOB_OPER_OK;
    -}
    -
    -*/
    -Ex_Lob_Error ExLob::readDataToLocalFile(char *fileName,  Int64 offset, Int64 &operLen)
    -{ 
    -    Ex_Lob_Error err;
    -
    -    ExLobDesc desc;
    -    err = getDesc(desc);
    -    if (err != LOB_OPER_OK)
    -      return err;
    -
    -    if (offset > desc.getSize())
    -    {
    -      operLen = 0;
           return LOB_OPER_OK;
         }
    -
    -    char *data = (char *)memalign(512, desc.getSize());
    -    if (data == NULL) {
    -      return LOB_SOURCE_DATA_ALLOC_ERROR;
    +  else
    +    {
    +      //handle reading the multiple chunks like a cursor
    +      err = readCursor(memAddr,size, getRequest()->getHandleIn(),
    +		       getRequest()->getHandleInLen(), operLen);
    +	 
    +	 
    +      if (err==LOB_OPER_OK)
    +	closeCursor(getRequest()->getHandleIn(), 
    +		    getRequest()->getHandleInLen());
    +      else
    +	return err;
         }
    +  return LOB_OPER_OK;
    +}
     
    -#ifdef SQ_USE_HDFS
    -    // tbd
    -#else
    -    if (pread(fdData_, data, desc.getSize(), desc.getOffset()) == -1) {
    -      free(data);
    -      return LOB_DATA_READ_ERROR;
    -    }
    -#endif
    + 
     
    -    int openFlags = O_CREAT | O_RDWR ; // O_DIRECT needs mem alignment
    -    int filePerms = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;
    +Ex_Lob_Error ExLob::readDataToLocalFile(char *fileName,  Int64 offset, Int64 size, Int64
&writeOperLen, Int64 lobMaxChunkMemSize, Int32 fileflags)
    +{ 
    +    Ex_Lob_Error err;
    +    Int64 operLen = 0;
    +   
    +    Int64 srcLen = size;
    +    Int64 srcOffset = offset;
    +    Int64 tgtOffset = 0;
    +    char *lobData = 0;
    +    Int64 chunkSize = 0;
     
    +    if (srcLen <=0)
    +       return LOB_SOURCE_DATA_ALLOC_ERROR;
    +    // open the targte file for writing 
    +    int filePerms = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;
    +    int openFlags = O_RDWR ; // O_DIRECT needs mem alignment
    +    if ((LobTgtFileFlags)fileflags == Lob_Append_Or_Error )
    +      openFlags |= O_APPEND;
    +    else
    +      openFlags |= O_TRUNC;
         int fdDestFile = open(fileName, openFlags, filePerms);
    -    if (fdDestFile == -1) {
    -      return LOB_DEST_FILE_OPEN_ERROR;
    -    }
    -
    -    if (pwrite(fdDestFile, data, desc.getSize(), 0) == -1) {
    -      free(data);
    -      close(fdDestFile);
    -      return LOB_DATA_WRITE_ERROR;
    -    }
    +	  
    +    if (fdDestFile >0 )
    --- End diff --
    
    Should this be >= 0? (open could return 0 on success; highly unlikely here because
file descriptor 0 is likely already in use, but conceivable.)


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message