Skip to content

Commit 672dfaa

Browse files
committed
Merge #1509: Fix wrong number of downloads when the tracker starts
632185b refactor: tracing spwams to use structure formats (Jose Celano) ced2788 fix: [#1502] import torrents' download counters from DB (Jose Celano) 46c7eae dev: enable persistence for downdloads in dev config (Jose Celano) Pull request description: Relates to: #1502 As described [here](#1502 (comment)), when you start the tracker and stats persistence is enabled, you should see the last value for the number of downloads. Instead, you see something like this: ![image](https://github.com/user-attachments/assets/9fffeb7f-5666-41f0-ac64-7049a6225a17) This PR fixes that problem. It fixes the bug described in #1502. However, it does not fix other problems described in the issue (problem 3). I will open a new PR to fix problem 3. ACKs for top commit: josecelano: ACK 632185b Tree-SHA512: 5234afb19f35368c3fa678ab064aaa4f011c743b353ec5ffc4282c6bafffca3689068d9f85f5b26f9115a412952bd844862ca497c8c1c5040c01d396acf82d39
2 parents 627d535 + 632185b commit 672dfaa

File tree

4 files changed

+18
-8
lines changed

4 files changed

+18
-8
lines changed

packages/torrent-repository/src/swarms.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ impl Swarms {
231231
inactive_peers_removed += removed;
232232
}
233233

234-
tracing::info!("Inactive peers removed: {inactive_peers_removed}");
234+
tracing::info!(inactive_peers_removed = inactive_peers_removed);
235235

236236
Ok(inactive_peers_removed)
237237
}
@@ -262,7 +262,7 @@ impl Swarms {
262262
peerless_torrents_removed += 1;
263263
}
264264

265-
tracing::info!("Peerless torrents removed: {peerless_torrents_removed}");
265+
tracing::info!(peerless_torrents_removed = peerless_torrents_removed);
266266

267267
Ok(peerless_torrents_removed)
268268
}
@@ -291,7 +291,7 @@ impl Swarms {
291291
torrents_imported += 1;
292292
}
293293

294-
tracing::info!("Imported torrents: {torrents_imported}");
294+
tracing::info!(imported_torrents = torrents_imported);
295295

296296
torrents_imported
297297
}

packages/tracker-core/src/torrent/manager.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ impl TorrentsManager {
6060
}
6161
}
6262

63-
/// Loads torrents from the persistent database into the in-memory repository.
63+
/// Loads torrents from the database into the in-memory repository.
6464
///
6565
/// This function retrieves the list of persistent torrent entries (which
6666
/// include only the aggregate metrics, not the detailed peer lists) from
@@ -70,8 +70,7 @@ impl TorrentsManager {
7070
///
7171
/// Returns a `databases::error::Error` if unable to load the persistent
7272
/// torrent data.
73-
#[allow(dead_code)]
74-
pub(crate) fn load_torrents_from_database(&self) -> Result<(), databases::error::Error> {
73+
pub fn load_torrents_from_database(&self) -> Result<(), databases::error::Error> {
7574
let persistent_torrents = self.db_torrent_repository.load_all()?;
7675

7776
self.in_memory_torrent_repository.import_persistent(&persistent_torrents);

share/default/config/tracker.development.sqlite3.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ threshold = "info"
1111
listed = false
1212
private = false
1313

14-
#[core.tracker_policy]
14+
[core.tracker_policy]
1515
#max_peer_timeout = 30
16-
#persistent_torrent_completed_stat = true
16+
persistent_torrent_completed_stat = true
1717
#remove_peerless_torrents = true
1818

1919
[[udp_trackers]]

src/app.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ pub async fn start(config: &Configuration, app_container: &Arc<AppContainer>) ->
6161
async fn load_data_from_database(config: &Configuration, app_container: &Arc<AppContainer>) {
6262
load_peer_keys(config, app_container).await;
6363
load_whitelisted_torrents(config, app_container).await;
64+
load_torrents_from_database(config, app_container);
6465
}
6566

6667
async fn start_jobs(config: &Configuration, app_container: &Arc<AppContainer>) -> JobManager {
@@ -109,6 +110,16 @@ async fn load_whitelisted_torrents(config: &Configuration, app_container: &Arc<A
109110
}
110111
}
111112

113+
fn load_torrents_from_database(config: &Configuration, app_container: &Arc<AppContainer>) {
114+
if config.core.tracker_policy.persistent_torrent_completed_stat {
115+
app_container
116+
.tracker_core_container
117+
.torrents_manager
118+
.load_torrents_from_database()
119+
.expect("Could not load torrents from database.");
120+
}
121+
}
122+
112123
fn start_http_core_event_listener(config: &Configuration, app_container: &Arc<AppContainer>, job_manager: &mut JobManager) {
113124
let opt_handle = jobs::http_tracker_core::start_event_listener(config, app_container);
114125

0 commit comments

Comments
 (0)