mononoke: add allow_bookmark_update_delay

Summary:
Follow up from D22819791.
We want to use bookmark update delay only in scs, so let's configure it this
way

Reviewed By: krallin

Differential Revision: D22847143

fbshipit-source-id: b863d7fa4bf861ffe5d53a6a2d5ec44e7f60eb1a
This commit is contained in:
Stanislau Hlebik 2020-07-31 03:07:39 -07:00 committed by Facebook GitHub Bot
parent 43ac2a1c62
commit cd2a3fcf32
3 changed files with 55 additions and 16 deletions

View File

@ -58,6 +58,12 @@ pub type IsDerivedFn = dyn for<'a> Fn(&'a CoreContext, &'a BlobRepo, &'a Changes
+ Send
+ Sync;
#[derive(Clone, Copy)]
pub enum BookmarkUpdateDelay {
Allow,
Disallow,
}
pub struct Warmer {
warmer: Box<WarmerFn>,
is_derived: Box<IsDerivedFn>,
@ -82,15 +88,20 @@ pub fn create_warmer<D: BonsaiDerived>(ctx: &CoreContext) -> Warmer {
}
impl WarmBookmarksCache {
pub async fn new(ctx: &CoreContext, repo: &BlobRepo) -> Result<Self, Error> {
pub async fn new(
ctx: &CoreContext,
repo: &BlobRepo,
bookmark_update_delay: BookmarkUpdateDelay,
) -> Result<Self, Error> {
let derived_data_types = &repo.get_derived_data_config().derived_data_types;
Self::new_with_types(ctx, repo, derived_data_types).await
Self::new_with_types(ctx, repo, derived_data_types, bookmark_update_delay).await
}
pub async fn new_with_types(
ctx: &CoreContext,
repo: &BlobRepo,
types: &BTreeSet<String>,
bookmark_update_delay: BookmarkUpdateDelay,
) -> Result<Self, Error> {
let derived_data_types = &repo.get_derived_data_config().derived_data_types;
let mut warmers: Vec<Warmer> = Vec::new();
@ -133,6 +144,7 @@ impl WarmBookmarksCache {
repo.clone(),
warmers.clone(),
loop_sleep,
bookmark_update_delay,
);
Ok(Self {
bookmarks,
@ -339,6 +351,7 @@ fn spawn_bookmarks_coordinator(
repo: BlobRepo,
warmers: Arc<Vec<Warmer>>,
loop_sleep: Duration,
bookmark_update_delay: BookmarkUpdateDelay,
) {
// ignore JoinHandle, because we want it to run until `terminate` receives a signal
let _ = tokio::spawn(async move {
@ -433,6 +446,7 @@ fn spawn_bookmarks_coordinator(
);
});
},
bookmark_update_delay,
)
.await;
if let Err(ref err) = res {
@ -566,22 +580,30 @@ async fn single_bookmark_updater(
bookmarks: &Arc<RwLock<HashMap<BookmarkName, (ChangesetId, BookmarkKind)>>>,
warmers: &Arc<Vec<Warmer>>,
mut staleness_reporter: impl FnMut(Timestamp),
bookmark_update_delay: BookmarkUpdateDelay,
) -> Result<(), Error> {
let (latest_derived, underived_history) =
find_all_underived_and_latest_derived(&ctx, &repo, &bookmark.name(), warmers.as_ref())
.await?;
let delay_secs = tunables().get_warm_bookmark_cache_delay();
if delay_secs < 0 {
warn!(
ctx.logger(),
"invalid warm bookmark cache delay value: {}", delay_secs
);
}
let bookmark_update_delay_secs = match bookmark_update_delay {
BookmarkUpdateDelay::Allow => {
let delay_secs = tunables().get_warm_bookmark_cache_delay();
if delay_secs < 0 {
warn!(
ctx.logger(),
"invalid warm bookmark cache delay value: {}", delay_secs
);
}
delay_secs
}
BookmarkUpdateDelay::Disallow => 0,
};
let update_bookmark = |ts: Timestamp, cs_id: ChangesetId| async move {
let cur_delay = ts.since_seconds();
if cur_delay < delay_secs {
let to_sleep = (delay_secs - cur_delay) as u64;
if cur_delay < bookmark_update_delay_secs {
let to_sleep = (bookmark_update_delay_secs - cur_delay) as u64;
info!(
ctx.logger(),
"sleeping for {} secs before updating a bookmark", to_sleep
@ -840,6 +862,7 @@ mod tests {
repo.clone(),
warmers,
TEST_LOOP_SLEEP,
BookmarkUpdateDelay::Disallow,
);
let master_book = BookmarkName::new("master")?;
@ -895,7 +918,16 @@ mod tests {
master_book_name.clone(),
BookmarkKind::PullDefaultPublishing,
);
single_bookmark_updater(&ctx, &repo, &master_book, &bookmarks, &warmers, |_| {}).await?;
single_bookmark_updater(
&ctx,
&repo,
&master_book,
&bookmarks,
&warmers,
|_| {},
BookmarkUpdateDelay::Disallow,
)
.await?;
assert_eq!(
bookmarks.with_read(|bookmarks| bookmarks.get(&master_book_name).cloned()),
@ -1003,6 +1035,7 @@ mod tests {
repo.clone(),
warmers,
TEST_LOOP_SLEEP,
BookmarkUpdateDelay::Disallow,
);
let master_book = BookmarkName::new("master")?;
@ -1033,6 +1066,7 @@ mod tests {
repo,
warmers,
TEST_LOOP_SLEEP,
BookmarkUpdateDelay::Disallow,
);
wait_for_bookmark(
&bookmarks,
@ -1121,6 +1155,7 @@ mod tests {
repo.clone(),
warmers.clone(),
TEST_LOOP_SLEEP,
BookmarkUpdateDelay::Disallow,
);
// Give it a chance to derive
wait({
@ -1183,6 +1218,7 @@ mod tests {
repo.clone(),
warmers,
TEST_LOOP_SLEEP,
BookmarkUpdateDelay::Disallow,
);
let publishing_book = BookmarkName::new("publishing")?;

View File

@ -57,7 +57,7 @@ use stats::prelude::*;
use std::collections::HashSet;
use std::hash::{Hash, Hasher};
use synced_commit_mapping::{SqlSyncedCommitMapping, SyncedCommitMapping};
use warm_bookmarks_cache::WarmBookmarksCache;
use warm_bookmarks_cache::{BookmarkUpdateDelay, WarmBookmarksCache};
use crate::changeset::ChangesetContext;
use crate::errors::MononokeError;
@ -196,7 +196,8 @@ impl Repo {
let blobstore = blob_repo.get_blobstore().boxed();
let skiplist_index = fetch_skiplist_index(&ctx, &skiplist_index_blobstore_key, &blobstore);
let warm_bookmarks_cache = WarmBookmarksCache::new(&ctx, &blob_repo);
let warm_bookmarks_cache =
WarmBookmarksCache::new(&ctx, &blob_repo, BookmarkUpdateDelay::Allow);
let (
repo_permission_checker,
@ -273,7 +274,8 @@ impl Repo {
},
..Default::default()
};
let warm_bookmarks_cache = WarmBookmarksCache::new(&ctx, &blob_repo).await?;
let warm_bookmarks_cache =
WarmBookmarksCache::new(&ctx, &blob_repo, BookmarkUpdateDelay::Disallow).await?;
let warm_bookmarks_cache = Arc::new(warm_bookmarks_cache);
let live_commit_sync_config: Arc<dyn LiveCommitSyncConfig> = match live_commit_sync_config {

View File

@ -37,7 +37,7 @@ use sql_construct::SqlConstructFromMetadataDatabaseConfig;
use sql_ext::facebook::MysqlOptions;
use synced_commit_mapping::SqlSyncedCommitMapping;
use warm_bookmarks_cache::WarmBookmarksCache;
use warm_bookmarks_cache::{BookmarkUpdateDelay, WarmBookmarksCache};
use crate::errors::ErrorKind;
@ -290,6 +290,7 @@ pub fn repo_handlers(
&ctx,
&blobrepo,
&btreeset! { MappedHgChangesetId::NAME.to_string() },
BookmarkUpdateDelay::Disallow,
)
.await?,
)))