Skip to content

Proposal: git/gitscanner package for v2.0 #1649

Closed

Description

@technoweenie

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:

  1. 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-list has run on the entire history.
  2. No shared context, each lfs.ScanRefs() in a git push with lots of branches/tags results in duplicated work, such as comparing local and remote refs, or spinning up extra git cat-file processes for each ref.
  3. Lots of coupling with the config and lfs packages.

@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

  1. ttaylorr commented on Nov 14, 2016

    @ttaylorr
    Contributor

    I'd like to propose a new design for the scanner code in the lfs package

    I strong agree that we should keep this new design in the lfs package to start. I started working over the weekend to uncover what it might look like to introduce a new scanner package, and there's a significant amount of lfs code that we depend on (*lfs.Pointer being 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 scanner package, but I think starting in lfs is the right call.

    Essentially, I want to create a gitscanner.Scanner object that can handle multiple scan options.

    I'm a bit confused by your notation. Did you want to create a package gitscanner and a type Scanner within it, or create a private type gitscanner in the lfs package and have a Scanner method export with it as the receiver?

    scanner := bufio.NewScanner(os.Stdin)

    I think we can optimize here. calling ScanLeftToRight for 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 a git diff between the left we want to scan for and the lefts we've already seen?

  2. technoweenie commented on Nov 14, 2016

    @technoweenie
    ContributorAuthor

    I'm a bit confused by your notation. Did you want to create a package gitscanner and a type Scanner within it

    *gitscanner.Scanner from package git/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 --batch in #1650, implemented in the lfs package for now.

    I think we can optimize here. calling ScanLeftToRight for 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 a git diff between the left we want to scan for and the lefts we've already seen?

    That's an optimization that could be made, sure. I think having a single scanner object is the key to this though.

  3. larsxschneider commented on Nov 14, 2016

    @larsxschneider
    Member

    Did you test/prototype the parallel git cat-file --batch-check worker? 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 😄

  4. technoweenie commented on Nov 14, 2016

    @technoweenie
    ContributorAuthor

    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-file workers too. Doing benchmarks here is important 👍

  5. technoweenie commented on Nov 28, 2016

    @technoweenie
    ContributorAuthor

    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 push missing 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/pushlogs or something. There's no need to log fetches IMO, just pushes.

  6. ttaylorr commented on Nov 28, 2016

    @ttaylorr
    Contributor

    Great idea. ❤️

  7. technoweenie commented on Dec 21, 2016

    @technoweenie
    ContributorAuthor

    We've made a lot of progress, but there's still some stuff to do:

    • Update push and pre-push to use the new gitscanner and progress meter, instead of accumulating []*lfs.WrappedPointer slices.
    • Update prune to use the new gitscanner callbacks.
    • Remove the callback args on the Scan* functions. A gitscanner should only have a single callback.
    • Remove lfs.WrappedPointer in favor of some gitscanner-specific pointer.
    • Move the cat-file calls so they are instantiated just once, and not on every Scan* function call.
    • Add gitscanner plumbing commands that simply dump the LFS OIDs for a given scan function call.
  8. ttaylorr commented on Jul 27, 2018

    @ttaylorr
    Contributor

    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 on git cat-file -p, and similar. To avoid cluttering this thread, I'm going to close this issue for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions