Skip to content

Commit 5de500b

Browse files
mononoke: passing LiveCommitSyncConfig all the way to CommitSyncer
Summary: CommitSyncer is a struct that we use to remap a commit from one repo to another. It uses commit sync map to figure out which paths need to be changed. Commit sync mapping might change, and each commit sync mapping has a version associated with it. At the moment CommitSyncer doesn't work correctly if a commit sync mapping is changed. Consider the following DAG ``` large repo A' <- remapped with mapping V1 | O B' <- remapped with mapping V1 | / ... small repo A | O B | / ... ``` We have commit A and B from a small repo remapped into a large repo into commits A' and B'. They were remapped with commit sync mapping V1, which for example remaps files in "dir/" into "smallrepo/dir". Now let's say we start to use a new mapping v2 which remaps "dir/" into "otherdir/". After this point every commit will be created with new mapping. But this is incorrect - if we create a commit on top of B in a small repo that touches "dir/file.txt" then it will be remapped into "otherdir/file.txt" in the large repo, even though every other file is still in "smallrepo/dir"! The fix for this issue is to always use the same mapping as commit parent was using (there are a few tricky cases with merge commits and commits with no parents, but those will be dealt with separately). This diff is the first step - it threads through LiveCommitSyncConfig all the way to the CommitSyncer object, so that CommitSyncer can always fetch whatever mapping it needs. Reviewed By: ikostia Differential Revision: D23845720 fbshipit-source-id: 555cc31fd4ce09f0a6fa2869bfcee2c7cdfbcc61
1 parent 0754074 commit 5de500b

File tree

24 files changed

+161
-56
lines changed

24 files changed

+161
-56
lines changed

eden/mononoke/cmds/admin/crossrepo.rs

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ use metaconfig_types::{CommitSyncConfig, RepoConfig};
2626
use mononoke_types::RepositoryId;
2727
use movers::{get_large_to_small_mover, get_small_to_large_mover};
2828
use slog::{info, warn, Logger};
29+
use std::sync::Arc;
2930
use synced_commit_mapping::{SqlSyncedCommitMapping, SyncedCommitMapping};
3031

3132
use crate::error::SubcommandError;
@@ -51,6 +52,10 @@ pub async fn subcommand_crossrepo<'a>(
5152
matches: &'a ArgMatches<'_>,
5253
sub_m: &'a ArgMatches<'_>,
5354
) -> Result<(), SubcommandError> {
55+
let config_store = args::maybe_init_config_store(fb, &logger, &matches)
56+
.ok_or_else(|| format_err!("Failed initializing ConfigStore"))?;
57+
let live_commit_sync_config = CfgrLiveCommitSyncConfig::new(&logger, &config_store)?;
58+
5459
args::init_cachelib(fb, &matches, None);
5560
let ctx = CoreContext::new_with_logger(fb, logger.clone());
5661
match sub_m.subcommand() {
@@ -74,7 +79,11 @@ pub async fn subcommand_crossrepo<'a>(
7479
target_repo,
7580
&source_repo_config,
7681
)?;
77-
CommitSyncer::new(mapping, commit_sync_repos)
82+
CommitSyncer::new(
83+
mapping,
84+
commit_sync_repos,
85+
Arc::new(live_commit_sync_config),
86+
)
7887
};
7988

