You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "westonpace (via GitHub)" <gi...@apache.org> on 2025/05/30 17:28:07 UTC

[PR] Add a strong_count method to Buffer [arrow-rs]

westonpace opened a new pull request, #7569:
URL: https://github.com/apache/arrow-rs/pull/7569

   # Which issue does this PR close?
   
   Closes #7568.
   
   # Rationale for this change
    
   See issue
   
   # What changes are included in this PR?
   
   Adds a `strong_count` method to `Buffer`
   
   # Are there any user-facing changes?
   
   There is a new public method.  There is no change to any existing behavior.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add a strong_count method to Buffer [arrow-rs]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb merged PR #7569:
URL: https://github.com/apache/arrow-rs/pull/7569


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add a strong_count method to Buffer [arrow-rs]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #7569:
URL: https://github.com/apache/arrow-rs/pull/7569#discussion_r2118171609


##########
arrow-buffer/src/buffer/immutable.rs:
##########
@@ -125,6 +125,15 @@ impl Buffer {
         self.data.ptr()
     }
 
+    /// Returns the number of strong references to the buffer.
+    ///
+    /// This method is safe but if the buffer is shared across mulitple threads

Review Comment:
   I looked around and could not find any way to avoid the potential race condition. 
   
   The only thing I can think of is `into_inner()` that woudl return the inner `Arc<Bytes>` but confusingly I think the `Bytes` is an internal implementation detail that we shouldn't expose



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add a strong_count method to Buffer [arrow-rs]

Posted by "westonpace (via GitHub)" <gi...@apache.org>.
westonpace commented on code in PR #7569:
URL: https://github.com/apache/arrow-rs/pull/7569#discussion_r2123775720


##########
arrow-buffer/src/buffer/immutable.rs:
##########
@@ -125,6 +125,15 @@ impl Buffer {
         self.data.ptr()
     }
 
+    /// Returns the number of strong references to the buffer.
+    ///
+    /// This method is safe but if the buffer is shared across mulitple threads

Review Comment:
   I'm pretty sure even `into_inner` would have the potential race condition as this message was mostly just copying the warning from `Arc`'s [`strong_count`](https://doc.rust-lang.org/std/sync/struct.Arc.html#method.strong_count): 
   
   > This method by itself is safe, but using it correctly requires extra care. Another thread can change the strong count at any time, including potentially between calling this method and acting on the result.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add a strong_count method to Buffer [arrow-rs]

Posted by "mbrobbel (via GitHub)" <gi...@apache.org>.
mbrobbel commented on code in PR #7569:
URL: https://github.com/apache/arrow-rs/pull/7569#discussion_r2120467023


##########
arrow-buffer/src/buffer/immutable.rs:
##########
@@ -125,6 +125,15 @@ impl Buffer {
         self.data.ptr()
     }
 
+    /// Returns the number of strong references to the buffer.
+    ///
+    /// This method is safe but if the buffer is shared across mulitple threads

Review Comment:
   ```suggestion
       /// This method is safe but if the buffer is shared across multiple threads
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add a strong_count method to Buffer [arrow-rs]

Posted by "westonpace (via GitHub)" <gi...@apache.org>.
westonpace commented on code in PR #7569:
URL: https://github.com/apache/arrow-rs/pull/7569#discussion_r2123775720


##########
arrow-buffer/src/buffer/immutable.rs:
##########
@@ -125,6 +125,15 @@ impl Buffer {
         self.data.ptr()
     }
 
+    /// Returns the number of strong references to the buffer.
+    ///
+    /// This method is safe but if the buffer is shared across mulitple threads

Review Comment:
   I'm pretty sure even `into_inner` would have the potential race condition as this message was mostly just copying the warning from `Arc`'s [`strong_count`](https://doc.rust-lang.org/std/sync/struct.Arc.html#method.strong_count) :laughing: : 
   
   > This method by itself is safe, but using it correctly requires extra care. Another thread can change the strong count at any time, including potentially between calling this method and acting on the result.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org