Skip to content

Commit b2a9684

Browse files
committed
feat!: [torrust#1491] remove unused torrent repository entry types
Entry types that are not used in production. They have been moved to a new package `torrent-repository-benchmarking`.
1 parent 16a6d08 commit b2a9684

File tree

10 files changed

+80
-482
lines changed

10 files changed

+80
-482
lines changed

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/torrent-repository/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ version.workspace = true
1919
aquatic_udp_protocol = "0"
2020
bittorrent-primitives = "0.1.0"
2121
crossbeam-skiplist = "0"
22-
parking_lot = "0"
2322
tokio = { version = "1", features = ["macros", "net", "rt-multi-thread", "signal", "sync"] }
2423
torrust-tracker-clock = { version = "3.0.0-develop", path = "../clock" }
2524
torrust-tracker-configuration = { version = "3.0.0-develop", path = "../configuration" }

packages/torrent-repository/src/entry/mod.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,8 @@ use torrust_tracker_primitives::{peer, DurationSinceUnixEpoch};
88

99
use self::peer_list::PeerList;
1010

11-
pub mod mutex_parking_lot;
1211
pub mod mutex_std;
13-
pub mod mutex_tokio;
1412
pub mod peer_list;
15-
pub mod rw_lock_parking_lot;
1613
pub mod single;
1714

1815
pub trait Entry {

packages/torrent-repository/src/entry/mutex_parking_lot.rs

Lines changed: 0 additions & 49 deletions
This file was deleted.

packages/torrent-repository/src/entry/mutex_tokio.rs

Lines changed: 0 additions & 49 deletions
This file was deleted.

packages/torrent-repository/src/entry/rw_lock_parking_lot.rs

Lines changed: 0 additions & 49 deletions
This file was deleted.

packages/torrent-repository/src/lib.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,8 @@ pub mod entry;
77
pub mod repository;
88

99
// Repo Entries
10-
1110
pub type EntrySingle = entry::Torrent;
1211
pub type EntryMutexStd = Arc<std::sync::Mutex<entry::Torrent>>;
13-
pub type EntryMutexTokio = Arc<tokio::sync::Mutex<entry::Torrent>>;
14-
pub type EntryMutexParkingLot = Arc<parking_lot::Mutex<entry::Torrent>>;
15-
pub type EntryRwLockParkingLot = Arc<parking_lot::RwLock<entry::Torrent>>;
1612

1713
// Repository
1814
pub type TorrentsSkipMapMutexStd = CrossbeamSkipList<EntryMutexStd>;
Lines changed: 1 addition & 189 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use std::sync::Arc;
2-
31
use bittorrent_primitives::info_hash::InfoHash;
42
use crossbeam_skiplist::SkipMap;
53
use torrust_tracker_configuration::TrackerPolicy;
@@ -10,7 +8,7 @@ use torrust_tracker_primitives::{peer, DurationSinceUnixEpoch, PersistentTorrent
108
use super::Repository;
119
use crate::entry::peer_list::PeerList;
1210
use crate::entry::{Entry, EntrySync};
13-
use crate::{EntryMutexParkingLot, EntryMutexStd, EntryRwLockParkingLot, EntrySingle};
11+
use crate::{EntryMutexStd, EntrySingle};
1412

1513
#[derive(Default, Debug)]
1614
pub struct CrossbeamSkipList<T> {
@@ -140,189 +138,3 @@ where
140138
}
141139
}
142140
}
143-
144-
impl Repository<EntryRwLockParkingLot> for CrossbeamSkipList<EntryRwLockParkingLot>
145-
where
146-
EntryRwLockParkingLot: EntrySync,
147-
EntrySingle: Entry,
148-
{
149-
fn upsert_peer(&self, info_hash: &InfoHash, peer: &peer::Peer, _opt_persistent_torrent: Option<PersistentTorrent>) -> bool {
150-
// todo: load persistent torrent data if provided
151-
152-
let entry = self.torrents.get_or_insert(*info_hash, Arc::default());
153-
entry.value().upsert_peer(peer)
154-
}
155-
156-
fn get_swarm_metadata(&self, info_hash: &InfoHash) -> Option<SwarmMetadata> {
157-
self.torrents.get(info_hash).map(|entry| entry.value().get_swarm_metadata())
158-
}
159-
160-
fn get(&self, key: &InfoHash) -> Option<EntryRwLockParkingLot> {
161-
let maybe_entry = self.torrents.get(key);
162-
maybe_entry.map(|entry| entry.value().clone())
163-
}
164-
165-
fn get_metrics(&self) -> AggregateSwarmMetadata {
166-
let mut metrics = AggregateSwarmMetadata::default();
167-
168-
for entry in &self.torrents {
169-
let stats = entry.value().read().get_swarm_metadata();
170-
metrics.total_complete += u64::from(stats.complete);
171-
metrics.total_downloaded += u64::from(stats.downloaded);
172-
metrics.total_incomplete += u64::from(stats.incomplete);
173-
metrics.total_torrents += 1;
174-
}
175-
176-
metrics
177-
}
178-
179-
fn get_paginated(&self, pagination: Option<&Pagination>) -> Vec<(InfoHash, EntryRwLockParkingLot)> {
180-
match pagination {
181-
Some(pagination) => self
182-
.torrents
183-
.iter()
184-
.skip(pagination.offset as usize)
185-
.take(pagination.limit as usize)
186-
.map(|entry| (*entry.key(), entry.value().clone()))
187-
.collect(),
188-
None => self
189-
.torrents
190-
.iter()
191-
.map(|entry| (*entry.key(), entry.value().clone()))
192-
.collect(),
193-
}
194-
}
195-
196-
fn import_persistent(&self, persistent_torrents: &PersistentTorrents) {
197-
for (info_hash, completed) in persistent_torrents {
198-
if self.torrents.contains_key(info_hash) {
199-
continue;
200-
}
201-
202-
let entry = EntryRwLockParkingLot::new(
203-
EntrySingle {
204-
swarm: PeerList::default(),
205-
downloaded: *completed,
206-
}
207-
.into(),
208-
);
209-
210-
// Since SkipMap is lock-free the torrent could have been inserted
211-
// after checking if it exists.
212-
self.torrents.get_or_insert(*info_hash, entry);
213-
}
214-
}
215-
216-
fn remove(&self, key: &InfoHash) -> Option<EntryRwLockParkingLot> {
217-
self.torrents.remove(key).map(|entry| entry.value().clone())
218-
}
219-
220-
fn remove_inactive_peers(&self, current_cutoff: DurationSinceUnixEpoch) {
221-
for entry in &self.torrents {
222-
entry.value().remove_inactive_peers(current_cutoff);
223-
}
224-
}
225-
226-
fn remove_peerless_torrents(&self, policy: &TrackerPolicy) {
227-
for entry in &self.torrents {
228-
if entry.value().meets_retaining_policy(policy) {
229-
continue;
230-
}
231-
232-
entry.remove();
233-
}
234-
}
235-
}
236-
237-
impl Repository<EntryMutexParkingLot> for CrossbeamSkipList<EntryMutexParkingLot>
238-
where
239-
EntryMutexParkingLot: EntrySync,
240-
EntrySingle: Entry,
241-
{
242-
fn upsert_peer(&self, info_hash: &InfoHash, peer: &peer::Peer, _opt_persistent_torrent: Option<PersistentTorrent>) -> bool {
243-
// todo: load persistent torrent data if provided
244-
245-
let entry = self.torrents.get_or_insert(*info_hash, Arc::default());
246-
entry.value().upsert_peer(peer)
247-
}
248-
249-
fn get_swarm_metadata(&self, info_hash: &InfoHash) -> Option<SwarmMetadata> {
250-
self.torrents.get(info_hash).map(|entry| entry.value().get_swarm_metadata())
251-
}
252-
253-
fn get(&self, key: &InfoHash) -> Option<EntryMutexParkingLot> {
254-
let maybe_entry = self.torrents.get(key);
255-
maybe_entry.map(|entry| entry.value().clone())
256-
}
257-
258-
fn get_metrics(&self) -> AggregateSwarmMetadata {
259-
let mut metrics = AggregateSwarmMetadata::default();
260-
261-
for entry in &self.torrents {
262-
let stats = entry.value().lock().get_swarm_metadata();
263-
metrics.total_complete += u64::from(stats.complete);
264-
metrics.total_downloaded += u64::from(stats.downloaded);
265-
metrics.total_incomplete += u64::from(stats.incomplete);
266-
metrics.total_torrents += 1;
267-
}
268-
269-
metrics
270-
}
271-
272-
fn get_paginated(&self, pagination: Option<&Pagination>) -> Vec<(InfoHash, EntryMutexParkingLot)> {
273-
match pagination {
274-
Some(pagination) => self
275-
.torrents
276-
.iter()
277-
.skip(pagination.offset as usize)
278-
.take(pagination.limit as usize)
279-
.map(|entry| (*entry.key(), entry.value().clone()))
280-
.collect(),
281-
None => self
282-
.torrents
283-
.iter()
284-
.map(|entry| (*entry.key(), entry.value().clone()))
285-
.collect(),
286-
}
287-
}
288-
289-
fn import_persistent(&self, persistent_torrents: &PersistentTorrents) {
290-
for (info_hash, completed) in persistent_torrents {
291-
if self.torrents.contains_key(info_hash) {
292-
continue;
293-
}
294-
295-
let entry = EntryMutexParkingLot::new(
296-
EntrySingle {
297-
swarm: PeerList::default(),
298-
downloaded: *completed,
299-
}
300-
.into(),
301-
);
302-
303-
// Since SkipMap is lock-free the torrent could have been inserted
304-
// after checking if it exists.
305-
self.torrents.get_or_insert(*info_hash, entry);
306-
}
307-
}
308-
309-
fn remove(&self, key: &InfoHash) -> Option<EntryMutexParkingLot> {
310-
self.torrents.remove(key).map(|entry| entry.value().clone())
311-
}
312-
313-
fn remove_inactive_peers(&self, current_cutoff: DurationSinceUnixEpoch) {
314-
for entry in &self.torrents {
315-
entry.value().remove_inactive_peers(current_cutoff);
316-
}
317-
}
318-
319-
fn remove_peerless_torrents(&self, policy: &TrackerPolicy) {
320-
for entry in &self.torrents {
321-
if entry.value().meets_retaining_policy(policy) {
322-
continue;
323-
}
324-
325-
entry.remove();
326-
}
327-
}
328-
}

0 commit comments

Comments
 (0)