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 storageID to gc manager #8684

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions pkg/catalog/catalog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -895,9 +895,9 @@ func createPrepareUncommittedTestScenario(t *testing.T, repositoryID string, num

if numRecords > 0 {
test.GarbageCollectionManager.EXPECT().
GetUncommittedLocation(gomock.Any(), gomock.Any()).
GetUncommittedLocation(gomock.Any(), gomock.Any(), gomock.Any()).
MinTimes(1).
DoAndReturn(func(runID string, sn graveler.StorageNamespace) (string, error) {
DoAndReturn(func(runID string, storageID graveler.StorageID, sn graveler.StorageNamespace) (string, error) {
return fmt.Sprintf("%s/retention/gc/uncommitted/%s/uncommitted/", "_lakefs", runID), nil
})
}
Expand Down
20 changes: 10 additions & 10 deletions pkg/graveler/graveler.go
Original file line number Diff line number Diff line change
Expand Up @@ -1640,15 +1640,15 @@ func (g *Graveler) GetStagingToken(ctx context.Context, repository *RepositoryRe
}

func (g *Graveler) getGarbageCollectionRules(ctx context.Context, repository *RepositoryRecord) (*GarbageCollectionRules, error) {
return g.garbageCollectionManager.GetRules(ctx, repository.StorageNamespace)
return g.garbageCollectionManager.GetRules(ctx, repository.StorageID, repository.StorageNamespace)
}

func (g *Graveler) GetGarbageCollectionRules(ctx context.Context, repository *RepositoryRecord) (*GarbageCollectionRules, error) {
return g.getGarbageCollectionRules(ctx, repository)
}

func (g *Graveler) SetGarbageCollectionRules(ctx context.Context, repository *RepositoryRecord, rules *GarbageCollectionRules) error {
return g.garbageCollectionManager.SaveRules(ctx, repository.StorageNamespace, rules)
return g.garbageCollectionManager.SaveRules(ctx, repository.StorageID, repository.StorageNamespace, rules)
}

func (g *Graveler) SaveGarbageCollectionCommits(ctx context.Context, repository *RepositoryRecord) (*GarbageCollectionRunMetadata, error) {
Expand All @@ -1661,11 +1661,11 @@ func (g *Graveler) SaveGarbageCollectionCommits(ctx context.Context, repository
if err != nil {
return nil, fmt.Errorf("save garbage collection commits: %w", err)
}
commitsLocation, err := g.garbageCollectionManager.GetCommitsCSVLocation(runID, repository.StorageNamespace)
commitsLocation, err := g.garbageCollectionManager.GetCommitsCSVLocation(runID, repository.StorageID, repository.StorageNamespace)
if err != nil {
return nil, err
}
addressLocation, err := g.garbageCollectionManager.GetAddressesLocation(repository.StorageNamespace)
addressLocation, err := g.garbageCollectionManager.GetAddressesLocation(repository.StorageID, repository.StorageNamespace)
if err != nil {
return nil, err
}
Expand All @@ -1678,7 +1678,7 @@ func (g *Graveler) SaveGarbageCollectionCommits(ctx context.Context, repository
}

func (g *Graveler) GCGetUncommittedLocation(repository *RepositoryRecord, runID string) (string, error) {
return g.garbageCollectionManager.GetUncommittedLocation(runID, repository.StorageNamespace)
return g.garbageCollectionManager.GetUncommittedLocation(runID, repository.StorageID, repository.StorageNamespace)
}

func (g *Graveler) GCNewRunID() string {
Expand Down Expand Up @@ -3724,14 +3724,14 @@ func (c *commitValueIterator) Close() {
}

type GarbageCollectionManager interface {
GetRules(ctx context.Context, storageNamespace StorageNamespace) (*GarbageCollectionRules, error)
SaveRules(ctx context.Context, storageNamespace StorageNamespace, rules *GarbageCollectionRules) error
GetRules(ctx context.Context, storageID StorageID, storageNamespace StorageNamespace) (*GarbageCollectionRules, error)
SaveRules(ctx context.Context, storageID StorageID, storageNamespace StorageNamespace, rules *GarbageCollectionRules) error

SaveGarbageCollectionCommits(ctx context.Context, repository *RepositoryRecord, rules *GarbageCollectionRules) (string, error)
GetCommitsCSVLocation(runID string, sn StorageNamespace) (string, error)
GetCommitsCSVLocation(runID string, storageID StorageID, sn StorageNamespace) (string, error)
SaveGarbageCollectionUncommitted(ctx context.Context, repository *RepositoryRecord, filename, runID string) error
GetUncommittedLocation(runID string, sn StorageNamespace) (string, error)
GetAddressesLocation(sn StorageNamespace) (string, error)
GetUncommittedLocation(runID string, storageID StorageID, sn StorageNamespace) (string, error)
GetAddressesLocation(storageID StorageID, sn StorageNamespace) (string, error)
NewID() string
}

Expand Down
40 changes: 20 additions & 20 deletions pkg/graveler/mock/graveler.go

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

31 changes: 14 additions & 17 deletions pkg/graveler/retention/garbage_collection_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,39 +34,36 @@ type GarbageCollectionManager struct {
committedBlockStoragePrefix string
}

func (m *GarbageCollectionManager) GetCommitsCSVLocation(runID string, sn graveler.StorageNamespace) (string, error) {
func (m *GarbageCollectionManager) GetCommitsCSVLocation(runID string, storageID graveler.StorageID, sn graveler.StorageNamespace) (string, error) {
key := fmt.Sprintf(commitsFileSuffixTemplate, m.committedBlockStoragePrefix, runID)
// TODO (gilo): replace StorageID with a real value
qk, err := m.blockAdapter.ResolveNamespace("", sn.String(), key, block.IdentifierTypeRelative)
qk, err := m.blockAdapter.ResolveNamespace(string(storageID), sn.String(), key, block.IdentifierTypeRelative)
if err != nil {
return "", err
}
return qk.Format(), nil
}

func (m *GarbageCollectionManager) GetAddressesLocation(sn graveler.StorageNamespace) (string, error) {
func (m *GarbageCollectionManager) GetAddressesLocation(storageID graveler.StorageID, sn graveler.StorageNamespace) (string, error) {
key := fmt.Sprintf(addressesFilePrefixTemplate, m.committedBlockStoragePrefix)
// TODO (gilo): replace StorageID with a real value
qk, err := m.blockAdapter.ResolveNamespace("", sn.String(), key, block.IdentifierTypeRelative)
qk, err := m.blockAdapter.ResolveNamespace(string(storageID), sn.String(), key, block.IdentifierTypeRelative)
if err != nil {
return "", err
}
return qk.Format(), nil
}

// GetUncommittedLocation return full path to underlying storage path to store uncommitted information
func (m *GarbageCollectionManager) GetUncommittedLocation(runID string, sn graveler.StorageNamespace) (string, error) {
func (m *GarbageCollectionManager) GetUncommittedLocation(runID string, storageID graveler.StorageID, sn graveler.StorageNamespace) (string, error) {
key := fmt.Sprintf(uncommittedFilePrefixTemplate, m.committedBlockStoragePrefix, runID)
// TODO (gilo): replace StorageID with a real value
qk, err := m.blockAdapter.ResolveNamespace("", sn.String(), key, block.IdentifierTypeRelative)
qk, err := m.blockAdapter.ResolveNamespace(string(storageID), sn.String(), key, block.IdentifierTypeRelative)
if err != nil {
return "", err
}
return qk.Format(), nil
}

func (m *GarbageCollectionManager) SaveGarbageCollectionUncommitted(ctx context.Context, repository *graveler.RepositoryRecord, filename, runID string) error {
location, err := m.GetUncommittedLocation(runID, repository.StorageNamespace)
location, err := m.GetUncommittedLocation(runID, repository.StorageID, repository.StorageNamespace)
if err != nil {
return err
}
Expand All @@ -85,7 +82,7 @@ func (m *GarbageCollectionManager) SaveGarbageCollectionUncommitted(ctx context.
}
location += filename
_, err = m.blockAdapter.Put(ctx, block.ObjectPointer{
// TODO (gilo): ObjectPointer init - add StorageID here?
StorageID: string(repository.StorageID),
Identifier: location,
IdentifierType: block.IdentifierTypeFull,
}, stat.Size(), fd, block.PutOpts{})
Expand Down Expand Up @@ -118,9 +115,9 @@ func NewGarbageCollectionManager(blockAdapter block.Adapter, refManager graveler
}
}

func (m *GarbageCollectionManager) GetRules(ctx context.Context, storageNamespace graveler.StorageNamespace) (*graveler.GarbageCollectionRules, error) {
// TODO (gilo): ObjectPointer init - add StorageID here?
func (m *GarbageCollectionManager) GetRules(ctx context.Context, storageID graveler.StorageID, storageNamespace graveler.StorageNamespace) (*graveler.GarbageCollectionRules, error) {
objectPointer := block.ObjectPointer{
StorageID: string(storageID),
StorageNamespace: string(storageNamespace),
Identifier: fmt.Sprintf(configFileSuffixTemplate, m.committedBlockStoragePrefix),
IdentifierType: block.IdentifierTypeRelative,
Expand Down Expand Up @@ -151,13 +148,13 @@ func (m *GarbageCollectionManager) GetRules(ctx context.Context, storageNamespac
return &rules, nil
}

func (m *GarbageCollectionManager) SaveRules(ctx context.Context, storageNamespace graveler.StorageNamespace, rules *graveler.GarbageCollectionRules) error {
func (m *GarbageCollectionManager) SaveRules(ctx context.Context, storageID graveler.StorageID, storageNamespace graveler.StorageNamespace, rules *graveler.GarbageCollectionRules) error {
rulesBytes, err := proto.Marshal(rules)
if err != nil {
return err
}
// TODO (gilo): ObjectPointer init - add StorageID here?
_, err = m.blockAdapter.Put(ctx, block.ObjectPointer{
StorageID: string(storageID),
StorageNamespace: string(storageNamespace),
Identifier: fmt.Sprintf(configFileSuffixTemplate, m.committedBlockStoragePrefix),
IdentifierType: block.IdentifierTypeRelative,
Expand Down Expand Up @@ -207,12 +204,12 @@ func (m *GarbageCollectionManager) SaveGarbageCollectionCommits(ctx context.Cont
}
commitsStr := b.String()
runID := m.NewID()
csvLocation, err := m.GetCommitsCSVLocation(runID, repository.StorageNamespace)
csvLocation, err := m.GetCommitsCSVLocation(runID, repository.StorageID, repository.StorageNamespace)
if err != nil {
return "", err
}
_, err = m.blockAdapter.Put(ctx, block.ObjectPointer{
// TODO (gilo): ObjectPointer init - add StorageID here?
StorageID: string(repository.StorageID),
Identifier: csvLocation,
IdentifierType: block.IdentifierTypeFull,
}, int64(len(commitsStr)), strings.NewReader(commitsStr), block.PutOpts{})
Expand Down
Loading
Loading