Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "get metarange", "get range" API endpoints #1465

Merged
merged 5 commits into from
Feb 17, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
56 changes: 56 additions & 0 deletions api/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1281,6 +1281,62 @@ func writeSymlinkToS3(params metadata.CreateSymlinkParams, repo *catalog.Reposit
return err
}

func (c *Controller) MetadataGetMetarangeHandler() metadata.GetMetaRangeHandler {
return metadata.GetMetaRangeHandlerFunc(func(params metadata.GetMetaRangeParams, user *models.User) middleware.Responder {
deps, err := c.setupRequest(user, params.HTTPRequest, []permissions.Permission{
{
Action: permissions.ListObjectsAction,
Resource: permissions.RepoArn(params.Repository),
},
{
Action: permissions.ReadRepositoryAction,
Resource: permissions.RepoArn(params.Repository),
},
})
if err != nil {
return metadata.NewGetMetaRangeUnauthorized().WithPayload(responseErrorFrom(err))
}
deps.LogAction("metadata_get_metarange")
cataloger := deps.Cataloger

metarange, err := cataloger.GetMetaRange(deps.ctx, params.Repository, params.MetaRange)
if err != nil {
return metadata.NewGetMetaRangeDefault(http.StatusInternalServerError).WithPayload(responseErrorFrom(err))
}
ret := metadata.NewGetMetaRangeOK()
ret.Location = metarange.Address
return ret
})
}

func (c *Controller) MetadataGetRangeHandler() metadata.GetRangeHandler {
return metadata.GetRangeHandlerFunc(func(params metadata.GetRangeParams, user *models.User) middleware.Responder {
deps, err := c.setupRequest(user, params.HTTPRequest, []permissions.Permission{
{
Action: permissions.ListObjectsAction,
Resource: permissions.RepoArn(params.Repository),
},
{
Action: permissions.ReadRepositoryAction,
Resource: permissions.RepoArn(params.Repository),
},
})
if err != nil {
return metadata.NewGetRangeUnauthorized().WithPayload(responseErrorFrom(err))
}
deps.LogAction("metadata_get_range")
cataloger := deps.Cataloger

rng, err := cataloger.GetRange(deps.ctx, params.Repository, params.Range)
if err != nil {
return metadata.NewGetRangeDefault(http.StatusInternalServerError).WithPayload(responseErrorFrom(err))
}
ret := metadata.NewGetRangeOK()
ret.Location = rng.Address
return ret
})
}

func (c *Controller) ObjectsListObjectsHandler() objects.ListObjectsHandler {
return objects.ListObjectsHandlerFunc(func(params objects.ListObjectsParams, user *models.User) middleware.Responder {
deps, err := c.setupRequest(user, params.HTTPRequest, []permissions.Permission{
Expand Down
6 changes: 6 additions & 0 deletions catalog/cataloger.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package catalog
import (
"context"
"io"

"github.com/treeverse/lakefs/graveler"
)

const (
Expand Down Expand Up @@ -108,5 +110,9 @@ type Cataloger interface {
LoadBranches(ctx context.Context, repositoryID, branchesMetaRangeID string) error
LoadTags(ctx context.Context, repositoryID, tagsMetaRangeID string) error

// forward metadata for thick clients
GetMetaRange(ctx context.Context, repositoryID, metaRangeID string) (graveler.MetaRangeInfo, error)
GetRange(ctx context.Context, repositoryID, rangeID string) (graveler.RangeInfo, error)

io.Closer
}
9 changes: 9 additions & 0 deletions catalog/entry_catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ type Store interface {
graveler.KeyValueStore
graveler.VersionController
graveler.Dumper
graveler.Plumbing
graveler.Loader
}

Expand Down Expand Up @@ -613,3 +614,11 @@ func (e *EntryCatalog) PreMergeHook(ctx context.Context, eventID uuid.UUID, repo
func (e *EntryCatalog) PostMergeHook(ctx context.Context, eventID uuid.UUID, repositoryRecord graveler.RepositoryRecord, destination graveler.BranchID, source graveler.Ref, commitRecord graveler.CommitRecord) error {
return nil
}

func (e *EntryCatalog) GetMetaRange(ctx context.Context, repositoryID graveler.RepositoryID, metaRangeID graveler.MetaRangeID) (graveler.MetaRangeInfo, error) {
return e.Store.GetMetaRange(ctx, repositoryID, metaRangeID)
}

func (e *EntryCatalog) GetRange(ctx context.Context, repositoryID graveler.RepositoryID, rangeID graveler.RangeID) (graveler.RangeInfo, error) {
return e.Store.GetRange(ctx, repositoryID, rangeID)
}
8 changes: 8 additions & 0 deletions catalog/fake_graveler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ func (g *FakeGraveler) DumpTags(ctx context.Context, repositoryID graveler.Repos
panic("implement me")
}

func (g *FakeGraveler) GetMetaRange(ctx context.Context, repositoryID graveler.RepositoryID, metaRangeID graveler.MetaRangeID) (graveler.MetaRangeInfo, error) {
panic("implement me")
}

func (g *FakeGraveler) GetRange(ctx context.Context, repositoryID graveler.RepositoryID, rangeID graveler.RangeID) (graveler.RangeInfo, error) {
panic("implement me")
}

func fakeGravelerBuildKey(repositoryID graveler.RepositoryID, ref graveler.Ref, key graveler.Key) string {
return strings.Join([]string{repositoryID.String(), ref.String(), key.String()}, "/")
}
Expand Down
8 changes: 8 additions & 0 deletions catalog/rocks_cataloger.go
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,14 @@ func (c *cataloger) LoadTags(ctx context.Context, repositoryID, tagsMetaRangeID
return c.EntryCatalog.LoadTags(ctx, graveler.RepositoryID(repositoryID), graveler.MetaRangeID(tagsMetaRangeID))
}

func (c *cataloger) GetMetaRange(ctx context.Context, repositoryID, metaRangeID string) (graveler.MetaRangeInfo, error) {
return c.EntryCatalog.GetMetaRange(ctx, graveler.RepositoryID(repositoryID), graveler.MetaRangeID(metaRangeID))
}

func (c *cataloger) GetRange(ctx context.Context, repositoryID, rangeID string) (graveler.RangeInfo, error) {
return c.EntryCatalog.GetRange(ctx, graveler.RepositoryID(repositoryID), graveler.RangeID(rangeID))
}

func (c *cataloger) Close() error {
return nil
}
Expand Down
Loading