Skip to content
This repository has been archived by the owner on Sep 11, 2020. It is now read-only.

filesystem: ObjectStorage, MaxOpenDescriptors option #1123

Merged
merged 1 commit into from
Apr 22, 2019

Conversation

saracen
Copy link
Contributor

@saracen saracen commented Apr 21, 2019

The MaxOpenDescriptors option provides a middle ground solution between keeping all pack files open (as offered by the KeepDescriptors option) and keeping none open.

This PR is a modification of #1109. This version moves to keeping packfile objects around, rather than just the open file. Whilst updating this, PR #1120 was opened that offers effectively the same solution to that problem. But there's a few other changes here in relation to that, too:

  • Using KeepDescriptors when calling NewStorageWithOptions no longer passes the option to dotgit, as there's little point in keeping a map of open files in both locations.
  • Packfile's scanner can be accessed (packfile.Scanner()), this avoids creating a new scanner around the file when the packfile is already open (as done here https://github.com/src-d/go-git/pull/1123/files#diff-e927e977f53290ca7a0e091f6ffd9081R456).
  • The dotgit version now uses the packfile's hash as the map key, instead of the path name. This results in a nice performance boost when iterating over many files, as objectPackPath (using path.Join) isn't as fast as you'd imagine.

@jfontan
Copy link
Contributor

jfontan commented Apr 22, 2019

LGTM. Thanks!

@@ -187,6 +191,57 @@ func (s *ObjectStorage) encodedObjectSizeFromUnpacked(h plumbing.Hash) (
return size, err
}

func (s *ObjectStorage) packfile(idx idxfile.Index, pack plumbing.Hash) (*packfile.Packfile, error) {
if s.packfiles == nil {
if s.options.MaxOpenDescriptors > 0 {
Copy link
Contributor

@mcuadros mcuadros Apr 22, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you move this logic to a function? in general review this long function

Copy link
Contributor Author

@saracen saracen Apr 22, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've now split it up so the code that handles what is more clearly defined. At the start we check to see if the packfile is cached with packfileFromCache, at the end we do storePackfileInCache if a new packfile was opened.

storePackfileInCache is still fairly long, but I think it's easier to follow now. Early returns when it can and then handles the freelist behavior.

@saracen saracen force-pushed the object-storage-open-packfile branch from 42bbcaf to f5c23da Compare April 22, 2019 22:41
The MaxOpenDescriptors option provides a middle ground solution between keeping
all packfiles open (as offered by the KeepDescriptors option) and keeping none
open.

Signed-off-by: Arran Walker <arran.walker@fiveturns.org>
@mcuadros mcuadros merged commit eb243ba into src-d:master Apr 22, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants