Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
[[constraint]]
name = "gopkg.in/src-d/go-git.v4"
source = "github.com/src-d/go-git"
revision = "5cc316baa64287c7e56cb7372a5046c30fd955c1"
revision = "208b3c3c32beaab14ebb7adf162fc136c939e99c"

[[constraint]]
name = "gopkg.in/src-d/go-git-fixtures.v3"
Expand Down
28 changes: 15 additions & 13 deletions cmd/gitbase/command/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
gopilosa "github.com/pilosa/go-pilosa"
"github.com/sirupsen/logrus"
"github.com/uber/jaeger-client-go/config"
"gopkg.in/src-d/go-git.v4/plumbing/cache"
sqle "gopkg.in/src-d/go-mysql-server.v0"
"gopkg.in/src-d/go-mysql-server.v0/server"
"gopkg.in/src-d/go-mysql-server.v0/sql"
Expand All @@ -39,18 +40,19 @@ type Server struct {
pool *gitbase.RepositoryPool
name string

Version string // Version of the application.
Directories []string `short:"d" long:"directories" description:"Path where the git repositories are located (standard and siva), multiple directories can be defined. Accepts globs."`
Depth int `long:"depth" default:"1000" description:"load repositories looking at less than <depth> nested subdirectories."`
Host string `long:"host" default:"localhost" description:"Host where the server is going to listen"`
Port int `short:"p" long:"port" default:"3306" description:"Port where the server is going to listen"`
User string `short:"u" long:"user" default:"root" description:"User name used for connection"`
Password string `short:"P" long:"password" default:"" description:"Password used for connection"`
PilosaURL string `long:"pilosa" default:"http://localhost:10101" description:"URL to your pilosa server" env:"PILOSA_ENDPOINT"`
IndexDir string `short:"i" long:"index" default:"/var/lib/gitbase/index" description:"Directory where the gitbase indexes information will be persisted." env:"GITBASE_INDEX_DIR"`
DisableSquash bool `long:"no-squash" description:"Disables the table squashing."`
TraceEnabled bool `long:"trace" env:"GITBASE_TRACE" description:"Enables jaeger tracing"`
ReadOnly bool `short:"r" long:"readonly" description:"Only allow read queries. This disables creating and deleting indexes as well." env:"GITBASE_READONLY"`
Version string // Version of the application.
Directories []string `short:"d" long:"directories" description:"Path where the git repositories are located (standard and siva), multiple directories can be defined. Accepts globs."`
Depth int `long:"depth" default:"1000" description:"load repositories looking at less than <depth> nested subdirectories."`
Host string `long:"host" default:"localhost" description:"Host where the server is going to listen."`
Port int `short:"p" long:"port" default:"3306" description:"Port where the server is going to listen."`
User string `short:"u" long:"user" default:"root" description:"User name used for connection."`
Password string `short:"P" long:"password" default:"" description:"Password used for connection."`
PilosaURL string `long:"pilosa" default:"http://localhost:10101" description:"URL to your pilosa server." env:"PILOSA_ENDPOINT"`
IndexDir string `short:"i" long:"index" default:"/var/lib/gitbase/index" description:"Directory where the gitbase indexes information will be persisted." env:"GITBASE_INDEX_DIR"`
CacheSize cache.FileSize `long:"cache" default:"536870912" description:"Object cache size" env:"GITBASE_CACHE_SIZE"`
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

could you change the default to something more human-friendly? like 100 and allows only MB

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yeah sure, how about 512MB?

DisableSquash bool `long:"no-squash" description:"Disables the table squashing."`
TraceEnabled bool `long:"trace" env:"GITBASE_TRACE" description:"Enables jaeger tracing"`
ReadOnly bool `short:"r" long:"readonly" description:"Only allow read queries. This disables creating and deleting indexes as well." env:"GITBASE_READONLY"`

SkipGitErrors bool // SkipGitErrors disables failing when Git errors are found.
DisableGit bool `long:"no-git" description:"disable the load of git standard repositories."`
Expand Down Expand Up @@ -159,7 +161,7 @@ func (c *Server) buildDatabase() error {
c.engine = NewDatabaseEngine(c.ReadOnly, c.Version)
}

c.pool = gitbase.NewRepositoryPool()
c.pool = gitbase.NewRepositoryPool(c.CacheSize)

if err := c.addDirectories(); err != nil {
return err
Expand Down
3 changes: 2 additions & 1 deletion common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/stretchr/testify/require"
fixtures "gopkg.in/src-d/go-git-fixtures.v3"
"gopkg.in/src-d/go-git.v4/plumbing/cache"
"gopkg.in/src-d/go-mysql-server.v0/sql"
)

Expand Down Expand Up @@ -35,7 +36,7 @@ func buildSession(t *testing.T, repos fixtures.Fixtures,

require.NoError(fixtures.Init())

pool := NewRepositoryPool()
pool := NewRepositoryPool(cache.DefaultMaxSize)
for _, fixture := range repos {
path := fixture.Worktree().Root()
ok, err := IsGitRepo(path)
Expand Down
19 changes: 11 additions & 8 deletions fs_error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
billy "gopkg.in/src-d/go-billy.v4"
fixtures "gopkg.in/src-d/go-git-fixtures.v3"
git "gopkg.in/src-d/go-git.v4"
"gopkg.in/src-d/go-git.v4/plumbing/cache"
"gopkg.in/src-d/go-git.v4/storage/filesystem"
"gopkg.in/src-d/go-mysql-server.v0/sql"
)
Expand Down Expand Up @@ -56,7 +57,7 @@ func setupErrorRepos(t *testing.T) (*sql.Context, CleanupFunc) {
fixture := fixtures.ByTag("worktree").One()
baseFS := fixture.Worktree()

pool := NewRepositoryPool()
pool := NewRepositoryPool(cache.DefaultMaxSize)

fs, err := brokenFS(brokenPackfile, baseFS)
require.NoError(err)
Expand Down Expand Up @@ -118,23 +119,21 @@ func testTable(t *testing.T, tableName string, number int) {
}

type billyRepository struct {
id string
fs billy.Filesystem
id string
fs billy.Filesystem
cache cache.Object
}

func billyRepo(id string, fs billy.Filesystem) repository {
return &billyRepository{id, fs}
return &billyRepository{id, fs, cache.NewObjectLRUDefault()}
}

func (r *billyRepository) ID() string {
return r.id
}

func (r *billyRepository) Repo() (*Repository, error) {
storage, err := filesystem.NewStorage(r.fs)
if err != nil {
return nil, err
}
storage := filesystem.NewStorage(r.fs, r.cache)

repo, err := git.Open(storage, r.fs)
if err != nil {
Expand All @@ -152,6 +151,10 @@ func (r *billyRepository) Path() string {
return r.id
}

func (r *billyRepository) Cache() cache.Object {
return r.cache
}

type brokenType uint64

const (
Expand Down
7 changes: 4 additions & 3 deletions integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/src-d/gitbase/internal/function"
"github.com/stretchr/testify/require"
fixtures "gopkg.in/src-d/go-git-fixtures.v3"
"gopkg.in/src-d/go-git.v4/plumbing/cache"
sqle "gopkg.in/src-d/go-mysql-server.v0"
"gopkg.in/src-d/go-mysql-server.v0/sql"
"gopkg.in/src-d/go-mysql-server.v0/sql/analyzer"
Expand All @@ -33,7 +34,7 @@ func TestIntegration(t *testing.T) {

path := fixtures.ByTag("worktree").One().Worktree().Root()

pool := gitbase.NewRepositoryPool()
pool := gitbase.NewRepositoryPool(cache.DefaultMaxSize)
require.NoError(t, pool.AddGitWithID("worktree", path))

testCases := []struct {
Expand Down Expand Up @@ -443,7 +444,7 @@ func TestMissingHeadRefs(t *testing.T) {
"_testdata",
)

pool := gitbase.NewRepositoryPool()
pool := gitbase.NewRepositoryPool(cache.DefaultMaxSize)
require.NoError(
filepath.Walk(path, func(path string, info os.FileInfo, err error) error {
if err != nil {
Expand Down Expand Up @@ -829,7 +830,7 @@ func setup(t testing.TB) (*sqle.Engine, *gitbase.RepositoryPool, func()) {
require.NoError(t, fixtures.Clean())
}

pool := gitbase.NewRepositoryPool()
pool := gitbase.NewRepositoryPool(cache.DefaultMaxSize)
for _, f := range fixtures.ByTag("worktree") {
pool.AddGitWithID("worktree", f.Worktree().Root())
}
Expand Down
3 changes: 2 additions & 1 deletion internal/function/uast_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"gopkg.in/bblfsh/sdk.v1/protocol"
"gopkg.in/bblfsh/sdk.v1/uast"
fixtures "gopkg.in/src-d/go-git-fixtures.v3"
"gopkg.in/src-d/go-git.v4/plumbing/cache"
"gopkg.in/src-d/go-mysql-server.v0/sql"
"gopkg.in/src-d/go-mysql-server.v0/sql/expression"
)
Expand Down Expand Up @@ -421,7 +422,7 @@ func setup(t *testing.T) (*sql.Context, func()) {
t.Helper()
require.NoError(t, fixtures.Init())

pool := gitbase.NewRepositoryPool()
pool := gitbase.NewRepositoryPool(cache.DefaultMaxSize)
for _, f := range fixtures.ByTag("worktree") {
pool.AddGit(f.Worktree().Root())
}
Expand Down
11 changes: 2 additions & 9 deletions packfiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,7 @@ func getUnpackedObject(repo repository, hash plumbing.Hash) (o object.Object, er

defer ioutil.CheckClose(f, &err)

storage, err := filesystem.NewStorage(fs)
if err != nil {
return nil, err
}
storage := filesystem.NewStorage(fs, repo.Cache())

obj := storage.NewEncodedObject()
r, err := objfile.NewReader(f)
Expand Down Expand Up @@ -224,11 +221,7 @@ func newRepoObjectDecoder(
return nil, err
}

storage, err := filesystem.NewStorage(fs)
if err != nil {
_ = packf.Close()
return nil, err
}
storage := filesystem.NewStorage(fs, repo.Cache())

idx, err := openPackfileIndex(dot, hash)
if err != nil {
Expand Down
5 changes: 3 additions & 2 deletions packfiles_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ import (

"github.com/stretchr/testify/require"
"gopkg.in/src-d/go-git.v4/plumbing"
"gopkg.in/src-d/go-git.v4/plumbing/cache"
)

var testSivaFilePath = filepath.Join("_testdata", "fff7062de8474d10a67d417ccea87ba6f58ca81d.siva")

func TestRepositoryPackfiles(t *testing.T) {
require := require.New(t)

fs, packfiles, err := repositoryPackfiles(sivaRepo("siva", testSivaFilePath))
fs, packfiles, err := repositoryPackfiles(sivaRepo("siva", testSivaFilePath, cache.NewObjectLRUDefault()))

require.NoError(err)
require.Equal([]plumbing.Hash{
Expand All @@ -24,7 +25,7 @@ func TestRepositoryPackfiles(t *testing.T) {
}

func TestRepositoryIndex(t *testing.T) {
idx, err := newRepositoryIndex(sivaRepo("siva", testSivaFilePath))
idx, err := newRepositoryIndex(sivaRepo("siva", testSivaFilePath, cache.NewObjectLRUDefault()))
require.NoError(t, err)

testCases := []struct {
Expand Down
5 changes: 3 additions & 2 deletions repositories_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"testing"

"github.com/stretchr/testify/require"
"gopkg.in/src-d/go-git.v4/plumbing/cache"
"gopkg.in/src-d/go-mysql-server.v0/sql"
"gopkg.in/src-d/go-mysql-server.v0/sql/expression"
)
Expand Down Expand Up @@ -36,10 +37,10 @@ func TestRepositoriesTable_RowIter(t *testing.T) {
"seven", "eight", "nine",
}

pool := NewRepositoryPool()
pool := NewRepositoryPool(cache.DefaultMaxSize)

for _, id := range repoIDs {
pool.Add(gitRepo(id, ""))
pool.Add(gitRepo(id, "", pool.cache))
}

session := NewSession(pool)
Expand Down
Loading