dag: add DagImportCloneData::import_clone_data

Summary:
This method reconstructs a dag from clone data.

At the moment we only have a clone data construction method in Mononoke. It's
the Dags job to construct and import the clone_data. We'll consolidate that at
a later time.

Reviewed By: quark-zju

Differential Revision: D24954823

fbshipit-source-id: fe92179ec80f71234fc8f1cf7709f5104aabb4fb
This commit is contained in:
Stefan Filip 2020-12-01 09:57:24 -08:00 committed by Facebook GitHub Bot
parent 042dcbb3a8
commit 8327c54db1
2 changed files with 24 additions and 0 deletions

View File

@ -9,6 +9,7 @@
//!
//! Combination of IdMap and IdDag.
use crate::clone::CloneData;
use crate::delegate;
use crate::errors::bug;
use crate::errors::programming;
@ -24,6 +25,7 @@ use crate::nameset::hints::Hints;
use crate::nameset::NameSet;
use crate::ops::DagAddHeads;
use crate::ops::DagAlgorithm;
use crate::ops::DagImportCloneData;
use crate::ops::DagPersistent;
use crate::ops::IdConvert;
use crate::ops::IdMapSnapshot;
@ -227,6 +229,21 @@ where
}
}
impl<IS, M, P, S> DagImportCloneData for AbstractNameDag<IdDag<IS>, M, P, S>
where
IS: IdDagStore,
M: IdMapAssignHead,
{
fn import_clone_data(&mut self, clone_data: CloneData<VertexName>) -> Result<()> {
for (id, name) in clone_data.idmap {
self.map.insert(id, name.as_ref())?;
}
self.dag
.build_segments_volatile_from_prepared_flat_segments(&clone_data.flat_segments)?;
Ok(())
}
}
impl<IS, M, P, S> AbstractNameDag<IdDag<IS>, M, P, S>
where
IS: IdDagStore,

View File

@ -7,6 +7,7 @@
//! DAG and Id operations (mostly traits)
use crate::clone::CloneData;
use crate::default_impl;
use crate::id::Group;
use crate::id::Id;
@ -169,6 +170,12 @@ pub trait DagAddHeads {
F: Fn(VertexName) -> Result<Vec<VertexName>>;
}
/// Import a generated `CloneData` object into the DAG.
pub trait DagImportCloneData {
/// Updates the DAG using a `CloneData` object.
fn import_clone_data(&mut self, clone_data: CloneData<VertexName>) -> Result<()>;
}
/// Persistent the DAG on disk.
pub trait DagPersistent {
/// Write in-memory DAG to disk. This might also pick up changes to