support for multiple heads in BonsaiDerived::find_all_underived_ancestors

Summary: Support for multiple heads in `BonsaiDerived::find_all_underived_ancestors`. This change will be needed to remove manual step of fetching of all changesets in `backfill_derived_data` utilty.

Reviewed By: StanislavGlebik

Differential Revision: D23705295

fbshipit-source-id: 32aa97a77f0a4461cbe4bf1864477e3e121e1879
This commit is contained in:
Pavel Aslanov 2020-09-15 09:19:40 -07:00 committed by Facebook GitHub Bot
parent d7081f6aba
commit 92b09459f0
3 changed files with 26 additions and 11 deletions

View File

@ -83,9 +83,15 @@ pub fn derive_impl<
) -> impl Future<Item = Derived, Error = DeriveError> {
async move {
let derivation = async {
let all_csids =
find_topo_sorted_underived(&ctx, &repo, &derived_mapping, &start_csid, None, mode)
.await?;
let all_csids = find_topo_sorted_underived(
&ctx,
&repo,
&derived_mapping,
Some(start_csid),
None,
mode,
)
.await?;
for csid in &all_csids {
ctx.scuba().clone().log_with_msg(
@ -168,11 +174,12 @@ fn fail_if_disabled<Derived: BonsaiDerived>(repo: &BlobRepo) -> Result<(), Deriv
pub(crate) async fn find_topo_sorted_underived<
Derived: BonsaiDerived,
Mapping: BonsaiDerivedMapping<Value = Derived> + Send + Sync + Clone + 'static,
Changesets: IntoIterator<Item = ChangesetId>,
>(
ctx: &CoreContext,
repo: &BlobRepo,
derived_mapping: &Mapping,
start_csid: &ChangesetId,
start_csids: Changesets,
limit: Option<u64>,
mode: Mode,
) -> Result<Vec<ChangesetId>, Error> {
@ -187,7 +194,7 @@ pub(crate) async fn find_topo_sorted_underived<
let changeset_fetcher = &changeset_fetcher;
let visited = &visited;
let commits_not_derived_to_parents =
bounded_traversal::bounded_traversal_stream(100, Some(*start_csid), {
bounded_traversal::bounded_traversal_stream(100, start_csids, {
move |cs_id| {
async move {
if let Some(limit) = limit {

View File

@ -109,11 +109,11 @@ pub trait BonsaiDerived: Sized + 'static + Send + Sync + Clone {
limit: u64,
) -> Result<u64, DeriveError> {
let mapping = Self::mapping(&ctx, &repo);
let underived = derive_impl::find_topo_sorted_underived::<Self, Self::Mapping>(
let underived = derive_impl::find_topo_sorted_underived::<Self, Self::Mapping, _>(
ctx,
repo,
&mapping,
csid,
Some(*csid),
Some(limit),
Mode::OnlyIfEnabled,
)
@ -121,17 +121,21 @@ pub trait BonsaiDerived: Sized + 'static + Send + Sync + Clone {
Ok(underived.len() as u64)
}
/// Find all underived ancestors reachable from provided set of changesets.
///
/// Items are returned in topologically sorted order starting from changesets
/// with no dependencies or derived dependencies.
async fn find_all_underived_ancestors(
ctx: &CoreContext,
repo: &BlobRepo,
csid: &ChangesetId,
csids: Vec<ChangesetId>,
) -> Result<Vec<ChangesetId>, DeriveError> {
let mapping = Self::mapping(&ctx, &repo);
let underived = derive_impl::find_topo_sorted_underived::<Self, Self::Mapping>(
let underived = derive_impl::find_topo_sorted_underived::<Self, Self::Mapping, _>(
ctx,
repo,
&mapping,
csid,
csids,
None,
Mode::OnlyIfEnabled,
)

View File

@ -250,7 +250,11 @@ where
) -> Result<Option<BonsaiChangeset>, Error> {
let mut underived_ancestors = vec![];
for cs_id in csids {
underived_ancestors.push(M::Value::find_all_underived_ancestors(&ctx, &repo, cs_id));
underived_ancestors.push(M::Value::find_all_underived_ancestors(
&ctx,
&repo,
vec![*cs_id],
));
}
let boxed_stream = stream::iter(underived_ancestors)