Repository navigation
Closed
Description
I'd like to propose a new design for the scanner code in the lfs package. The scanner functions are concerned with extracting LFS pointers from a range of git objects:
lfs.ScanRefs()scans a range of commits.lfs.ScanTree()scans just the tree of a single commit.lfs.ScanIndex()scans uncommited objects in the git index.lfs.ScanUnpushed()looks for local objects that have not been pushed to a given remote.lfs.ScanPreviousVersions()scans commits in a ref since a given time.
There are a number of problems with it, as it has organically grown:
- Common usage of the scanner functions buffer the LFS pointers to a slice. This means operations that depend on the scanner can't start until it's done. This is most apparent when you notice that LFS uploads of large git pushes don't start until
git rev-listhas run on the entire history. - No shared context, each
lfs.ScanRefs()in agit pushwith lots of branches/tags results in duplicated work, such as comparing local and remote refs, or spinning up extragit cat-fileprocesses for each ref. - Lots of coupling with the
configandlfspackages.
@ttaylorr and I came up with a design for a new scanner, focusing on async communication so it can begin feeding LFS Pointers to the transfer queue almost immediately.
Essentially, I want to create a gitscanner.Scanner object that can handle multiple scan options. Here's an illustration in pseudo go code for a pre-push implementation.
// The hook receives commit information on stdin in the form:
// <local ref> <local sha1> <remote ref> <remote sha1>
// Pushes with lots of branches/tags will have to scan multiple commit ranges
// this spins up `git cat-file --batch-check` and `git cat-file --batch` commands
gscanner := gitscanner.New()
// the scanner can calculate the remote refs needed for a push, just once,
// instead of for each ref line in stdin.
// https://github.com/github/git-lfs/blob/49354864921c6d4acaedf70ccd33a6ff5abff431/lfs/scanner.go#L296-L310
gscanner.Remote("origin")
go func() {
for pointer := range gscanner.Output {
// pass to the transfer queue
}
}()
scanner := bufio.NewScanner(os.Stdin)
for scanner.Scan() {
line := strings.TrimSpace(scanner.Text())
left, right := decodeRefs(line)
// this blocks until the rev-list command finished
gscanner.ScanLeftToRemote(left)
}
// kills the `git cat-file` commands
gscanner.Close()
Activity
ttaylorr commentedon Nov 14, 2016
I strong agree that we should keep this new design in the
lfspackage to start. I started working over the weekend to uncover what it might look like to introduce a newscannerpackage, and there's a significant amount oflfscode that we depend on (*lfs.Pointerbeing quite a big one) that would have to be moved in order to make this possible.At some point I'd love to have a
scannerpackage, but I think starting inlfsis the right call.I'm a bit confused by your notation. Did you want to create a package
gitscannerand a typeScannerwithin it, or create a private typegitscannerin thelfspackage and have aScannermethod export with it as the receiver?I think we can optimize here. calling
ScanLeftToRightfor each branch that we're pushing will yield a potentially large amount of duplicated scanning over objects that we've already seen. What do you think about doing agit diffbetween theleftwe want to scan for and theleftswe've already seen?technoweenie commentedon Nov 14, 2016
*gitscanner.Scannerfrom packagegit/gitscanner, though I'm very flexible on package names.Though I haven't implemented that type yet, I've started working my way up starting with
cat-file --batchin #1650, implemented in thelfspackage for now.That's an optimization that could be made, sure. I think having a single scanner object is the key to this though.
larsxschneider commentedon Nov 14, 2016
Did you test/prototype the parallel
git cat-file --batch-checkworker? I don't know that area but I am surprised that this is CPU bound where multiple worker would improve the performance. I would have assumed that it is I/O bound. Plus, do you know if Git locks anything in this process? It shouldn't since this is a read-only operation ... but you never know 😄technoweenie commentedon Nov 14, 2016
We have seen evidence that it's not particularly cpu or io bound on repositories with long histories (at least, on windows). I'm glad you brought this up though, as I'm skeptical on the idea of multiple
cat-fileworkers too. Doing benchmarks here is important 👍technoweenie commentedon Nov 28, 2016
Had a thought this weekend. The scanner should add the ability to log details of scans, so we can replay them later. We commonly get reports from people about a
git pushmissing some LFS objects. Without some way to log the scanner output, we rely on the user somehow remembering this info at push time to debug these issues. I'm thinking something like reflogs stored in.git/lfs/pushlogsor something. There's no need to log fetches IMO, just pushes.ttaylorr commentedon Nov 28, 2016
Great idea. ❤️
technoweenie commentedon Dec 21, 2016
We've made a lot of progress, but there's still some stuff to do:
pushandpre-pushto use the new gitscanner and progress meter, instead of accumulating[]*lfs.WrappedPointerslices.pruneto use the new gitscanner callbacks.Scan*functions. A gitscanner should only have a single callback.lfs.WrappedPointerin favor of some gitscanner-specific pointer.cat-filecalls so they are instantiated just once, and not on everyScan*function call.ttaylorr commentedon Jul 27, 2018
Hi, I think that this is in a good state for now, since we've been using the gitscanner in package LFS for a while. In the future, I would like to extract a package as you suggest in this thread, but I feel as if the design will be drastically different due to the existence of package
github.com/git-lfs/gitobj, using that instead of relying ongit cat-file -p, and similar. To avoid cluttering this thread, I'm going to close this issue for now.