This repository has been archived by the owner on May 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: #164 wip implementation of collection rotation strategies
- Loading branch information
1 parent
221282e
commit 6110d9b
Showing
6 changed files
with
92 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package storage | ||
|
||
import ( | ||
"github.com/riotkit-org/backup-repository/collections" | ||
"sort" | ||
) | ||
|
||
type RotationStrategy interface { | ||
// CanUpload returns nil if YES, error if NO | ||
CanUpload(version UploadedVersion) error | ||
|
||
// GetVersionsThatShouldBeDeletedIfThisVersionUploaded lists all the versions that should be deleted if a new version would be submitted | ||
GetVersionsThatShouldBeDeletedIfThisVersionUploaded(version UploadedVersion) []UploadedVersion | ||
} | ||
|
||
// | ||
// FifoRotationStrategy implements a simple queue, first is appended, oldest will be deleted | ||
// | ||
type FifoRotationStrategy struct { | ||
collection *collections.Collection | ||
existingVersions []UploadedVersion | ||
} | ||
|
||
func (frs *FifoRotationStrategy) CanUpload(version UploadedVersion) error { | ||
return nil | ||
} | ||
|
||
func (frs *FifoRotationStrategy) GetVersionsThatShouldBeDeletedIfThisVersionUploaded(version UploadedVersion) []UploadedVersion { | ||
existingVersions := frs.existingVersions | ||
|
||
// nothing to do, there is still enough slots | ||
if len(existingVersions) < frs.collection.Spec.MaxBackupsCount { | ||
return []UploadedVersion{} | ||
} | ||
|
||
// order by version number DESCENDING | ||
sort.SliceStable(&existingVersions, func(i, j int) bool { | ||
return existingVersions[i].VersionNumber > existingVersions[j].VersionNumber | ||
}) | ||
|
||
// oldest element | ||
return existingVersions[0:1] | ||
} | ||
|
||
// todo: test reference | ||
func NewFifoRotationStrategy(collection *collections.Collection, existingVersions []UploadedVersion) *FifoRotationStrategy { | ||
return &FifoRotationStrategy{ | ||
collection: collection, | ||
existingVersions: existingVersions, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package storage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters