- 
                Notifications
    You must be signed in to change notification settings 
- Fork 1k
Replace Arc with Box in ArrowArray for FFI structs #1432
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Closed
      
      
    
  
     Closed
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            8 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      ec345d8
              
                Replace Arc with Box
              
              
                viirya 62e0e26
              
                fix
              
              
                viirya 3996942
              
                Update
              
              
                viirya 3a8aa49
              
                Fix
              
              
                viirya ba4ac68
              
                Fix format
              
              
                viirya 412aab7
              
                Merge remote-tracking branch 'upstream/master' into remove_arc_from_ffi
              
              
                viirya 9f4126a
              
                Rebased
              
              
                viirya e10b1d6
              
                Update pyarrow
              
              
                viirya File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why we need to change ArrayData::try_from() to have &? This line seems very tricky.
And as we change the ArrayData::try_from() API, all other users may also need to change the code and also add this tricky line.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since
ArrayData::try_from()movesffi::ArrowArray, it will drop theArrowArrayand triggerreleasefor the structs (as they are justBoxpointers now). Users cannot prevent it happened. For example, without this change, our internal usecase got a SIGSEGV.So I change it to a borrowed reference to avoid dropping/releasing there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @viirya , understand the issue here.
I'm not sure if #1441 this can be the solution? Or even we can add a ArrowArray::try_from_box() to do the similar thing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so.
Arc::from(Box::from_raw(array as *mut FFI_ArrowArray))isArc<Box<FFI_ArrowArray>>. Then the raw pointer is*Box<FFI_ArrowArray>, but you treat it as*FFI_ArrowArray.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I'm wrong. I'm not aware that there is
from(v: Box<T>)API in Arc.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previously you don't need it. As
Arcis kept in the created Buffer of Array data, you can rely on deallocation of the Buffer to callreleaseof such ffi structs.But
Boxcannot give us such benefit. So it makes the management more explicit and relying on users. We need to keep these structs soreleasewon't be called, before we don't need the Array data (Buffer).The code is at
ArrowArrayRef.to_data. It is to create anArrayDatafrom anArrowArray(Ref). And you can followbuffers->create_buffer->Buffer::from_unowned.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, thanks for the explanation.
I'm wondering if we can still use
Arcbut drop the "envelop memory" allocated for the struct holding the actual pointers, for the input array and schema. For example:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks close to previous suggestion
Arc::fromas it also copies bytes from source structs. But it causes SIGSEGV. I will try to test this.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've tried it. It seems okay.
Arc::frompreviously not work, I think, is because it calls allocator to deallocate the memory allocation. As it is allocated by Java in our case, we cannot let Rust to deallocate it.std::ptr::drop_in_placeseems only trigger dropping. As we make it as empty structs, it won't triggerrelease. I think this is close to #1436 which cleans upreleasefield of source structs after cloning it. Here we in fact still clone it, but just internally and don't exposeclone.Looks good to me. Thanks @sunchao .
cc @alamb @wangfenjin WDYT? Are you agreed with this approach?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The suggested approach is at #1449.