8089
let large_hash = {
@@ -106,11 +115,12 @@ pub async fn subcommand_crossrepo<'a>(
106115
target_repo,
107116
mapping,
108117
update_large_repo_bookmarks,
118+
Arc::new(live_commit_sync_config),
109119
)
110120
.await
111121
}
112122
(SUBCOMMAND_CONFIG, Some(sub_sub_m)) => {
113-
run_config_sub_subcommand(fb, ctx, logger, matches, sub_sub_m).await
123+
run_config_sub_subcommand(fb, ctx, matches, sub_sub_m, live_commit_sync_config).await
114124
}
115125
_ => Err(SubcommandError::InvalidArgs),
116126
}
@@ -119,14 +129,11 @@ pub async fn subcommand_crossrepo<'a>(
119129
async fn run_config_sub_subcommand<'a>(
120130
fb: FacebookInit,
121131
ctx: CoreContext,
122-
logger: Logger,
123132
matches: &'a ArgMatches<'_>,
124133
config_subcommand_matches: &'a ArgMatches<'a>,
134+
live_commit_sync_config: CfgrLiveCommitSyncConfig,
125135
) -> Result<(), SubcommandError> {
126136
let repo_id = args::get_repo_id(fb, matches)?;
127-
let config_store = args::maybe_init_config_store(fb, &logger, &matches)
128-
.expect("failed to instantiate ConfigStore");
129-
let live_commit_sync_config = CfgrLiveCommitSyncConfig::new(ctx.logger(), &config_store)?;
130137

131138
match config_subcommand_matches.subcommand() {
132139
(SUBCOMMAND_BY_VERSION, Some(sub_m)) => {
@@ -312,13 +319,15 @@ async fn subcommand_verify_bookmarks(
312319
target_repo: BlobRepo,
313320
mapping: SqlSyncedCommitMapping,
314321
should_update_large_repo_bookmarks: bool,
322+
live_commit_sync_config: Arc<dyn LiveCommitSyncConfig>,
315323
) -> Result<(), SubcommandError> {
316324
let commit_sync_repos = get_large_to_small_commit_sync_repos(
317325
source_repo.clone(),
318326
target_repo.clone(),
319327
&source_repo_config,
320328
)?;
321-
let commit_syncer = CommitSyncer::new(mapping.clone(), commit_sync_repos);
329+
let commit_syncer =
330+
CommitSyncer::new(mapping.clone(), commit_sync_repos, live_commit_sync_config);
322331

323332
let large_repo = commit_syncer.get_large_repo();
324333
let small_repo = commit_syncer.get_small_repo();
@@ -609,6 +618,7 @@ mod test {
609618
use cross_repo_sync::validation::find_bookmark_diff;
610619
use fixtures::{linear, set_bookmark};
611620
use futures_old::stream::Stream;
621+
use live_commit_sync_config::TestLiveCommitSyncConfig;
612622
use maplit::{hashmap, hashset};
613623
use metaconfig_types::{
614624
CommitSyncConfig, CommitSyncConfigVersion, CommitSyncDirection,
@@ -814,6 +824,7 @@ mod test {
814824
},
815825
};
816826

817-
Ok(CommitSyncer::new(mapping, repos))
827+
let live_commit_sync_config = Arc::new(TestLiveCommitSyncConfig::new_empty());
828+
Ok(CommitSyncer::new(mapping, repos, live_commit_sync_config))
818829
}
819830
}

eden/mononoke/commit_rewriting/backsyncer/src/main.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ use stats::prelude::*;
3737
use std::fs::File;
3838
use std::io::{BufRead, BufReader};
3939
use std::str::FromStr;
40+
use std::sync::Arc;
4041
use std::time::Duration;
4142
use synced_commit_mapping::{SqlSyncedCommitMapping, SyncedCommitMapping};
4243

@@ -113,6 +114,7 @@ where
113114
{
114115
let target_repo_id = commit_syncer_args.get_target_repo_id();
115116

117+
let live_commit_sync_config = Arc::new(live_commit_sync_config);
116118
loop {
117119
// We only care about public pushes because draft pushes are not in the bookmark
118120
// update log at all.
@@ -131,7 +133,7 @@ where
131133

132134
let commit_syncer = commit_syncer_args
133135
.clone()
134-
.try_into_commit_syncer(&commit_sync_config)?;
136+
.try_into_commit_syncer(&commit_sync_config, live_commit_sync_config.clone())?;
135137

136138
backsync_latest(
137139
ctx.clone(),
@@ -289,7 +291,8 @@ fn main(fb: FacebookInit) -> Result<(), Error> {
289291
let ctx = session_container.new_context(logger.clone(), scuba_sample);
290292
let commit_sync_config =
291293
live_commit_sync_config.get_current_commit_sync_config(&ctx, target_repo_id)?;
292-
let commit_syncer = commit_syncer_args.try_into_commit_syncer(&commit_sync_config)?;
294+
let commit_syncer = commit_syncer_args
295+
.try_into_commit_syncer(&commit_sync_config, Arc::new(live_commit_sync_config))?;
293296

294297
let db_config = target_repo_config.storage_config.metadata;
295298
let target_repo_dbs = runtime.block_on_std(
@@ -355,7 +358,8 @@ fn main(fb: FacebookInit) -> Result<(), Error> {
355358
let ctx = session_container.new_context(logger, ScubaSampleBuilder::with_discard());
356359
let commit_sync_config =
357360
live_commit_sync_config.get_current_commit_sync_config(&ctx, target_repo_id)?;
358-
let commit_syncer = commit_syncer_args.try_into_commit_syncer(&commit_sync_config)?;
361+
let commit_syncer = commit_syncer_args
362+
.try_into_commit_syncer(&commit_sync_config, Arc::new(live_commit_sync_config))?;
359363

360364
let inputfile = sub_m
361365
.value_of(ARG_INPUT_FILE)

eden/mononoke/commit_rewriting/backsyncer/src/tests.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ use futures::{
2626
};
2727
use futures_ext::spawn_future;
2828
use futures_old::{future, stream::Stream as OldStream};
29+
use live_commit_sync_config::TestLiveCommitSyncConfig;
2930
use manifest::{Entry, ManifestOps};
3031
use maplit::btreemap;
3132
use mercurial_types::HgChangesetId;
@@ -904,8 +905,9 @@ async fn init_repos(
904905
)
905906
.await;
906907

908+
let live_commit_sync_config = Arc::new(TestLiveCommitSyncConfig::new_empty());
907909
// Sync first commit manually
908-
let commit_syncer = CommitSyncer::new(mapping.clone(), repos);
910+
let commit_syncer = CommitSyncer::new(mapping.clone(), repos, live_commit_sync_config);
909911
let initial_bcs_id = source_repo
910912
.get_bonsai_from_hg(
911913
ctx.clone(),
@@ -1197,7 +1199,8 @@ async fn init_merged_repos(
11971199
version_name: CommitSyncConfigVersion("TEST_VERSION_NAME".to_string()),
11981200
};
11991201

1200-
let commit_syncer = CommitSyncer::new(mapping.clone(), repos);
1202+
let live_commit_sync_config = Arc::new(TestLiveCommitSyncConfig::new_empty());
1203+
let commit_syncer = CommitSyncer::new(mapping.clone(), repos, live_commit_sync_config);
12011204
output.push((commit_syncer, small_repo_dbs));
12021205

12031206
let filename = format!("file_in_smallrepo{}", small_repo.get_repoid().id());
@@ -1433,7 +1436,8 @@ async fn preserve_premerge_commit(
14331436
version_name: CommitSyncConfigVersion("TEST_VERSION_NAME".to_string()),
14341437
};
14351438

1436-
CommitSyncer::new(mapping.clone(), repos)
1439+
let live_commit_sync_config = Arc::new(TestLiveCommitSyncConfig::new_empty());
1440+
CommitSyncer::new(mapping.clone(), repos, live_commit_sync_config)
14371441
};
14381442

14391443
small_to_large_sync_config

eden/mononoke/commit_rewriting/bookmarks_validator/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,10 @@ fn get_commit_syncer<'a>(
106106
let target_repo_id = args::get_target_repo_id(ctx.fb, &matches)?;
107107
let config_store = args::maybe_init_config_store(ctx.fb, &logger, &matches)
108108
.ok_or_else(|| format_err!("Failed initializing ConfigStore"))?;
109-
let live_commit_sync_config = CfgrLiveCommitSyncConfig::new(&logger, &config_store)?;
109+
let live_commit_sync_config = Arc::new(CfgrLiveCommitSyncConfig::new(&logger, &config_store)?);
110110
let commit_sync_config =
111111
live_commit_sync_config.get_current_commit_sync_config(&ctx, target_repo_id)?;
112-
commit_syncer_args.try_into_commit_syncer(&commit_sync_config)
112+
commit_syncer_args.try_into_commit_syncer(&commit_sync_config, live_commit_sync_config)
113113
}
114114

115115
async fn loop_forever<M: SyncedCommitMapping + Clone + 'static>(

eden/mononoke/commit_rewriting/commit_validator/src/validation.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,7 @@ impl ValidationHelpers {
662662
self.large_repo.0.clone(),
663663
&commit_sync_config,
664664
self.mapping.clone(),
665+
Arc::new(self.live_commit_sync_config.clone()),
665666
)
666667
}
667668
}

eden/mononoke/commit_rewriting/cross_repo_sync/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ blobsync = { path = "../../blobrepo/blobsync" }
2121
bookmark_renaming = { path = "../bookmark_renaming" }
2222
bookmarks = { path = "../../bookmarks" }
2323
context = { path = "../../server/context" }
24+
live_commit_sync_config = { path = "../live_commit_sync_config" }
2425
manifest = { path = "../../manifest" }
2526
mercurial_types = { path = "../../mercurial/types" }
2627
metaconfig_types = { path = "../../metaconfig/types" }

eden/mononoke/commit_rewriting/cross_repo_sync/src/commit_syncer_args.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@
77

88
use anyhow::Error;
99
use blobrepo::BlobRepo;
10+
use live_commit_sync_config::LiveCommitSyncConfig;
1011
use metaconfig_types::CommitSyncConfig;
1112
use mononoke_types::RepositoryId;
1213
use std::fmt;
14+
use std::sync::Arc;
1315
use synced_commit_mapping::SyncedCommitMapping;
1416

1517
use crate::{CommitSyncRepos, CommitSyncer};
@@ -50,6 +52,8 @@ impl<T: SyncedCommitMapping + Clone + 'static> CommitSyncerArgs<T> {
5052
pub fn try_into_commit_syncer(
5153
self,
5254
commit_sync_config: &CommitSyncConfig,
55+
// TODO(stash): remove commit_sync_config and use just live_commit_sync_config
56+
live_commit_sync_config: Arc<dyn LiveCommitSyncConfig>,
5357
) -> Result<CommitSyncer<T>, Error> {
5458
let Self {
5559
source_repo,
@@ -58,7 +62,11 @@ impl<T: SyncedCommitMapping + Clone + 'static> CommitSyncerArgs<T> {
5862
} = self;
5963

6064
let commit_sync_repos = CommitSyncRepos::new(source_repo, target_repo, commit_sync_config)?;
61-
Ok(CommitSyncer::new(mapping, commit_sync_repos))
65+
Ok(CommitSyncer::new(
66+
mapping,
67+
commit_sync_repos,
68+
live_commit_sync_config,
69+
))
6270
}
6371
}
6472

eden/mononoke/commit_rewriting/cross_repo_sync/src/lib.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ use futures::{
2828
};
2929
use futures_old::Future;
3030
use futures_old::Stream as StreamOld;
31+
use live_commit_sync_config::LiveCommitSyncConfig;
3132
use manifest::get_implicit_deletes;
3233
use maplit::{hashmap, hashset};
3334
use mercurial_types::HgManifestId;
@@ -42,6 +43,7 @@ use movers::{get_movers, Movers};
4243
use pushrebase::{do_pushrebase_bonsai, PushrebaseError};
4344
use slog::info;
4445
use std::collections::{BTreeMap, HashMap};
46+
use std::sync::Arc;
4547
use std::{collections::VecDeque, fmt};
4648
use synced_commit_mapping::{
4749
EquivalentWorkingCopyEntry, SyncedCommitMapping, SyncedCommitMappingEntry,
@@ -485,6 +487,7 @@ pub struct CommitSyncer<M> {
485487
// TODO: Finish refactor and remove pub
486488
pub mapping: M,
487489
pub repos: CommitSyncRepos,
490+
live_commit_sync_config: Arc<dyn LiveCommitSyncConfig>,
488491
}
489492

490493
impl<M> fmt::Debug for CommitSyncer<M>
@@ -502,8 +505,16 @@ impl<M> CommitSyncer<M>
502505
where
503506
M: SyncedCommitMapping + Clone + 'static,
504507
{
505-
pub fn new(mapping: M, repos: CommitSyncRepos) -> Self {
506-
Self { mapping, repos }
508+
pub fn new(
509+
mapping: M,
510+
repos: CommitSyncRepos,
511+
live_commit_sync_config: Arc<dyn LiveCommitSyncConfig>,
512+
) -> Self {
513+
Self {
514+
mapping,
515+
repos,
516+
live_commit_sync_config,
517+
}
507518
}
508519

509520
pub fn get_source_repo(&self) -> &BlobRepo {
@@ -1253,7 +1264,7 @@ where
12531264
source_bcs_id: ChangesetId,
12541265
maybe_target_bcs_id: Option<ChangesetId>,
12551266
) -> Result<(), Error> {
1256-
let CommitSyncer { repos, mapping } = self.clone();
1267+
let CommitSyncer { repos, mapping, .. } = self.clone();
12571268
let (source_repo, target_repo, source_is_large) = match repos {
12581269
CommitSyncRepos::LargeToSmall {
12591270
large_repo,
@@ -1488,6 +1499,7 @@ pub fn create_commit_syncers<M>(
14881499
large_repo: BlobRepo,
14891500
commit_sync_config: &CommitSyncConfig,
14901501
mapping: M,
1502+
live_commit_sync_config: Arc<dyn LiveCommitSyncConfig>,
14911503
) -> Result<Syncers<M>, Error>
14921504
where
14931505
M: SyncedCommitMapping + Clone + 'static,
@@ -1523,10 +1535,12 @@ where
15231535
let large_to_small_commit_syncer = CommitSyncer {
15241536
mapping: mapping.clone(),
15251537
repos: large_to_small_commit_sync_repos,
1538+
live_commit_sync_config: live_commit_sync_config.clone(),
15261539
};
15271540
let small_to_large_commit_syncer = CommitSyncer {
15281541
mapping,
15291542
repos: small_to_large_commit_sync_repos,
1543+
live_commit_sync_config: live_commit_sync_config.clone(),
15301544
};
15311545

15321546
Ok(Syncers {

eden/mononoke/commit_rewriting/cross_repo_sync/src/validation.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,7 @@ mod test {
654654
use fbinit::FacebookInit;
655655
use fixtures::linear;
656656
use futures_old::stream::Stream;
657+
use live_commit_sync_config::TestLiveCommitSyncConfig;
657658
use metaconfig_types::{CommitSyncConfigVersion, CommitSyncDirection};
658659
use mononoke_types::{MPath, RepositoryId};
659660
use revset::AncestorsNodeStream;
@@ -863,6 +864,7 @@ mod test {
863864
},
864865
};
865866

866-
Ok(CommitSyncer::new(mapping, repos))
867+
let live_commit_sync_config = Arc::new(TestLiveCommitSyncConfig::new_empty());
868+
Ok(CommitSyncer::new(mapping, repos, live_commit_sync_config))
867869
}
868870
}

eden/mononoke/commit_rewriting/cross_repo_sync/test/main.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
use bytes::Bytes;
1313
use fbinit::FacebookInit;
14-
use maplit::{btreemap, hashmap};
1514
use std::collections::BTreeMap;
1615
use std::str::FromStr;
1716
use std::sync::Arc;
@@ -28,6 +27,8 @@ use cross_repo_sync_test_utils::rebase_root_on_master;
2827

2928
use fixtures::{linear, many_files_dirs};
3029
use futures::compat::Future01CompatExt;
30+
use live_commit_sync_config::TestLiveCommitSyncConfig;
31+
use maplit::{btreemap, hashmap};
3132
use mercurial_types::HgChangesetId;
3233
use metaconfig_types::{
3334
CommitSyncConfig, CommitSyncConfigVersion, CommitSyncDirection,
@@ -239,7 +240,8 @@ fn create_small_to_large_commit_syncer(
239240

240241
let commit_sync_config = create_commit_sync_config(small_repo_id, large_repo_id, prefix)?;
241242
let repos = CommitSyncRepos::new(small_repo, large_repo, &commit_sync_config)?;
242-
Ok(CommitSyncer::new(mapping, repos))
243+
let live_commit_sync_config = Arc::new(TestLiveCommitSyncConfig::new_empty());
244+
Ok(CommitSyncer::new(mapping, repos, live_commit_sync_config))
243245
}
244246

245247
fn create_large_to_small_commit_syncer(
@@ -253,7 +255,8 @@ fn create_large_to_small_commit_syncer(
253255

254256
let commit_sync_config = create_commit_sync_config(small_repo_id, large_repo_id, prefix)?;
255257
let repos = CommitSyncRepos::new(large_repo, small_repo, &commit_sync_config)?;
256-
Ok(CommitSyncer::new(mapping, repos))
258+
let live_commit_sync_config = Arc::new(TestLiveCommitSyncConfig::new_empty());
259+
Ok(CommitSyncer::new(mapping, repos, live_commit_sync_config))
257260
}
258261

259262
#[fbinit::compat_test]

0 commit comments

Comments
 (0)