remotefilelog: log undesired filename fetches

Summary:
Now that the Rust revisionstore records undesired filename fetches,
let's log those results to Scuba in Python.

Reviewed By: StanislavGlebik

Differential Revision: D23462572

fbshipit-source-id: b55f2290e30e3a5c3b67d9f612b24bc3aad403a8
This commit is contained in:
Durham Goode 2020-09-04 14:53:03 -07:00 committed by Facebook GitHub Bot
parent 9772ab1718
commit 8b91cccc8b
4 changed files with 85 additions and 1 deletions

View File

@ -555,6 +555,8 @@ class remotefileslog(filelog.fileslog):
additions."""
if self.contentstore:
self.contentstore.flush()
self.logfetches()
if self.metadatastore:
self.metadatastore.flush()
self.commitsharedpacks()
@ -562,6 +564,21 @@ class remotefileslog(filelog.fileslog):
def abortpending(self):
"""Used in alternative filelog implementations to throw out pending
additions."""
self.logfetches()
self.contentstore = None
self.metadatastore = None
self._memcachestore = None
def logfetches(self):
if self.contentstore:
fetched = self.contentstore.getloggedfetches()
if fetched:
ui = self.repo.ui
for path in fetched:
ui.log(
"undesired_file_fetches",
"",
filename=path,
reponame=self.repo.name,
)
ui.metrics.gauge("undesiredfilefetches", len(fetched))

View File

@ -935,6 +935,11 @@ py_class!(pub class contentstore |py| {
let store = self.store(py);
store.metadata_py(py, name, node)
}
def getloggedfetches(&self) -> PyResult<Vec<PyPathBuf>> {
let store = self.store(py);
Ok(store.get_logged_fetches().into_iter().map(|p| p.into()).collect::<Vec<PyPathBuf>>())
}
});
impl ExtractInnerRef for contentstore {

View File

@ -6,6 +6,7 @@
*/
use std::{
collections::HashSet,
path::{Path, PathBuf},
sync::Arc,
};
@ -19,7 +20,7 @@ use configparser::{
config::ConfigSet,
hg::{ByteCount, ConfigSetHgExt},
};
use types::Key;
use types::{Key, RepoPathBuf};
use crate::{
datastore::{
@ -76,6 +77,14 @@ impl ContentStore {
Ok(None)
}
}
pub fn get_logged_fetches(&self) -> HashSet<RepoPathBuf> {
if let Some(remote_store) = &self.remote_store {
remote_store.take_seen()
} else {
HashSet::new()
}
}
}
// Repack specific methods, not to be used directly but by the repack code.

View File

@ -0,0 +1,53 @@
#chg-compatible
$ . "$TESTDIR/library.sh"
$ cat >> "$TESTTMP/uilog.py" <<EOF
> from edenscm.mercurial import extensions
> from edenscm.mercurial import ui as uimod
> def uisetup(ui):
> extensions.wrapfunction(uimod.ui, 'log', mylog)
> def mylog(orig, self, service, *msg, **opts):
> if service in ['undesired_file_fetches']:
> kw = []
> for k, v in sorted(opts.items()):
> kw.append("%s=%s" % (k, v))
> kwstr = ", ".join(kw)
> msgstr = msg[0] % msg[1:]
> self.warn('%s: %s (%s)\n' % (service, msgstr, kwstr))
> with open('$TESTTMP/undesiredfiles', 'a') as f:
> f.write('%s: %s (%s)\n' % (service, msgstr, kwstr))
> return orig(self, service, *msg, **opts)
> EOF
$ cat >> "$HGRCPATH" <<EOF
> [extensions]
> uilog=$TESTTMP/uilog.py
> EOF
$ newserver master
$ clone master client1
$ cd client1
$ echo x > x
$ hg commit -qAm x
$ mkdir dir
$ echo y > dir/y
$ hg commit -qAm y
$ hg push -r tip --to master --create
pushing rev 79c51fb96423 to destination ssh://user@dummy/master bookmark master
searching for changes
exporting bookmark master
remote: adding changesets (?)
remote: adding manifests (?)
remote: adding file changes (?)
remote: added 2 changesets with 2 changes to 2 files (?)
$ cd ..
$ clone master shallow --noupdate
$ cd shallow
$ hg update -q master --config remotefilelog.undesiredfileregex=".*" 2>&1 | sort
2 trees fetched over 0.00s
fetching tree '' 05bd2758dd7a25912490d0633b8975bf52bfab06, found via 79c51fb96423
undesired_file_fetches: (filename=dir/y, reponame=master)
undesired_file_fetches: (filename=x, reponame=master)