mirror of
https://github.com/facebook/sapling.git
synced 2024-10-10 08:47:12 +03:00
Support hg-sync-bundle remains --without-blobimport
Summary: This adds the ability to exclude blobimport entries when querying the count of remaining entries in the HG sync replay log. Reviewed By: ikostia Differential Revision: D15097549 fbshipit-source-id: ae1a9a31f51a044924fdebbdd219fff1e2b3d46a
This commit is contained in:
parent
8daba8e8c3
commit
c224058b2e
@ -150,6 +150,12 @@ queries! {
|
||||
"
|
||||
}
|
||||
|
||||
read CountFurtherBookmarkLogEntriesWithoutReason(min_id: u64, repo_id: RepositoryId, reason: BookmarkUpdateReason) -> (u64) {
|
||||
"SELECT COUNT(*)
|
||||
FROM bookmarks_update_log
|
||||
WHERE id > {min_id} AND repo_id = {repo_id} AND NOT reason = {reason}"
|
||||
}
|
||||
|
||||
write AddBundleReplayData(values: (id: u64, bundle_handle: String, commit_hashes_json: String)) {
|
||||
none,
|
||||
"INSERT INTO bundle_replay_data
|
||||
@ -297,13 +303,34 @@ impl Bookmarks for SqlBookmarks {
|
||||
_ctx: CoreContext,
|
||||
id: u64,
|
||||
repoid: RepositoryId,
|
||||
maybe_exclude_reason: Option<BookmarkUpdateReason>,
|
||||
) -> BoxFuture<u64, Error> {
|
||||
CountFurtherBookmarkLogEntries::query(&self.read_connection, &id, &repoid)
|
||||
.and_then(|entries| {
|
||||
let query = match maybe_exclude_reason {
|
||||
Some(ref r) => CountFurtherBookmarkLogEntriesWithoutReason::query(
|
||||
&self.read_connection,
|
||||
&id,
|
||||
&repoid,
|
||||
&r,
|
||||
)
|
||||
.boxify(),
|
||||
None => {
|
||||
CountFurtherBookmarkLogEntries::query(&self.read_connection, &id, &repoid).boxify()
|
||||
}
|
||||
};
|
||||
|
||||
query
|
||||
.and_then(move |entries| {
|
||||
let entry = entries.into_iter().next();
|
||||
match entry {
|
||||
Some(count) => future::ok(count.0),
|
||||
None => future::err(err_msg("Failed to query further bookmark log entries")),
|
||||
None => {
|
||||
let extra = match maybe_exclude_reason {
|
||||
Some(..) => "without reason",
|
||||
None => "",
|
||||
};
|
||||
let msg = format!("Failed to query further bookmark log entries{}", extra);
|
||||
future::err(err_msg(msg))
|
||||
}
|
||||
}
|
||||
})
|
||||
.boxify()
|
||||
|
@ -184,12 +184,14 @@ pub trait Bookmarks: Send + Sync + 'static {
|
||||
max_rec: u32,
|
||||
) -> BoxStream<(Option<ChangesetId>, BookmarkUpdateReason, Timestamp), Error>;
|
||||
|
||||
/// Count the number of BookmarkUpdateLog entries wiht id greater than the give value
|
||||
/// Count the number of BookmarkUpdateLog entries with id greater than the given value,
|
||||
/// possibly excluding a given reason.
|
||||
fn count_further_bookmark_log_entries(
|
||||
&self,
|
||||
_ctx: CoreContext,
|
||||
id: u64,
|
||||
repoid: RepositoryId,
|
||||
exclude_reason: Option<BookmarkUpdateReason>,
|
||||
) -> BoxFuture<u64, Error>;
|
||||
|
||||
/// Count the number of BookmarkUpdateLog entries with id greater than the given value
|
||||
|
@ -213,6 +213,13 @@ fn setup_app<'a, 'b>() -> App<'a, 'b> {
|
||||
.required(false)
|
||||
.takes_value(false)
|
||||
.help("only print the number if present"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("without-blobimport")
|
||||
.long("without-blobimport")
|
||||
.required(false)
|
||||
.takes_value(false)
|
||||
.help("exclude blobimport entries from the count"),
|
||||
),
|
||||
)
|
||||
.subcommand(
|
||||
@ -967,6 +974,7 @@ fn process_hg_sync_subcommand<'a>(
|
||||
},
|
||||
(HG_SYNC_REMAINS, Some(sub_m)) => {
|
||||
let quiet = sub_m.is_present("quiet");
|
||||
let without_blobimport = sub_m.is_present("without-blobimport");
|
||||
mutable_counters
|
||||
.get_counter(ctx.clone(), repo_id, LATEST_REPLAYED_REQUEST_KEY)
|
||||
.map(|maybe_counter| {
|
||||
@ -977,9 +985,21 @@ fn process_hg_sync_subcommand<'a>(
|
||||
maybe_counter.unwrap_or(0)
|
||||
})
|
||||
.and_then({
|
||||
cloned!(ctx, repo_id);
|
||||
cloned!(ctx, repo_id, without_blobimport);
|
||||
move |counter| {
|
||||
bookmarks.count_further_bookmark_log_entries(ctx, counter as u64, repo_id)
|
||||
let counter = counter as u64;
|
||||
|
||||
let exclude_reason = match without_blobimport {
|
||||
true => Some(BookmarkUpdateReason::Blobimport),
|
||||
false => None,
|
||||
};
|
||||
|
||||
bookmarks.count_further_bookmark_log_entries(
|
||||
ctx,
|
||||
counter,
|
||||
repo_id,
|
||||
exclude_reason
|
||||
)
|
||||
}
|
||||
})
|
||||
.map({
|
||||
@ -988,9 +1008,17 @@ fn process_hg_sync_subcommand<'a>(
|
||||
if quiet {
|
||||
println!("{}", remaining);
|
||||
} else {
|
||||
let name = match without_blobimport {
|
||||
true => "non-blobimport bundles",
|
||||
false => "bundles",
|
||||
};
|
||||
|
||||
info!(
|
||||
logger,
|
||||
"Remaining bundles to replay in {:?}: {}", repo_id, remaining
|
||||
"Remaining {} to replay in {:?}: {}",
|
||||
name,
|
||||
repo_id,
|
||||
remaining
|
||||
);
|
||||
}
|
||||
}
|
||||
|
53
tests/integration/test-admin-hg-sync-bundle-remains.t
Normal file
53
tests/integration/test-admin-hg-sync-bundle-remains.t
Normal file
@ -0,0 +1,53 @@
|
||||
$ . $TESTDIR/library.sh
|
||||
$ ZERO=0000000000000000000000000000000000000000000000000000000000000000
|
||||
$ ONE=1111111111111111111111111111111111111111111111111111111111111111
|
||||
$ TWO=2222222222222222222222222222222222222222222222222222222222222222
|
||||
$ THREE=3333333333333333333333333333333333333333333333333333333333333333
|
||||
|
||||
setup configuration
|
||||
$ ENABLE_PRESERVE_BUNDLE2=1 setup_common_config blob:files
|
||||
$ mkdir "$TESTTMP"/repo
|
||||
$ create_books_sqlite3_db
|
||||
$ write_stub_log_entry create "$ZERO"
|
||||
$ write_stub_log_entry update "$ZERO" "$ONE"
|
||||
$ write_stub_log_entry --blobimport update "$ONE" "$TWO"
|
||||
$ write_stub_log_entry --blobimport update "$TWO" "$THREE"
|
||||
$ sqlite3 "$TESTTMP/repo/books" "select id, repo_id, hex(from_changeset_id), reason from bookmarks_update_log;"
|
||||
1|0||testmove
|
||||
2|0|0000000000000000000000000000000000000000000000000000000000000000|testmove
|
||||
3|0|1111111111111111111111111111111111111111111111111111111111111111|blobimport
|
||||
4|0|2222222222222222222222222222222222222222222222222222222222222222|blobimport
|
||||
|
||||
it should count remaining entries
|
||||
$ mononoke_admin hg-sync-bundle last-processed --set 0
|
||||
* INFO Counter for RepositoryId(0) set to 0 (glob)
|
||||
$ mononoke_admin hg-sync-bundle remains
|
||||
* INFO Remaining bundles to replay in RepositoryId(0): 4 (glob)
|
||||
$ mononoke_admin hg-sync-bundle last-processed --set 1
|
||||
* INFO Counter for RepositoryId(0) set to 1 (glob)
|
||||
$ mononoke_admin hg-sync-bundle remains
|
||||
* INFO Remaining bundles to replay in RepositoryId(0): 3 (glob)
|
||||
$ mononoke_admin hg-sync-bundle last-processed --set 10
|
||||
* INFO Counter for RepositoryId(0) set to 10 (glob)
|
||||
$ mononoke_admin hg-sync-bundle remains
|
||||
* INFO Remaining bundles to replay in RepositoryId(0): 0 (glob)
|
||||
it should count remaining entries excluding blobimport
|
||||
$ mononoke_admin hg-sync-bundle last-processed --set 0
|
||||
* INFO Counter for RepositoryId(0) set to 0 (glob)
|
||||
$ mononoke_admin hg-sync-bundle remains --without-blobimport
|
||||
* INFO Remaining non-blobimport bundles to replay in RepositoryId(0): 2 (glob)
|
||||
$ mononoke_admin hg-sync-bundle last-processed --set 1
|
||||
* INFO Counter for RepositoryId(0) set to 1 (glob)
|
||||
$ mononoke_admin hg-sync-bundle remains --without-blobimport
|
||||
* INFO Remaining non-blobimport bundles to replay in RepositoryId(0): 1 (glob)
|
||||
$ mononoke_admin hg-sync-bundle last-processed --set 10
|
||||
* INFO Counter for RepositoryId(0) set to 10 (glob)
|
||||
$ mononoke_admin hg-sync-bundle remains --without-blobimport
|
||||
* INFO Remaining non-blobimport bundles to replay in RepositoryId(0): 0 (glob)
|
||||
it should support --quiet
|
||||
$ mononoke_admin hg-sync-bundle last-processed --set 0
|
||||
* INFO Counter for RepositoryId(0) set to 0 (glob)
|
||||
$ mononoke_admin hg-sync-bundle remains --quiet
|
||||
4
|
||||
$ mononoke_admin hg-sync-bundle remains --quiet --without-blobimport
|
||||
2
|
Loading…
Reference in New Issue
Block a user