-
Notifications
You must be signed in to change notification settings - Fork 111
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
[ISSUE #2188]💫Remove SyncUnsafeCellWrapper from mmapped_file🍻 #2189
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,7 +32,6 @@ | |
use rocketmq_common::common::message::message_batch::MessageExtBatch; | ||
use rocketmq_common::common::message::message_ext_broker_inner::MessageExtBrokerInner; | ||
use rocketmq_common::UtilAll::ensure_dir_ok; | ||
use rocketmq_rust::SyncUnsafeCellWrapper; | ||
use tracing::debug; | ||
use tracing::error; | ||
use tracing::info; | ||
|
@@ -58,7 +57,7 @@ | |
pub struct DefaultMappedFile { | ||
reference_resource: ReferenceResourceImpl, | ||
file: File, | ||
mmapped_file: SyncUnsafeCellWrapper<MmapMut>, | ||
mmapped_file: MmapMut, | ||
transient_store_pool: Option<TransientStorePool>, | ||
file_name: CheetahString, | ||
file_from_offset: u64, | ||
|
@@ -123,7 +122,7 @@ | |
Self { | ||
reference_resource: ReferenceResourceImpl::new(), | ||
file, | ||
mmapped_file: SyncUnsafeCellWrapper::new(mmap), | ||
mmapped_file: mmap, | ||
file_name, | ||
file_from_offset, | ||
mapped_byte_buffer: None, | ||
|
@@ -205,7 +204,7 @@ | |
start_timestamp: 0, | ||
transient_store_pool: Some(transient_store_pool), | ||
stop_timestamp: 0, | ||
mmapped_file: SyncUnsafeCellWrapper::new(mmap), | ||
mmapped_file: mmap, | ||
} | ||
} | ||
} | ||
|
@@ -695,13 +694,14 @@ | |
#[allow(unused_variables)] | ||
impl DefaultMappedFile { | ||
#[inline] | ||
#[allow(clippy::mut_from_ref)] | ||
pub fn get_mapped_file_mut(&self) -> &mut MmapMut { | ||
self.mmapped_file.mut_from_ref() | ||
unsafe { &mut *(self.mmapped_file.as_ptr() as *mut MmapMut) } | ||
} | ||
|
||
#[inline] | ||
pub fn get_mapped_file(&self) -> &MmapMut { | ||
self.mmapped_file.as_ref() | ||
unsafe { &*(self.mmapped_file.as_ptr() as *const MmapMut) } | ||
Comment on lines
+697
to
+704
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix unsafe mutable reference handling. The current implementation of
Additionally, Consider this safer implementation: -#[allow(clippy::mut_from_ref)]
-pub fn get_mapped_file_mut(&self) -> &mut MmapMut {
- unsafe { &mut *(self.mmapped_file.as_ptr() as *mut MmapMut) }
-}
+pub fn get_mapped_file_mut(&mut self) -> &mut MmapMut {
+ &mut self.mmapped_file
+}
-pub fn get_mapped_file(&self) -> &MmapMut {
- unsafe { &*(self.mmapped_file.as_ptr() as *const MmapMut) }
-}
+pub fn get_mapped_file(&self) -> &MmapMut {
+ &self.mmapped_file
+}
|
||
} | ||
|
||
#[inline] | ||
|
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.
💡 Codebase verification
Confirmed thread-safety issues after SyncUnsafeCellWrapper removal
The verification reveals serious thread-safety concerns:
get_mapped_file_mut()
can create multiple mutable references toMmapMut
, violating Rust's aliasing rulesMmapMut
without synchronization could lead to data races in concurrent scenariosConsider wrapping
MmapMut
in a proper synchronization primitive likeRwLock
to ensure thread-safe access to the memory-mapped content.🔗 Analysis chain
Verify thread-safety after removing SyncUnsafeCellWrapper.
The removal of
SyncUnsafeCellWrapper
might impact thread-safety. Ensure that all access tommapped_file
is properly synchronized through other mechanisms.🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
Length of output: 701
Script:
Length of output: 2497