Skip to content

Commit d98a116

Browse files
committed
fix
1 parent e3eb005 commit d98a116

File tree

4 files changed

+23
-15
lines changed

4 files changed

+23
-15
lines changed

scripts/tests/calibnet_other_check.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ fi
2727
forest_check_db_stats
2828
echo "Run snapshot GC"
2929
forest_run_snap_gc
30-
sleep 5
30+
forest_wait_api
3131
echo "Wait the node to sync"
3232
forest_wait_for_sync
3333
forest_check_db_stats

src/cli/subcommands/chain_cmd/prune.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,18 @@ use std::time::Duration;
88
#[derive(Debug, Subcommand)]
99
pub enum ChainPruneCommands {
1010
/// Run snapshot GC
11-
Snap,
11+
Snap {
12+
#[arg(long)]
13+
no_wait: bool,
14+
},
1215
}
1316

1417
impl ChainPruneCommands {
1518
pub async fn run(self, client: rpc::Client) -> anyhow::Result<()> {
1619
match self {
17-
Self::Snap => {
20+
Self::Snap { no_wait } => {
1821
client
19-
.call(ChainPruneSnapshot::request(())?.with_timeout(Duration::MAX))
22+
.call(ChainPruneSnapshot::request((!no_wait,))?.with_timeout(Duration::MAX))
2023
.await?;
2124
}
2225
}

src/db/gc/snapshot.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,18 @@ where
8787
}
8888
}
8989

90-
pub fn trigger(&self) -> flume::Receiver<()> {
91-
let (progress_tx, progress_rx) = flume::unbounded();
92-
*self.progress_tx.write() = Some(progress_tx);
90+
pub fn trigger(&self) -> anyhow::Result<flume::Receiver<()>> {
91+
if self.running.load(Ordering::Relaxed) {
92+
anyhow::bail!("snap gc has already been running");
93+
}
94+
9395
if self.trigger_tx.try_send(()).is_err() {
94-
tracing::warn!("snap gc has already been triggered");
96+
anyhow::bail!("snap gc has already been triggered");
9597
}
96-
progress_rx
98+
99+
let (progress_tx, progress_rx) = flume::unbounded();
100+
*self.progress_tx.write() = Some(progress_tx);
101+
Ok(progress_rx)
97102
}
98103

99104
async fn export_snapshot(&self) -> anyhow::Result<()> {

src/rpc/methods/chain.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -196,22 +196,22 @@ impl RpcMethod<1> for ChainGetMessagesInTipset {
196196
}
197197

198198
pub enum ChainPruneSnapshot {}
199-
impl RpcMethod<0> for ChainPruneSnapshot {
199+
impl RpcMethod<1> for ChainPruneSnapshot {
200200
const NAME: &'static str = "Forest.SnapshotGC";
201-
const PARAM_NAMES: [&'static str; 0] = [];
201+
const PARAM_NAMES: [&'static str; 1] = ["blocking"];
202202
const API_PATHS: BitFlags<ApiPaths> = ApiPaths::all();
203203
const PERMISSION: Permission = Permission::Admin;
204204

205-
type Params = ();
205+
type Params = (bool,);
206206
type Ok = ();
207207

208208
async fn handle(
209209
_ctx: Ctx<impl Blockstore + Send + Sync + 'static>,
210-
(): Self::Params,
210+
(blocking,): Self::Params,
211211
) -> Result<Self::Ok, ServerError> {
212212
if let Some(gc) = crate::daemon::GLOBAL_SNAPSHOT_GC.get() {
213-
let progress_rx = gc.trigger();
214-
while progress_rx.recv_async().await.is_ok() {}
213+
let progress_rx = gc.trigger()?;
214+
while blocking && progress_rx.recv_async().await.is_ok() {}
215215
Ok(())
216216
} else {
217217
Err(anyhow::anyhow!("snapshot gc is not enabled").into())

0 commit comments

Comments
 (0)