mirror of
https://github.com/facebook/sapling.git
synced 2024-09-11 10:36:52 +03:00
repo_client: move unbundle commit limit to config
Summary: Replace the `unbundle_limit_num_of_commits_in_push` tunable with repo-level configuration. Reviewed By: gustavoavena Differential Revision: D52201415 fbshipit-source-id: da7fa9a0360901657701904b9d0e4733aac7a5b5
This commit is contained in:
parent
ac41c66632
commit
dc2c2a638c
@ -1,4 +1,4 @@
|
||||
// @generated SignedSource<<3ba4ba16bcf3fa0b0f0edc2a7df07f72>>
|
||||
// @generated SignedSource<<09e30cbe0a30f657920fbddcbf0e80f9>>
|
||||
// DO NOT EDIT THIS FILE MANUALLY!
|
||||
// This file is a mechanical copy of the version in the configerator repo. To
|
||||
// modify it, edit the copy in the configerator repo instead and copy it over by
|
||||
@ -501,7 +501,9 @@ struct RawStorageConfig {
|
||||
|
||||
struct RawPushParams {
|
||||
1: optional bool pure_push_allowed;
|
||||
// 2: deleted
|
||||
// 2: deleted
|
||||
/// The maximum number of commits that will be accepted in a single unbundle request
|
||||
3: optional i64 unbundle_commit_limit;
|
||||
} (rust.exhaustive)
|
||||
|
||||
struct RawPushrebaseRemoteModeLocal {} (rust.exhaustive)
|
||||
|
@ -1158,6 +1158,7 @@ mod test {
|
||||
],
|
||||
push: PushParams {
|
||||
pure_push_allowed: false,
|
||||
unbundle_commit_limit: None,
|
||||
},
|
||||
pushrebase: PushrebaseParams {
|
||||
flags: PushrebaseFlags {
|
||||
|
@ -231,6 +231,10 @@ impl Convert for RawPushParams {
|
||||
let default = PushParams::default();
|
||||
Ok(PushParams {
|
||||
pure_push_allowed: self.pure_push_allowed.unwrap_or(default.pure_push_allowed),
|
||||
unbundle_commit_limit: self
|
||||
.unbundle_commit_limit
|
||||
.map(|limit| limit.try_into())
|
||||
.transpose()?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -612,12 +612,15 @@ pub struct HookParams {
|
||||
pub struct PushParams {
|
||||
/// Whether normal non-pushrebase pushes are allowed
|
||||
pub pure_push_allowed: bool,
|
||||
/// Limit of commits in a single unbundle
|
||||
pub unbundle_commit_limit: Option<u64>,
|
||||
}
|
||||
|
||||
impl Default for PushParams {
|
||||
fn default() -> Self {
|
||||
PushParams {
|
||||
pure_push_allowed: true,
|
||||
unbundle_commit_limit: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1594,7 +1594,6 @@ impl HgCommands for RepoClient {
|
||||
|
||||
let infinitepush_writes_allowed = repo.repo_config().infinitepush.allow_writes;
|
||||
let pushrebase_params = repo.repo_config().pushrebase.clone();
|
||||
let pure_push_allowed = repo.repo_config().push.pure_push_allowed;
|
||||
let maybe_backup_repo_source = client.maybe_backup_repo_source.clone();
|
||||
|
||||
let pushrebase_flags = pushrebase_params.flags.clone();
|
||||
@ -1603,7 +1602,7 @@ impl HgCommands for RepoClient {
|
||||
repo.as_blob_repo(),
|
||||
infinitepush_writes_allowed,
|
||||
stream.compat().boxed(),
|
||||
pure_push_allowed,
|
||||
&repo.repo_config().push,
|
||||
pushrebase_flags,
|
||||
maybe_backup_repo_source,
|
||||
)
|
||||
|
@ -45,6 +45,7 @@ use mercurial_bundles::PartId;
|
||||
use mercurial_mutation::HgMutationEntry;
|
||||
use mercurial_revlog::changeset::RevlogChangeset;
|
||||
use mercurial_types::HgChangesetId;
|
||||
use metaconfig_types::PushParams;
|
||||
use metaconfig_types::PushrebaseFlags;
|
||||
use mononoke_types::BonsaiChangeset;
|
||||
use mononoke_types::ChangesetId;
|
||||
@ -52,7 +53,6 @@ use rate_limiting::RateLimitBody;
|
||||
use repo_identity::RepoIdentityRef;
|
||||
use slog::trace;
|
||||
use topo_sort::sort_topological;
|
||||
use tunables::tunables;
|
||||
use wirepack::TreemanifestBundle2Parser;
|
||||
use wireproto_handler::BackupSourceRepo;
|
||||
|
||||
@ -264,7 +264,7 @@ pub async fn resolve<'a>(
|
||||
repo: &'a BlobRepo,
|
||||
infinitepush_writes_allowed: bool,
|
||||
bundle2: BoxStream<'static, Result<Bundle2Item<'static>>>,
|
||||
pure_push_allowed: bool,
|
||||
push_params: &'a PushParams,
|
||||
pushrebase_flags: PushrebaseFlags,
|
||||
maybe_backup_repo_source: Option<BackupSourceRepo>,
|
||||
) -> Result<PostResolveAction, BundleResolverError> {
|
||||
@ -273,7 +273,7 @@ pub async fn resolve<'a>(
|
||||
repo,
|
||||
infinitepush_writes_allowed,
|
||||
bundle2,
|
||||
pure_push_allowed,
|
||||
push_params,
|
||||
pushrebase_flags,
|
||||
maybe_backup_repo_source,
|
||||
)
|
||||
@ -287,11 +287,17 @@ async fn resolve_impl<'a>(
|
||||
repo: &'a BlobRepo,
|
||||
infinitepush_writes_allowed: bool,
|
||||
bundle2: BoxStream<'static, Result<Bundle2Item<'static>>>,
|
||||
pure_push_allowed: bool,
|
||||
push_params: &'a PushParams,
|
||||
pushrebase_flags: PushrebaseFlags,
|
||||
maybe_backup_repo_source: Option<BackupSourceRepo>,
|
||||
) -> Result<PostResolveAction, BundleResolverError> {
|
||||
let resolver = Bundle2Resolver::new(ctx, repo, infinitepush_writes_allowed, pushrebase_flags);
|
||||
let resolver = Bundle2Resolver::new(
|
||||
ctx,
|
||||
repo,
|
||||
infinitepush_writes_allowed,
|
||||
push_params.unbundle_commit_limit,
|
||||
pushrebase_flags,
|
||||
);
|
||||
let bundle2 = resolver.resolve_stream_params(bundle2).await?;
|
||||
let bundle2 = resolver.resolve_replycaps(bundle2).await?;
|
||||
|
||||
@ -342,6 +348,7 @@ async fn resolve_impl<'a>(
|
||||
.await
|
||||
}
|
||||
} else {
|
||||
let pure_push_allowed = push_params.pure_push_allowed;
|
||||
resolve_push(
|
||||
ctx,
|
||||
resolver,
|
||||
@ -793,6 +800,7 @@ struct Bundle2Resolver<'r> {
|
||||
ctx: &'r CoreContext,
|
||||
repo: &'r BlobRepo,
|
||||
infinitepush_writes_allowed: bool,
|
||||
unbundle_commit_limit: Option<u64>,
|
||||
#[allow(dead_code)]
|
||||
pushrebase_flags: PushrebaseFlags,
|
||||
}
|
||||
@ -802,11 +810,13 @@ impl<'r> Bundle2Resolver<'r> {
|
||||
ctx: &'r CoreContext,
|
||||
repo: &'r BlobRepo,
|
||||
infinitepush_writes_allowed: bool,
|
||||
unbundle_commit_limit: Option<u64>,
|
||||
pushrebase_flags: PushrebaseFlags,
|
||||
) -> Self {
|
||||
Self {
|
||||
ctx,
|
||||
repo,
|
||||
unbundle_commit_limit,
|
||||
infinitepush_writes_allowed,
|
||||
pushrebase_flags,
|
||||
}
|
||||
@ -965,20 +975,18 @@ impl<'r> Bundle2Resolver<'r> {
|
||||
.try_collect()
|
||||
.await?;
|
||||
|
||||
let commit_limit = tunables()
|
||||
.unbundle_limit_num_of_commits_in_push()
|
||||
.unwrap_or_default();
|
||||
// Ignore commit limit if hg sync job is pushing. Hg sync job is used
|
||||
// to mirror one repository into another, and we can't discard a push
|
||||
// even if it's too big
|
||||
if commit_limit > 0 && !self.ctx.session().is_hg_sync_job() {
|
||||
let commit_limit: usize = commit_limit.try_into().unwrap();
|
||||
if changesets.len() > commit_limit {
|
||||
bail!(
|
||||
"Trying to push too many commits! Limit is {}, tried to push {}",
|
||||
commit_limit,
|
||||
changesets.len()
|
||||
);
|
||||
if let Some(commit_limit) = self.unbundle_commit_limit {
|
||||
// Ignore commit limit if hg sync job is pushing. Hg sync job is used
|
||||
// to mirror one repository into another, and we can't discard a push
|
||||
// even if it's too big
|
||||
if !self.ctx.session().is_hg_sync_job() {
|
||||
if changesets.len() as u64 > commit_limit {
|
||||
bail!(
|
||||
"Trying to push too many commits! Limit is {}, tried to push {}",
|
||||
commit_limit,
|
||||
changesets.len()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1109,6 +1109,12 @@ pure_push_allowed = true
|
||||
CONFIG
|
||||
fi
|
||||
|
||||
if [[ -n "${UNBUNDLE_COMMIT_LIMIT}" ]]; then
|
||||
cat >> "repos/$reponame_urlencoded/server.toml" <<CONFIG
|
||||
unbundle_commit_limit = ${UNBUNDLE_COMMIT_LIMIT}
|
||||
CONFIG
|
||||
fi
|
||||
|
||||
if [[ -n "${CACHE_WARMUP_BOOKMARK:-}" ]]; then
|
||||
cat >> "repos/$reponame_urlencoded/server.toml" <<CONFIG
|
||||
[cache_warmup]
|
||||
|
@ -7,7 +7,7 @@
|
||||
$ . "${TEST_FIXTURES}/library.sh"
|
||||
|
||||
setup configuration
|
||||
$ setup_common_config
|
||||
$ UNBUNDLE_COMMIT_LIMIT=2 setup_common_config
|
||||
|
||||
$ cd $TESTTMP
|
||||
|
||||
@ -40,13 +40,6 @@ setup push source repo
|
||||
|
||||
start mononoke
|
||||
|
||||
$ merge_tunables <<EOF
|
||||
> {
|
||||
> "ints": {
|
||||
> "unbundle_limit_num_of_commits_in_push": 2
|
||||
> }
|
||||
> }
|
||||
> EOF
|
||||
$ start_and_wait_for_mononoke_server
|
||||
create new commit in repo2 and check that push fails
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user