Commit Graph

32 Commits

Author SHA1 Message Date
Kostia Balytskyi
0e26c82bba mononoke: add a few bits to CommitSyncer
Summary:
Instead of doing `commit_syncer.get_bookmark_renamer()(&bookmark)` everywhere,
let's allow to just do `commit_syncer.rename_bookmark(&bookmark)`.

Also, let's add helper methods for fetching repo ids.
Also, let's `impl Debug` to use it in logs.

Reviewed By: farnz

Differential Revision: D18353939

fbshipit-source-id: 1cebcad4a8c1523064580594e392b901566d3c28
2019-11-07 01:49:44 -08:00
Stanislau Hlebik
67a443199f mononoke: megarepo wc verifier
Summary:
A tool that checks that files in a commit from a large repo match files from a
corresponding commit in a small repo.

The tool does verification in a few stages:
1) Fetch paths and filenodes for small and large repo
2) Move all paths in the large repo
3) For each path check if we have the same path in small repo. If we don't
print a warning
4) For each filenode that are different also compare their content ids, and
repo an error only if content ids are different

Note that we can't rely just on filenode id comparison, because it turns out
that filenodes can legitimately be different between large and small repo.
We could also just compare the content ids, but that's much slower.

Reviewed By: krallin

Differential Revision: D18268939

fbshipit-source-id: 14f091db380e127ce2d926253376fbc0cf1e30b3
2019-11-05 11:06:56 -08:00
Stanislau Hlebik
8c0516b50b mononoke: cleanup compat function
Summary:
Use idea suggested by krallin in https://fburl.com/diff/j1pl3kvl, it looks
much nicer.

Reviewed By: krallin

Differential Revision: D18303027

fbshipit-source-id: efcc1f7b618dedda1801320f71914018668acc64
2019-11-04 11:22:52 -08:00
Kostia Balytskyi
33847d05ec mononoke: change RepoSyncTarget to contain CommitSyncer
Summary:
1. `CommitSyncer` seems to be the struct that hides all the lowly implementation
details of how commits are synced across repos, so let's make `RepoSyncTarget` own it, rather than
explicit `Mover` instances.
1. while we're at that, let's make `CommitSyncRepos` own `BookmarkRenamer` the
same way it owns `Mover`.

Reviewed By: StanislavGlebik

Differential Revision: D18274007

fbshipit-source-id: 4451980a0714220933a0583a8f964e4278bf1594
2019-11-04 06:31:29 -08:00
Stanislau Hlebik
7fe4d855a1 mononoke: use synced_working_copy_equivalence to compute get_commit_sync_outcome
Reviewed By: ikostia

Differential Revision: D18169229

fbshipit-source-id: d4d50133538d042c6fe1aab2e40c32c8332a8f85
2019-10-30 10:53:00 -07:00
Stanislau Hlebik
3bebf38753 mononoke: add synced_working_copy_equivalence table
Summary:
This table is needed for backsyncer to track commits that are "equivalent"
between large ans small repo i.e. the closest ancestor ancestor of large commit
that was rewritten in the small repo.

It's very similar to normal `synced_commit_mapping`, but with a few important differences:

1) Small bcs id can be NULL, meaning that commit from large repo doesn't remap to any commit from the small repo [1]
2) Multiple large bcs ids can point to the same small bcs id
3) Inserting new entry in synced_commit_mapping  automatically inserts entry in synced_working_copy_equivalence - if a commit was remapped, then it's by definition an equivalent working copy

Reviewed By: ikostia

Differential Revision: D18172894

fbshipit-source-id: 14d5f692521282223778e8c9ad46191d0e24d618
2019-10-29 07:11:10 -07:00
Stanislau Hlebik
e7f69ccbc2 mononoke: remove unused methods from SyncedCommitMapping
Summary:
We are not using them now, and we decide to use them later we can always add
the back

Reviewed By: aslpavel

Differential Revision: D18169226

fbshipit-source-id: 9b964abde2eda4361ad9610075e37d3b11bd0efe
2019-10-28 04:22:07 -07:00
Stanislau Hlebik
0890ed888b CommitSyncConfig is ambiguous - rename the active one to CommitSyncer
Summary: We're centralising all the commit syncing work in one place, which we called the CommitSyncConfig. This conflicts with the metaconfig CommitSyncConfig, so rename the one that does work to CommitSyncer

Reviewed By: farnz

Differential Revision: D18139821

