Просмотр исходного кода

event-graph: Flush sled on prune task stop.

parazyd 2 лет назад
Родитель
Сommit
f6699efea9
3 измененных файлов с 7 добавлено и 6 удалено
  1. 6 4
      src/event_graph2/mod.rs
  2. 0 1
      src/event_graph2/proto.rs
  3. 1 1
      src/event_graph2/tests.rs

+ 6 - 4
src/event_graph2/mod.rs

@@ -91,7 +91,7 @@ impl EventGraph {
     /// * `days_rotation` marks the lifetime of the DAG before it's pruned.
     pub async fn new(
         p2p: P2pPtr,
-        sled_db: &sled::Db,
+        sled_db: sled::Db,
         dag_tree_name: &str,
         days_rotation: u64,
         ex: Arc<Executor<'_>>,
@@ -133,7 +133,7 @@ impl EventGraph {
         prune_task.clone().start(
             self_.clone().dag_prune(days_rotation),
             |_| async move {
-                self__.clone()._handle_stop().await;
+                self__.clone()._handle_stop(sled_db).await;
             },
             Error::DetachedTaskStopped,
             ex.clone(),
@@ -142,8 +142,9 @@ impl EventGraph {
         Ok(self_)
     }
 
-    async fn _handle_stop(&self) {
-        log::warn!("DAG PRUNE TASK STOPPED");
+    async fn _handle_stop(&self, sled_db: sled::Db) {
+        info!(target: "event_graph::_handle_stop()", "[EVENTGRAPH] Prune task stopped, flushing sled");
+        sled_db.flush_async().await.unwrap();
     }
 
     /// Generate a deterministic genesis event corresponding to the DAG's configuration.
@@ -204,6 +205,7 @@ impl EventGraph {
             sleep(s).await;
             debug!(target: "event_graph::dag_prune()", "Rotation period reached. Pruning DAG");
 
+            *self.unreferenced_tips.write().await = HashSet::new();
             self.dag.clear()?;
             self.dag_insert(&current_genesis).await?;
             debug!(target: "event_graph::dag_prune()", "DAG pruned successfully");

+ 0 - 1
src/event_graph2/proto.rs

@@ -17,7 +17,6 @@
  */
 
 use std::{
-    collections::{HashMap, HashSet},
     sync::{
         atomic::{AtomicUsize, Ordering::SeqCst},
         Arc,

+ 1 - 1
src/event_graph2/tests.rs

@@ -114,7 +114,7 @@ async fn eventgraph_propagation_real(ex: Arc<Executor<'static>>) {
         let p2p = P2p::new(settings, ex.clone()).await;
         let sled_db = sled::Config::new().temporary(true).open().unwrap();
         let event_graph =
-            EventGraph::new(p2p.clone(), &sled_db, "dag", 1, ex.clone()).await.unwrap();
+            EventGraph::new(p2p.clone(), sled_db, "dag", 1, ex.clone()).await.unwrap();
         let event_graph_ = event_graph.clone();
 
         // Take the last sled item since there's only 1