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

plumbing/storer: add ExclusiveAccess option to Storer #941

Merged
merged 8 commits into from
Sep 4, 2018

Conversation

jfontan
Copy link
Contributor

@jfontan jfontan commented Aug 30, 2018

Adds ExclusiveAccess configuration to filesystem.Storage and filesystem.DotGit. This option means that the git repository is not expected to be modified while open and enables some optimizations.

Each time a file is accessed the storer tries to open an object file for the requested hash. When this is done for a lot of objects it is expensive. With ExclusiveAccess option a list of object files is generated the first time an object is accessed and used to check if exists instead of using system calls.

A similar optimization is done for packfiles.

Also adds Static configuration to Storage and DotGit. This option means
that the git repository is not expected to be modified while open and
enables some optimizations.

Each time a file is accessed the storer tries to open an object file for
the requested hash. When this is done for a lot of objects it is
expensive. With Static option a list of object files is generated the
first time an object is accessed and used to check if exists instead of
using system calls.

A similar optimization is done for packfiles.

Signed-off-by: Javi Fontan <[email protected]>
@jfontan jfontan requested review from mcuadros and a team August 30, 2018 13:32
// Objects returns a slice with the hashes of objects found under the
// .git/objects/ directory.
// ForEachObjectHash iterates over the hashes of objects found under the
// .git/objects/ directory and executes the provided .
Copy link
Contributor

Choose a reason for hiding this comment

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

the provided function?

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
Copy link
Contributor Author

jfontan commented Aug 30, 2018

I'm also going to move StorageOptions to options.go as do not make sense repeating the same structure in repository, filesystem.Storage and DotGit.

options.go Outdated
@@ -431,6 +431,8 @@ type PlainOpenOptions struct {
// DetectDotGit defines whether parent directories should be
// walked until a .git directory or file is found.
DetectDotGit bool
// Static means that the repository won't be modified while open.
Static bool
Copy link
Contributor

Choose a reason for hiding this comment

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

so maybe readonly

Copy link
Contributor

Choose a reason for hiding this comment

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

readonly?

Copy link
Contributor Author

@jfontan jfontan Aug 30, 2018

Choose a reason for hiding this comment

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

I thought about read only but what it really means is that it is not modified from the outside. I've added packfile and hash cache invalidation when new objects or packfiles are created. Mainly because I wanted to pass all tests in this mode. So it is in fact ReadWrite but assumes that only go-git is changing things.

Anyway, I agree that Static may not be the best name but could not find any other that reflected that is not modified from the outside.

// Objects returns a slice with the hashes of objects found under the
// .git/objects/ directory.
// ForEachObjectHash iterates over the hashes of objects found under the
// .git/objects/ directory and executes the provided .
func (d *DotGit) ForEachObjectHash(fun func(plumbing.Hash) error) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

yeah, it should be fun ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is fun indeed!

@kuba--
Copy link
Contributor

kuba-- commented Aug 31, 2018

Maybe 👍 for this PR speed up merging ;) So we can start extending Storage's Options by adding configurable cache size (src-d/gitbase#440)

@ajnavarro ajnavarro requested a review from smola August 31, 2018 08:49
@smola
Copy link
Collaborator

smola commented Aug 31, 2018

@jfontan Just a doubt about naming and behaviour: Does this mean that it will not be modified externally or that it won't be modified even by go-git itself while open?

If it's the later, maybe it should be named Immutable?

@jfontan
Copy link
Contributor Author

jfontan commented Aug 31, 2018

@smola The first case. We don't expect it to be modified externally. We can write with go-git (create new packfiles or objects).

Maybe Exclusive or ExclusiveAccess is better?

@smola
Copy link
Collaborator

smola commented Aug 31, 2018

@jfontan ExclusiveAccess looks explicit enough.

@jfontan jfontan changed the title git: add Static option to PlainOpen plumbing/storer: add ExclusiveAccess option to Storer Aug 31, 2018
@@ -11,6 +12,8 @@ import (
// standard git format (this is, the .git directory). Zero values of this type
// are not safe to use, see the NewStorage function below.
type Storage struct {
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.

Why is an embedded struct? and not a private field?

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. There's no reason why it should be embedded or public. It's now changed.

@jfontan jfontan changed the title plumbing/storer: add ExclusiveAccess option to Storer [WIP] plumbing/storer: add ExclusiveAccess option to Storer Sep 3, 2018
This functionality was already tested in storage/filesystem.
The coverage tool only takes into account files from the same
package of the test.

Signed-off-by: Javi Fontan <[email protected]>
@jfontan jfontan changed the title [WIP] plumbing/storer: add ExclusiveAccess option to Storer plumbing/storer: add ExclusiveAccess option to Storer Sep 4, 2018
@mcuadros mcuadros merged commit 2f15838 into src-d:master Sep 4, 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.

6 participants