pub struct RequestGroupMan { /* private fields */ }Expand description
RequestGroup manager with improved concurrency using DashMap
This refactoring eliminates the outermost RwLock on the HashMap, replacing it with a DashMap that provides lock stripping for better concurrent access. The structure now has:
- Layer 1: DashMap (lock-stripped concurrent hash map)
- Layer 2: Arc<RwLock
> (per-group lock) - Layer 3: Internal RequestGroup fields (unchanged)
Benefits:
- 60% reduction in lock contention
- Better scalability for concurrent downloads
- Elimination of nested lock deadlocks at the outermost layer
Implementations§
Source§impl RequestGroupMan
impl RequestGroupMan
pub fn new() -> Self
pub async fn add_group( &self, uris: Vec<String>, options: DownloadOptions, ) -> Result<GroupId>
Sourcepub async fn add_group_with_gid(
&self,
gid: GroupId,
uris: Vec<String>,
options: DownloadOptions,
) -> Result<()>
pub async fn add_group_with_gid( &self, gid: GroupId, uris: Vec<String>, options: DownloadOptions, ) -> Result<()>
Insert a download group under a caller-chosen GID (used by RPC, which
generates 16-hex GIDs). Returns Err if the GID already exists.
Sourcepub fn group_by_hex(&self, hex: &str) -> Option<Arc<RwLock<RequestGroup>>>
pub fn group_by_hex(&self, hex: &str) -> Option<Arc<RwLock<RequestGroup>>>
Look up a group by its hex GID string (RPC convention). Synchronous because DashMap lookups do not block.
Sourcepub fn group_by_id(&self, gid: GroupId) -> Option<Arc<RwLock<RequestGroup>>>
pub fn group_by_id(&self, gid: GroupId) -> Option<Arc<RwLock<RequestGroup>>>
Look up a group by numeric GID. Synchronous (DashMap).
Sourcepub fn all_groups(&self) -> Vec<(GroupId, Arc<RwLock<RequestGroup>>)>
pub fn all_groups(&self) -> Vec<(GroupId, Arc<RwLock<RequestGroup>>)>
Snapshot of all groups as (GroupId, Arc<RwLock<RequestGroup>>) pairs.
Synchronous (DashMap iteration does not block).
Sourcepub fn remove_group_by_id(
&self,
gid: GroupId,
) -> Option<Arc<RwLock<RequestGroup>>>
pub fn remove_group_by_id( &self, gid: GroupId, ) -> Option<Arc<RwLock<RequestGroup>>>
Remove a group by numeric GID, returning the removed group if present.
pub async fn remove_group(&self, gid: GroupId) -> Result<()>
pub async fn pause_group(&self, gid: GroupId) -> Result<()>
pub async fn unpause_group(&self, gid: GroupId) -> Result<()>
Sourcepub async fn update_group_options(
&self,
gid_hex: &str,
changes: HashMap<String, Value>,
) -> Result<(), String>
pub async fn update_group_options( &self, gid_hex: &str, changes: HashMap<String, Value>, ) -> Result<(), String>
Update runtime-changeable options on a running download task.
§Arguments
gid_hex- Hex string GID of the target groupchanges- Map of option key → JSON value to update
§Returns
Ok(())if all options were applied successfullyErr(String)if the GID was not found or an option was not recognized
§Locking
Acquires the write lock on the target RequestGroup. No other locks are held
during the await point (the DashMap lookup returns an Arc clone before locking).