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

storage/dotgit: add KeepDescriptors option #942

Merged
merged 4 commits into from
Sep 6, 2018

Conversation

jfontan
Copy link
Contributor

@jfontan jfontan commented Aug 30, 2018

Needs #941

This option maintains packfile file descriptors opened after reading objects from them. It improves performance as it does not have to be opening packfiles each time an object is needed.

Also adds Close to EncodedObjectStorer to close all the files manually.

@jfontan jfontan requested a review from ajnavarro August 30, 2018 18:31
@jfontan jfontan changed the title storage/dotgit: add KeepDescriptors option [WIP] storage/dotgit: add KeepDescriptors option Aug 30, 2018
options.go Outdated
// performed.
type PlainOpenOptions struct {
// Storage layer options.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe we should keep this out of Plain* methods and avoid adding Close to general interface. Just adding it to the filesystem implementation would be enough, and this option would be available only by creating the filesystem storage directly.

This way we avoid redundancy in other implementatons or end up exposing a lot of storage-specific options here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@jfontan jfontan force-pushed the improvement/maintain-packfiles-open branch 2 times, most recently from fb41588 to b43e2a0 Compare August 31, 2018 13:28
@jfontan jfontan changed the title [WIP] storage/dotgit: add KeepDescriptors option storage/dotgit: add KeepDescriptors option Aug 31, 2018
@jfontan jfontan force-pushed the improvement/maintain-packfiles-open branch from b43e2a0 to 2dfcef2 Compare September 3, 2018 09:38

// Options holds configuration for the storage.
type Options struct {
// ExclusiveAccess means that the filesystem is not modified externally
Copy link
Contributor

Choose a reason for hiding this comment

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

Since this is options strictly related to a one implementation I don't believe this is the right place to put this options, this options should be pass and used only to the file system implementation

@@ -60,18 +61,35 @@ var (
// The DotGit type represents a local git repository on disk. This
// type is not zero-value-safe, use the New function to initialize it.
type DotGit struct {
fs billy.Filesystem
Options storer.Options
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be private, if since can't be changed

@@ -268,7 +269,9 @@ func (s *ObjectStorage) getFromPackfile(h plumbing.Hash, canBeDelta bool) (
return nil, err
}

defer ioutil.CheckClose(f, &err)
if !s.dir.Options.KeepDescriptors {
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of requesting the options to dogGit, should be accessed from a local pointer to the storer.

@@ -411,6 +414,11 @@ func (s *ObjectStorage) buildPackfileIters(t plumbing.ObjectType, seen map[plumb
}, nil
}

// Close closes all opened files.
func (s *ObjectStorage) Close() error {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not covered by a test

d.objectList = nil
}

func (d *DotGit) genObjectList() error {
Copy link
Contributor

Choose a reason for hiding this comment

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

This function is not covered by a test

Copy link
Contributor Author

Choose a reason for hiding this comment

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

By default go coverage only annotates files from the same package tested. The test that exercise this part belongs to storage/filesystem. That's why it does not appear in coverage. The same happens with other functions. I'll add new tests in storage/filesystem/dotgit that forces the usage of those functions.

return d.forEachObjectHash(fun)
}

err := d.genObjectList()
Copy link
Contributor

Choose a reason for hiding this comment

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

This code isn't covered either.

@jfontan jfontan changed the title storage/dotgit: add KeepDescriptors option [WIP] storage/dotgit: add KeepDescriptors option Sep 3, 2018
This option maintains packfile file descriptors opened after reading
objects from them. It improves performance as it does not have to be
opening packfiles each time an object is needed.

Also adds Close to EncodedObjectStorer to close all the files manualy.

Signed-off-by: Javi Fontan <[email protected]>
@jfontan jfontan force-pushed the improvement/maintain-packfiles-open branch from 2dfcef2 to 6384ab9 Compare September 4, 2018 10:41
@jfontan jfontan changed the title [WIP] storage/dotgit: add KeepDescriptors option storage/dotgit: add KeepDescriptors option Sep 4, 2018
@@ -40,6 +40,8 @@ type EncodedObjectStorer interface {
// HasEncodedObject returns ErrObjNotFound if the object doesn't
// exist. If the object does exist, it returns nil.
HasEncodedObject(plumbing.Hash) error
// Close any opened files.
Close() error
Copy link
Collaborator

Choose a reason for hiding this comment

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

What about having Close() only on the filesystem implementation, not on the general interface?

Copy link
Contributor Author

@jfontan jfontan Sep 4, 2018

Choose a reason for hiding this comment

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

Somehow I understood that you didn't want to export Close in git.Repository. It's now deleted from EncodedObjectStorer.

Copy link
Collaborator

@smola smola left a comment

Choose a reason for hiding this comment

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

As per my previous comment.

@@ -157,3 +157,7 @@ func (o *MockObjectStorage) IterEncodedObjects(t plumbing.ObjectType) (EncodedOb
func (o *MockObjectStorage) Begin() Transaction {
return nil
}

func (o *MockObjectStorage) Close() error {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this is not needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right. Deleted that and Close in memory storer. Also added a new test for filesystem storer and KeepDescriptors option.

Also delete Close from MockObjectStorage and memory storer.

Signed-off-by: Javi Fontan <[email protected]>
@smola
Copy link
Collaborator

smola commented Sep 6, 2018

@jfontan AppVeyor is failing with OOM when executing storage/filesystem tests. It looks related to the new test, since other builds are ok and this one failed multiple times.

@jfontan
Copy link
Contributor Author

jfontan commented Sep 6, 2018

It is indeed the test. The comparison is generating diffs of the packfiles instead of checking if they are the same. Working on a fix.

@jfontan jfontan force-pushed the improvement/maintain-packfiles-open branch 2 times, most recently from 1865ade to c0cacb2 Compare September 6, 2018 17:09
Using equals to compare files it uses diff to do so. This can
potentially consume lots of ram. Changed the comparison to use file
offsets. If the descriptor is reused the offset is maintained.

Signed-off-by: Javi Fontan <[email protected]>
@jfontan jfontan force-pushed the improvement/maintain-packfiles-open branch from c0cacb2 to 8176f08 Compare September 6, 2018 17:14
@jfontan
Copy link
Contributor Author

jfontan commented Sep 6, 2018

@smola it seems the bug in windows tests is fixed.

@mcuadros mcuadros merged commit 174f373 into src-d:master Sep 6, 2018
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.

3 participants