fbshipit-source-id: 804e293e30167aa36a0818d297dbfd0594f41118
2019-10-28 02:33:51 -07:00
Stanislau Hlebik
2e0ea74101 Avoid recursing in get_commit_sync_outcome
Summary: By looking at whether an ancestor should be synced and is synced, we can get to the same conclusion as before, but faster. In particular, when you have lots of commits to sync, this rapidly notices that we have an ancestor that needs syncing, and says that we can't decide on this commit until that ancestor is synced

Reviewed By: farnz

Differential Revision: D18139085

fbshipit-source-id: 8b7459bafe287f1d7664f8606489dd1c26713637
2019-10-28 01:56:28 -07:00
Stanislau Hlebik
cfbaf17bd8 mononoke: backsyncer with commit rewriting
Summary:
Use functionality added in D18121305 to implement backsyncer that knows how to
rewrite commits (previously it was just copying commits from one repo to
another).

Note that tests were rewritten from scratch, and one of the tests was removed
without replacement - the one that tests backsyncer on diamond merges. It won't
work right now because there are known innefficiencies in
`get_commit_sync_outcome()`, which will be addressed later.

Reviewed By: farnz

Differential Revision: D18134820

fbshipit-source-id: f1ee39842f7e89d057d5be58667dab739df97b95
2019-10-25 09:26:12 -07:00
Simon Farnsworth
1a523a31f8 Add in cross-repo sync logic needed for back syncing
Summary:
When syncing large to small, we need to distinguish several states: Do I need to sync this commit? Can I sync this commit now? Will there be parent changes involved?

Add `CommitSyncOutcome` to answer this question, and start heading towards a state where commit syncing is contained in a single crate

Reviewed By: StanislavGlebik

Differential Revision: D18121305

fbshipit-source-id: 302b30d98ba1ff2b3e59ab9a40d49b3252686e7f
2019-10-25 06:55:53 -07:00
Stanislau Hlebik
eee72e2a04 mononoke: fail if parent commit hasn't been remapped
Summary:
We've changed data model to make sure we have entry for all pre-big merge
commits. This diff removes the checks for non-remapped commits in the target repo - those
shouldn't be necessary anymore.

Reviewed By: farnz

Differential Revision: D18084127

fbshipit-source-id: 6fa00ac59f5d0806035b1a4f590344e800a4c174
2019-10-23 08:30:41 -07:00
Stanislau Hlebik
c91aaf3bf2 mononoke: make recursion limit optional
Reviewed By: krallin

Differential Revision: D17977964

fbshipit-source-id: cc4e6c93d377e598d494f8374b994095b14fecde
2019-10-18 03:41:32 -07:00
Stanislau Hlebik
74f329c0b7 mononoke: backsync commits as well
Summary:
Now find new commits (i.e. commits from source_repo that are not in target
repo) and backsync them

Reviewed By: krallin

Differential Revision: D17930706

fbshipit-source-id: ca08f2b8c644a4dbab6edec5019e4445f5c5b011
2019-10-17 00:44:46 -07:00
Kostia Balytskyi
937488b097 mononoke: move sync direction into small repo commit sync config
Summary:
In the multi-directional-sync world it is not enough to have a single direction
specified for all small repos, let's move it to the small repo config level.

This prompts some changes in how we do verification:
- no overlapping prefixes are allowed among all small repos with small-to-large
  sync direction (when small repos tail into the large repo, we cannot deny
  a pushrebase because of the path conflicts (since the small repo has already
  accepted the commit in the past), so let's prohibit path conflicts in the first place)
- no overlapping prefixes are allowed between *all* small-to-large repos and
  *each* large-to-small repo (same reason, we cannot reject tailed commits,
  so we need to protect ourselves from path conflicts)
- overlapping *is* allowed between large-to-small repos, but only when used
  prefixes are identical, not when one prefix is a prefix of another prefix.
  To be clear, I am not certain that we cannot accommodate the latter case,
  but I just want to avoid additional complexity so far. Overlapped prefixes
  represent the "locked across repos" directories: ones, which can be changed
  from each of the small repos as part of a push redirector pushrebase

Reviewed By: StanislavGlebik

Differential Revision: D17930877

fbshipit-source-id: 97f0ab8f5975f9635e84716851fe42c8cc8800f5
2019-10-16 08:11:03 -07:00
Kostia Balytskyi
9040ebbf6e mononoke: do not use i32 instead of RepositoryId
Summary:
While we have the `RepositoryId` dedicated type, the `RepoConfig` struct used
`i32` for its `repoid` field, so in a lot of places, which referenced or used
this config we continued to use `i32`. This is sad, so let's fix this.

This diff changes `RepoConfig` and everything that depends on it.
Ideally we would also just remove the `.id()` method of the `RepositoryId`
struct, so that our clients have to use the struct, but in a few places it
is deserialized into thift/SQL types, so unless we move those transformations
into the same file (which also seems bad and not future-proof), we cannot get
rid of the method.

Reviewed By: farnz

Differential Revision: D17928574

fbshipit-source-id: 3d9355272cfcd20af787edd6417cc529be640356
2019-10-16 08:11:03 -07:00
Stanislau Hlebik
210459de03 mononoke: basic support for merges in x_repo_sync tool
Summary:
It handles only very specific case of merges - repo imports e.g. no ancestor of
p2 has a parent that's ancestor of p1. Also at the moment it doesn't support
Mover that removes a p2's ancestor commit.

There's no reason to not add support for both of these cases later though.

Reviewed By: ikostia

Differential Revision: D17899741

fbshipit-source-id: 7d96c9dd13790e1fd8ee96a9d2f486d56e25abf9
2019-10-15 11:02:13 -07:00
Andres Suarez
cf36295fa4 Yearless license header
Summary:
This diff updates all license headers to use the new text and style.
Also, a few internal files were missing the header, but now they have it.
`fbcode/common/rust/netstring/` had the internal header, but now it has
GPLV2PLUS - since that goes to Mononoke's Github too.

Differential Revision: D17881539

fbshipit-source-id: b70d2ee41d2019fc7c2fe458627f0f7c01978186
2019-10-11 13:52:34 -07:00
Kostia Balytskyi
f031f1aabe mononoke: add bookmark renamers to commit_rewriting
Summary:
Similarly to `Mover`, which acts on paths according to the sync config,
we need a `BookmarkRenamer`, which acts on bookmark names.

The logic now supports two types of bookmark configs:
- common pushrebase bookmarks: they are common for all small repos and they
  don't get renamed. `master` is one example of those, and I don't know if
  there can be any other :)
- prefixes: when the bookmark is updated in the small repo, an equivalent,
  but prefixed bookmark is updated in the large repo. Correspondingly, when
  a prefixed bookmark is updated in a large repo, an equivalent, but unprefixed
  bookmark is updated in the small repo.

There are also "error" cases:
- bookmark is neither common pushrebase, nor prefixed with the correct small
  repo's prefix. In that case we plan not to update that bookmark (although,
  create the corresponding commit(we may have to be careful and make it draft
  instead of public or something like this))

Reviewed By: krallin

Differential Revision: D17877749

fbshipit-source-id: 6e2f67456de354c2358376e5762fabffe0de3a42
2019-10-11 10:25:57 -07:00
Stanislau Hlebik
4bb6c0ee4c mononoke: slightly simplify rewrite_commit function
Summary:
Previously function remapped each copy_from changeset separately, however this
is not necessary. copy_from changeset is guaranteed to be one of the parents
(see https://fburl.com/0i80ojja).

This diff simplifies the function a bit by not doing a separate remap for
copy_from changesets

Reviewed By: farnz

Differential Revision: D17779792

fbshipit-source-id: c4c64bdc295858289a26e1d5b229ced6eca96414
2019-10-09 13:48:59 -07:00
Kostia Balytskyi
198b4cf69d mononoke: add phase preservation to cross-repo commit sync job
Reviewed By: farnz

Differential Revision: D17601085

fbshipit-source-id: bd01d51a8f7dcb157bb7d4b9c3eb92436886a97d
2019-09-26 14:47:12 -07:00
Kostia Balytskyi
9f7ba4b676 mononoke: add a cross-repo sync tailer
Reviewed By: farnz

Differential Revision: D17155814

fbshipit-source-id: a13f951662a9d035ed6ef9d077923d60da23687c
2019-09-26 14:47:12 -07:00
Kostia Balytskyi
7b9612738d mononoke: add find_first_synced query to synced_commit_mapping
Summary:
Given a list of changesets, a source and a target repo id, this query tells
you the first changeset from the list, which comes from the source repo and
has a synced equivalent in the target repo. Here, the word "first" refers to
the order of changesets in the provided list.

The naming is a little unfortunate, as the use case for this query is to
find the *last* (meaning newest) changeset that had been synced. But I wanted
the name to reflect this particular fn's behavior, rather than the intended
use.

Reviewed By: farnz

Differential Revision: D17600505

fbshipit-source-id: ea7336dcf839302e7b9ca6e1bc2ee88a3a1d99a9
2019-09-26 14:47:11 -07:00
Simon Farnsworth
632beb5550 Make sqlite synced_commit_mapping align with D17526345
Summary: We've improved the MySQL version in review - make the SQLite version match, to avoid nasty test/prod issues

Reviewed By: StanislavGlebik

Differential Revision: D17528682

fbshipit-source-id: 498467210608cce0ec27d014d64a22115355cda2
2019-09-23 13:40:05 -07:00
Kostia Balytskyi
daf9b3d79a mononoke: migrate cross_repo_sync to Movers instead of the impl Fns
Summary: Let's have all concerned parties use the same type under the same name.

Reviewed By: farnz

Differential Revision: D17481135

fbshipit-source-id: d0a99cce19fa0941d351f5754ed4517aea6a6105
2019-09-23 11:10:20 -07:00
Simon Farnsworth
484cd850f3 Add missing task link to commit sync code
Summary: This got amended into the wrong commit - land it so that we've got it

Reviewed By: krallin

Differential Revision: D17426107

fbshipit-source-id: 4bb2fcae1d7ea2db5378f39ec0f22c2abf225d74
2019-09-17 11:48:28 -07:00
Simon Farnsworth
b47d522fb8 Sync commits between two repos
Summary: To make merges into our final megarepo world Just Work, we want to sustain an interim period where the legacy repo is still present and up to date. Provide a way to do this by having Mononoke internally remap and pushrebase commits so that we can have two repos kept in sync.

Reviewed By: ikostia, StanislavGlebik

Differential Revision: D16918280

fbshipit-source-id: c7a8d1bb1b1972cb5609490b8fd5b759cb5f9cdd
2019-09-17 08:45:21 -07:00
Kostia Balytskyi
dc93d0c873 mononoke: implement logic to build movers from configs
Summary:
`movers` are functions, that we use to shift file paths when syncing commits.
These functions should be automatically buildable from repo-sync configs
for both small-to-large and large-to-small sync directions.

Reviewed By: farnz

Differential Revision: D17395844

fbshipit-source-id: 25ec9b06ba5908d8c125702a712b3cf782ccffca
2019-09-17 07:06:14 -07:00
Simon Farnsworth
895fd8135b Switch new tests back to async-unit
Summary: `async-unit` no longer has the old problems around deadlock - instead, it runs the tests in a Tokio runtime and threads the failure state (if any) back to the test runner. Use it.

Reviewed By: StanislavGlebik

Differential Revision: D16937389

fbshipit-source-id: 81b87a32b9c8ffdfd4a2033d10809cdcdb39898b
2019-09-16 06:23:25 -07:00
David Tolnay
713973975d Replace *fbinit::FACEBOOK with #[fbinit::main]
Summary:
This diff moves initFacebook calls that used to happen just before FFI calls to instead happen at the beginning of main.

The basic assumption of initFacebook is that it happens at the beginning of main before there are additional threads. It must be allowed to modify process-global state like env vars or gflags without the possibility of a data race from other code concurrently reading those things. As such, the previous approach of calling initFacebook through `*fbinit::FACEBOOK` near FFI calls was prone to race conditions.

The new approach is based on attribute macros added in D17245802.

 ---

The primary remaining situations that still require `*fbinit::FACEBOOK` are when we don't directly control the function arguments surrounding the call to C++, such as in lazy_static:

    lazy_static! {
        static ref S: Ty = {
            let _ = *fbinit::FACEBOOK;
            /* call C++ */
        };
    }

and quickcheck:

    quickcheck! {
        fn f(/* args that impl Arbitrary */) {
            let _ = *fbinit::FACEBOOK;
            /* call C++ */
        }
    }

I will revisit these in a separate diff. They are a small fraction of total uses of fbinit.

Reviewed By: Imxset21

Differential Revision: D17328504

fbshipit-source-id: f80edb763e7f42b3216552dd32f1ea0e6cc8fd12
2019-09-13 20:17:29 -07:00
David Tolnay
ecc30ffe8a Delete lines of the form "use [a-z_]+;"
Summary: I think these are left over from pre-2018 code where they may have been necessary. In 2018 edition, import paths in `use` always begin with a crate name or `crate`/`super`/`self`, so `use $ident;` always refers to a crate. Since extern crates are always in scope in every module, `use $ident` does nothing.

Reviewed By: Imxset21

Differential Revision: D17290473

fbshipit-source-id: 23d86e5d0dcd5c2d4e53c7a36b4267101dd4b45c
2019-09-10 15:06:19 -07:00
Simon Farnsworth
13008dece8 Mapping for commit syncing to identify commits by source repo
Summary: When we sync commits, we will need to be able to cross-reference the commits between the source repo and the target repo. Make it easy to track this mapping.

Reviewed By: StanislavGlebik

Differential Revision: D16896918

fbshipit-source-id: 3738cf2067291f16ce9b62509763ac526d1d35c2
2019-08-20 13:25:54 -07:00