mononoke: add x_repo_lookup to scsc

Summary:
Useful for debugging.

I also fixed how we open a SqlSyncedCommitMapping, because we used incorrect path for that.

Reviewed By: ikostia

Differential Revision: D19767148

fbshipit-source-id: baf67bceceb7b22429b05b41020cf4350e3c87bd
This commit is contained in:
Stanislau Hlebik 2020-02-06 07:05:04 -08:00 committed by Facebook Github Bot
parent c8a4ba5dac
commit af2f50d644
7 changed files with 127 additions and 78 deletions

View File

@ -136,62 +136,68 @@ impl MononokeRepo {
let commit_sync_config = config.commit_sync_config.clone();
// This is hacky, for the benefit of the new Mononoke object type
open_synced_commit_mapping(fb, config.clone(), mysql_options, readonly_storage)
.boxed()
.compat()
.join(open_blobrepo(
fb,
config.storage_config.clone(),
repoid,
mysql_options,
with_cachelib,
config.bookmarks_cache_ttl,
config.redaction,
common_config.scuba_censored_table,
config.filestore,
readonly_storage,
blobstore_options,
logger.clone(),
))
.map(move |(synced_commit_mapping, repo)| {
let warm_bookmarks_cache = WarmBookmarksCache::new(
ctx.clone(),
repo.clone(),
vec![Box::new(&warm_hg_changeset), Box::new(&derive_unodes)],
);
{
cloned!(config, logger);
async move {
open_synced_commit_mapping(fb, config, mysql_options, readonly_storage, &logger)
.await
}
}
.boxed()
.compat()
.join(open_blobrepo(
fb,
config.storage_config.clone(),
repoid,
mysql_options,
with_cachelib,
config.bookmarks_cache_ttl,
config.redaction,
common_config.scuba_censored_table,
config.filestore,
readonly_storage,
blobstore_options,
logger.clone(),
))
.map(move |(synced_commit_mapping, repo)| {
let warm_bookmarks_cache = WarmBookmarksCache::new(
ctx.clone(),
repo.clone(),
vec![Box::new(&warm_hg_changeset), Box::new(&derive_unodes)],
);
let skiplist_index = {
if !with_skiplist {
ok(Arc::new(SkiplistIndex::new())).right_future()
} else {
fetch_skiplist_index(
ctx.clone(),
skiplist_index_blobstore_key,
repo.get_blobstore().boxed(),
)
.left_future()
let skiplist_index = {
if !with_skiplist {
ok(Arc::new(SkiplistIndex::new())).right_future()
} else {
fetch_skiplist_index(
ctx.clone(),
skiplist_index_blobstore_key,
repo.get_blobstore().boxed(),
)
.left_future()
}
};
skiplist_index.join(warm_bookmarks_cache).map(
move |(skiplist_index, warm_bookmarks_cache)| {
let unodes_derived_mapping =
Arc::new(RootUnodeManifestMapping::new(repo.get_blobstore()));
Self {
repo,
logger,
skiplist_index,
cache,
unodes_derived_mapping,
warm_bookmarks_cache: Arc::new(warm_bookmarks_cache),
synced_commit_mapping,
monitoring_config,
commit_sync_config,
}
};
skiplist_index.join(warm_bookmarks_cache).map(
move |(skiplist_index, warm_bookmarks_cache)| {
let unodes_derived_mapping =
Arc::new(RootUnodeManifestMapping::new(repo.get_blobstore()));
Self {
repo,
logger,
skiplist_index,
cache,
unodes_derived_mapping,
warm_bookmarks_cache: Arc::new(warm_bookmarks_cache),
synced_commit_mapping: Arc::new(synced_commit_mapping),
monitoring_config,
commit_sync_config,
}
},
)
})
.flatten()
},
)
})
.flatten()
}
fn get_hgchangesetid_from_revision(

View File

@ -17,6 +17,7 @@ use anyhow::{bail, format_err, Error};
use blobrepo::BlobRepo;
use blobrepo_factory::{open_blobrepo, BlobstoreOptions, Caching, ReadOnlyStorage};
use blobstore::Loadable;
use blobstore_factory::make_sql_factory;
use bookmarks::{BookmarkName, BookmarkPrefix};
use context::CoreContext;
use fbinit::FacebookInit;
@ -36,7 +37,7 @@ use futures_preview::StreamExt as NewStreamExt;
use identity::Identity;
use mercurial_types::Globalrev;
use metaconfig_types::{
CommitSyncConfig, CommonConfig, MetadataDBConfig, RepoConfig, SourceControlServiceMonitoring,
CommitSyncConfig, CommonConfig, RepoConfig, SourceControlServiceMonitoring,
SourceControlServiceParams,
};
use mononoke_types::{
@ -47,8 +48,10 @@ use revset::AncestorsNodeStream;
use skiplist::{fetch_skiplist_index, SkiplistIndex};
use slog::{debug, error, Logger};
use sql_ext::MysqlOptions;
#[cfg(test)]
use sql_ext::SqlConstructors;
use stats_facebook::service_data::{get_service_data_singleton, ServiceData};
use synced_commit_mapping::{SqlConstructors, SqlSyncedCommitMapping, SyncedCommitMapping};
use synced_commit_mapping::{SqlSyncedCommitMapping, SyncedCommitMapping};
use unodes::{derive_unodes, RootUnodeManifestMapping};
use warm_bookmarks_cache::{warm_hg_changeset, WarmBookmarksCache};
@ -100,18 +103,19 @@ pub async fn open_synced_commit_mapping(
config: RepoConfig,
mysql_options: MysqlOptions,
readonly_storage: ReadOnlyStorage,
) -> Result<SqlSyncedCommitMapping, Error> {
let name = SqlSyncedCommitMapping::LABEL;
match config.storage_config.dbconfig {
MetadataDBConfig::LocalDB { path } => {
SqlSyncedCommitMapping::with_sqlite_path(path.join(name), readonly_storage.0)
}
MetadataDBConfig::Mysql { db_address, .. } => {
SqlSyncedCommitMapping::with_xdb(fb, db_address, mysql_options, readonly_storage.0)
.compat()
.await
}
}
logger: &Logger,
) -> Result<Arc<SqlSyncedCommitMapping>, Error> {
let sql_factory = make_sql_factory(
fb,
config.storage_config.dbconfig,
mysql_options,
readonly_storage,
logger.clone(),
)
.compat()
.await?;
sql_factory.open::<SqlSyncedCommitMapping>().compat().await
}
impl Repo {
@ -130,9 +134,14 @@ impl Repo {
let repoid = config.repoid;
let synced_commit_mapping = Arc::new(
open_synced_commit_mapping(fb, config.clone(), mysql_options, readonly_storage).await?,
);
let synced_commit_mapping = open_synced_commit_mapping(
fb,
config.clone(),
mysql_options,
readonly_storage,
&logger,
)
.await?;
let service_config = config.source_control_service.clone();
let monitoring_config = config.source_control_service_monitoring.clone();

View File

@ -17,7 +17,7 @@ function verify_wc() {
crossrepo verify-wc "$large_repo_commit"
}
function init_large_small_repo() {
function create_large_small_repo() {
REPOTYPE="blob_files"
ENABLE_PRESERVE_BUNDLE2=1 REPOID=0 REPONAME=large-mon setup_common_config "$REPOTYPE"
ENABLE_PRESERVE_BUNDLE2=1 REPOID=1 REPONAME=small-mon setup_common_config "$REPOTYPE"
@ -81,13 +81,17 @@ EOF
export SMALL_MASTER_BONSAI
SMALL_MASTER_BONSAI=$(get_bonsai_bookmark $REPOIDSMALL master_bookmark)
echo "Adding synced mapping entry"
add_synced_commit_mapping_entry "$REPOIDSMALL" "$SMALL_MASTER_BONSAI" \
"$REPOIDLARGE" "$LARGE_MASTER_BONSAI"
}
function init_large_small_repo() {
create_large_small_repo
echo "Starting Mononoke server"
mononoke "$@"
wait_for_mononoke
echo "Adding synced mapping entry"
add_synced_commit_mapping_entry "$REPOIDSMALL" "$SMALL_MASTER_BONSAI" \
"$REPOIDLARGE" "$LARGE_MASTER_BONSAI"
sqlite3 "$TESTTMP/monsql/sqlite_dbs" "INSERT INTO mutable_counters (repo_id, name, value) VALUES ($REPOIDSMALL, 'backsync_from_$REPOIDLARGE', 2)";
}

View File

@ -21,8 +21,8 @@
$ init_large_small_repo --local-configerator-path="$TESTTMP/configerator"
Setting up hg server repos
Blobimporting them
Starting Mononoke server
Adding synced mapping entry
Starting Mononoke server
Push a merge from a large repo
$ cd "$TESTTMP/large-hg-client"

View File

@ -22,8 +22,8 @@
$ init_large_small_repo --local-configerator-path="$TESTTMP/configerator"
Setting up hg server repos
Blobimporting them
Starting Mononoke server
Adding synced mapping entry
Starting Mononoke server
Normal pushrebase with one commit
$ cd "$TESTTMP/small-hg-client"

View File

@ -21,8 +21,8 @@
$ PUSHREBASE_REWRITE_DATES=1 init_large_small_repo --local-configerator-path="$TESTTMP/configerator"
Setting up hg server repos
Blobimporting them
Starting Mononoke server
Adding synced mapping entry
Starting Mononoke server
-- enable verification hook in small-hg-srv
$ cd "$TESTTMP/small-hg-srv"

View File

@ -0,0 +1,30 @@
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This software may be used and distributed according to the terms of the
# GNU General Public License found in the LICENSE file in the root
# directory of this source tree.
$ . "${TEST_FIXTURES}/library.sh"
$ . "${TEST_FIXTURES}/library-push-redirector.sh"
Setup config repo:
$ cd "$TESTTMP"
$ create_large_small_repo
Setting up hg server repos
Blobimporting them
Adding synced mapping entry
start SCS server
$ start_and_wait_for_scs_server
make some simple requests that we can use to check scuba logging
List repos - there should be two of them
$ scsc repos
large-mon
small-mon
$ scsc xrepo-lookup --source-repo small-mon --target-repo large-mon --bonsai-id $SMALL_MASTER_BONSAI
bfcfb674663c5438027bcde4a7ae5024c838f76a
$ scsc xrepo-lookup --source-repo large-mon --target-repo small-mon --bonsai-id $LARGE_MASTER_BONSAI
11f848659bfcf77abd04f947883badd8efa88d26