Skip to content
This repository has been archived by the owner on Apr 29, 2024. It is now read-only.

Commit

Permalink
node: Populate refs db on startup
Browse files Browse the repository at this point in the history
If the refs database is empty, populate it on startup.
Also includes a script to clear it.
  • Loading branch information
cloudhead committed Apr 5, 2024
1 parent 6be77ca commit ad7ba82
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
13 changes: 13 additions & 0 deletions radicle-node/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,19 @@ where
let nid = self.node_id();
self.started_at = Some(time);

// Populate refs database. This is only useful as part of the upgrade process for nodes
// that have been online since before the refs database was created.
match self.db.refs().count() {
Ok(0) => {
info!(target: "service", "Empty refs database, populating from storage..");
if let Err(e) = self.db.refs_mut().populate(&self.storage) {
error!(target: "service", "Failed to populate refs database: {e}");
}
}
Ok(n) => debug!(target: "service", "Refs database has {n} cached references"),
Err(e) => error!(target: "service", "Error checking refs database: {e}"),
}

// Ensure that our local node is in our address database.
self.db
.addresses_mut()
Expand Down
18 changes: 18 additions & 0 deletions scripts/clear-refs-db.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/sh
set -e

DB="$(rad path)/node/node.db"

if command -v sqlite3 >/dev/null 2>&1; then
if [ -f "$DB" ]; then
echo -n "Clearing 'refs' table from $DB.. "
sqlite3 $DB "DELETE FROM refs;"
echo "done."
else
echo "fatal: database file does not exist"
exit 1
fi
else
echo "fatal: sqlite3 is not installed"
exit 1
fi

0 comments on commit ad7ba82

Please sign in to comment.