You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iggy.apache.org by hg...@apache.org on 2025/07/05 11:44:52 UTC
(iggy) 01/01: fix(io_uring): make MemoryPool not hang when used as buffer for read_exact
This is an automated email from the ASF dual-hosted git repository.
hgruszecki pushed a commit to branch io_uring_tpc_memorypool
in repository https://gitbox.apache.org/repos/asf/iggy.git
commit 39a47d6c3073f0510e5aa489d3b392aa5ef71fee
Author: Hubert Gruszecki <h....@gmail.com>
AuthorDate: Sat Jul 5 13:42:44 2025 +0200
fix(io_uring): make MemoryPool not hang when used as buffer for read_exact
---
core/server/src/streaming/utils/memory_pool.rs | 14 +++-----------
core/server/src/streaming/utils/pooled_buffer.rs | 10 ++++++++--
2 files changed, 11 insertions(+), 13 deletions(-)
diff --git a/core/server/src/streaming/utils/memory_pool.rs b/core/server/src/streaming/utils/memory_pool.rs
index 16ad2087..e3524c53 100644
--- a/core/server/src/streaming/utils/memory_pool.rs
+++ b/core/server/src/streaming/utils/memory_pool.rs
@@ -156,20 +156,12 @@ impl MemoryPool {
/// Initialize the global pool from the given config.
pub fn init_pool(config: Arc<SystemConfig>) {
// TODO: Fixme (stary napraw).
- let is_enabled = false;
+ let is_enabled = config.memory_pool.enabled;
let memory_limit = config.memory_pool.size.as_bytes_usize();
let bucket_capacity = config.memory_pool.bucket_capacity as usize;
- let pool = MemoryPool::new(is_enabled, memory_limit, bucket_capacity);
- if MEMORY_POOL.set(pool).is_err() {
- warn!("Memory pool already initialized.");
- // This shouldn't ever happen in production code, only in tests
- // if someone forgets to add #[serial] tag to tests that have different
- // memory pool limits (different instances are created within same executable).
- if memory_pool().memory_limit != memory_limit {
- panic!("Previously initialized memory pool has a different limit.");
- }
- }
+ let _ =
+ MEMORY_POOL.get_or_init(|| MemoryPool::new(is_enabled, memory_limit, bucket_capacity));
}
/// Acquire a `BytesMut` buffer with at least `capacity` bytes.
diff --git a/core/server/src/streaming/utils/pooled_buffer.rs b/core/server/src/streaming/utils/pooled_buffer.rs
index 39ef25be..ec9d45f1 100644
--- a/core/server/src/streaming/utils/pooled_buffer.rs
+++ b/core/server/src/streaming/utils/pooled_buffer.rs
@@ -229,7 +229,7 @@ impl SetBufInit for PooledBuffer {
unsafe impl IoBufMut for PooledBuffer {
fn as_buf_mut_ptr(&mut self) -> *mut u8 {
- self.inner.as_buf_mut_ptr()
+ self.inner.as_mut_ptr()
}
}
@@ -243,6 +243,12 @@ unsafe impl IoBuf for PooledBuffer {
}
fn buf_capacity(&self) -> usize {
- self.inner.capacity()
+ // When buffer is pre-initialized with set_len, we should report
+ // the length as capacity to prevent over-reading
+ if self.inner.len() > 0 {
+ self.inner.len()
+ } else {
+ self.inner.capacity()
+ }
}
}