mirror of
https://github.com/facebook/sapling.git
synced 2024-10-09 16:31:02 +03:00
fd388aac1a
Summary: Implement a new version of data derivation in the derived data manager. This is different from the old version in a few ways: * `derived_data::BonsaiDerivable` is replaced by `derived_data_manager::BonsaiDerivable`. This trait defines both how to perform derivation and how to store and retrieve mapping values. Derivation is performed with reference to the derived data manager, rather than `BlobRepo`. * The old `Mapping` structs and traits are replaced with a direct implementation in the derived data manager, using the `BonsaiDerivable` trait to handle the derived-data-type-specific parts. * The new implementation assumes we will stick with parallel derivation, and doesn't implement serial derivation. Code is copied from the `derived_data` crate, as it is intended to be a replacement once all the derived data types are migrated, and re-using code would create a circular dependency during migration. This only covers the basic derivation implementation used during production. The derived data manager will also take over backfilling, but that will happen in a later diff. Reviewed By: yancouto Differential Revision: D30805046 fbshipit-source-id: b9660dd957fdf762f621b2cb37fc2eea7bf03074
116 lines
2.9 KiB
Rust
116 lines
2.9 KiB
Rust
/*
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
*
|
|
* This software may be used and distributed according to the terms of the
|
|
* GNU General Public License version 2.
|
|
*/
|
|
|
|
use std::sync::Arc;
|
|
|
|
use cacheblob::LeaseOps;
|
|
use changesets::Changesets;
|
|
use metaconfig_types::DerivedDataTypesConfig;
|
|
use mononoke_types::RepositoryId;
|
|
use repo_blobstore::RepoBlobstore;
|
|
use scuba_ext::MononokeScubaSampleBuilder;
|
|
|
|
use crate::lease::DerivedDataLease;
|
|
|
|
pub mod derive;
|
|
pub mod logging;
|
|
pub mod util;
|
|
|
|
/// Manager for derived data.
|
|
///
|
|
/// The manager is responsible for ordering derivation of data based
|
|
/// on the dependencies between derived data types and the changeset
|
|
/// graph.
|
|
#[derive(Clone)]
|
|
pub struct DerivedDataManager {
|
|
inner: Arc<DerivedDataManagerInner>,
|
|
}
|
|
|
|
#[derive(Clone)]
|
|
pub struct DerivedDataManagerInner {
|
|
repo_id: RepositoryId,
|
|
repo_name: String,
|
|
changesets: Arc<dyn Changesets>,
|
|
repo_blobstore: RepoBlobstore,
|
|
lease: DerivedDataLease,
|
|
scuba: MononokeScubaSampleBuilder,
|
|
config: DerivedDataTypesConfig,
|
|
}
|
|
|
|
impl DerivedDataManager {
|
|
pub fn new(
|
|
repo_id: RepositoryId,
|
|
repo_name: String,
|
|
changesets: Arc<dyn Changesets>,
|
|
repo_blobstore: RepoBlobstore,
|
|
lease: Arc<dyn LeaseOps>,
|
|
scuba: MononokeScubaSampleBuilder,
|
|
config: DerivedDataTypesConfig,
|
|
) -> Self {
|
|
let lease = DerivedDataLease::new(lease);
|
|
DerivedDataManager {
|
|
inner: Arc::new(DerivedDataManagerInner {
|
|
repo_id,
|
|
repo_name,
|
|
config,
|
|
changesets,
|
|
repo_blobstore,
|
|
lease,
|
|
scuba,
|
|
}),
|
|
}
|
|
}
|
|
|
|
// For dangerous-override: allow replacement of lease-ops
|
|
pub fn with_replaced_lease(&self, lease: Arc<dyn LeaseOps>) -> Self {
|
|
Self {
|
|
inner: Arc::new(DerivedDataManagerInner {
|
|
lease: DerivedDataLease::new(lease),
|
|
..self.inner.as_ref().clone()
|
|
}),
|
|
}
|
|
}
|
|
|
|
// For dangerous-override: allow replacement of blobstore
|
|
pub fn with_replaced_blobstore(&self, repo_blobstore: RepoBlobstore) -> Self {
|
|
Self {
|
|
inner: Arc::new(DerivedDataManagerInner {
|
|
repo_blobstore,
|
|
..self.inner.as_ref().clone()
|
|
}),
|
|
}
|
|
}
|
|
|
|
pub fn repo_id(&self) -> RepositoryId {
|
|
self.inner.repo_id
|
|
}
|
|
|
|
pub fn repo_name(&self) -> &str {
|
|
self.inner.repo_name.as_str()
|
|
}
|
|
|
|
pub fn changesets(&self) -> &dyn Changesets {
|
|
self.inner.changesets.as_ref()
|
|
}
|
|
|
|
pub fn repo_blobstore(&self) -> &RepoBlobstore {
|
|
&self.inner.repo_blobstore
|
|
}
|
|
|
|
pub fn lease(&self) -> &DerivedDataLease {
|
|
&self.inner.lease
|
|
}
|
|
|
|
pub fn scuba(&self) -> &MononokeScubaSampleBuilder {
|
|
&self.inner.scuba
|
|
}
|
|
|
|
pub fn config(&self) -> &DerivedDataTypesConfig {
|
|
&self.inner.config
|
|
}
|
|
}
|