2021-06-30 22:32:07 -04:00
|
|
|
// Copyright (c) 2015-2021 MinIO, Inc.
|
|
|
|
//
|
|
|
|
// This file is part of MinIO Object Storage stack
|
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/minio/minio/internal/bucket/lifecycle"
|
|
|
|
)
|
|
|
|
|
2021-11-18 15:15:22 -05:00
|
|
|
func (x xlMetaV2) listFreeVersions(volume, path string) ([]FileInfo, error) {
|
|
|
|
fivs, err := x.ListVersions(volume, path)
|
2021-06-30 22:32:07 -04:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
n := 0
|
|
|
|
for _, fiv := range fivs {
|
|
|
|
if fiv.TierFreeVersion() {
|
|
|
|
fivs[n] = fiv
|
|
|
|
n++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fivs = fivs[:n]
|
|
|
|
return fivs, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestFreeVersion(t *testing.T) {
|
2021-11-18 15:15:22 -05:00
|
|
|
fatalErr := func(err error) {
|
|
|
|
t.Helper()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-30 22:32:07 -04:00
|
|
|
// Add a version with tiered content, one with local content
|
|
|
|
xl := xlMetaV2{}
|
2021-11-18 15:15:22 -05:00
|
|
|
counter := 1
|
|
|
|
report := func() {
|
|
|
|
t.Helper()
|
|
|
|
// t.Logf("versions (%d): len = %d", counter, len(xl.versions))
|
|
|
|
counter++
|
|
|
|
}
|
2021-06-30 22:32:07 -04:00
|
|
|
fi := FileInfo{
|
|
|
|
Volume: "volume",
|
|
|
|
Name: "object-name",
|
|
|
|
VersionID: "00000000-0000-0000-0000-000000000001",
|
|
|
|
IsLatest: true,
|
|
|
|
Deleted: false,
|
|
|
|
TransitionStatus: "",
|
|
|
|
DataDir: "bffea160-ca7f-465f-98bc-9b4f1c3ba1ef",
|
|
|
|
XLV1: false,
|
|
|
|
ModTime: time.Now(),
|
|
|
|
Size: 0,
|
|
|
|
Mode: 0,
|
|
|
|
Metadata: nil,
|
|
|
|
Parts: nil,
|
|
|
|
Erasure: ErasureInfo{
|
|
|
|
Algorithm: ReedSolomon.String(),
|
|
|
|
DataBlocks: 4,
|
|
|
|
ParityBlocks: 2,
|
|
|
|
BlockSize: 10000,
|
|
|
|
Index: 1,
|
|
|
|
Distribution: []int{1, 2, 3, 4, 5, 6, 7, 8},
|
|
|
|
Checksums: []ChecksumInfo{{
|
|
|
|
PartNumber: 1,
|
|
|
|
Algorithm: HighwayHash256S,
|
|
|
|
Hash: nil,
|
|
|
|
}},
|
|
|
|
},
|
2021-09-18 16:31:35 -04:00
|
|
|
MarkDeleted: false,
|
|
|
|
//DeleteMarkerReplicationStatus: "",
|
|
|
|
//VersionPurgeStatus: "",
|
|
|
|
NumVersions: 1,
|
|
|
|
SuccessorModTime: time.Time{},
|
2021-06-30 22:32:07 -04:00
|
|
|
}
|
|
|
|
// Add a version with local content
|
2021-11-18 15:15:22 -05:00
|
|
|
fatalErr(xl.AddVersion(fi))
|
|
|
|
report()
|
2021-06-30 22:32:07 -04:00
|
|
|
|
|
|
|
// Add null version with tiered content
|
|
|
|
tierfi := fi
|
|
|
|
tierfi.VersionID = ""
|
2021-11-18 15:15:22 -05:00
|
|
|
fatalErr(xl.AddVersion(tierfi))
|
|
|
|
report()
|
2021-06-30 22:32:07 -04:00
|
|
|
tierfi.TransitionStatus = lifecycle.TransitionComplete
|
|
|
|
tierfi.TransitionedObjName = mustGetUUID()
|
|
|
|
tierfi.TransitionTier = "MINIOTIER-1"
|
2021-11-18 15:15:22 -05:00
|
|
|
var err error
|
|
|
|
_, _, err = xl.DeleteVersion(tierfi)
|
|
|
|
fatalErr(err)
|
|
|
|
report()
|
2021-06-30 22:32:07 -04:00
|
|
|
|
|
|
|
fvIDs := []string{
|
|
|
|
"00000000-0000-0000-0000-0000000000f1",
|
|
|
|
"00000000-0000-0000-0000-0000000000f2",
|
|
|
|
}
|
|
|
|
// Simulate overwrite of null version
|
|
|
|
newtierfi := tierfi
|
|
|
|
newtierfi.SetTierFreeVersionID(fvIDs[0])
|
2021-11-18 15:15:22 -05:00
|
|
|
fatalErr(xl.AddFreeVersion(newtierfi))
|
|
|
|
report()
|
|
|
|
fatalErr(xl.AddVersion(newtierfi))
|
|
|
|
report()
|
2021-06-30 22:32:07 -04:00
|
|
|
|
|
|
|
// Simulate removal of null version
|
|
|
|
newtierfi.TransitionTier = ""
|
|
|
|
newtierfi.TransitionedObjName = ""
|
|
|
|
newtierfi.TransitionStatus = ""
|
|
|
|
newtierfi.SetTierFreeVersionID(fvIDs[1])
|
2021-11-18 15:15:22 -05:00
|
|
|
report()
|
|
|
|
_, _, err = xl.DeleteVersion(newtierfi)
|
|
|
|
report()
|
|
|
|
fatalErr(err)
|
2021-06-30 22:32:07 -04:00
|
|
|
|
|
|
|
// Check number of free-versions
|
|
|
|
freeVersions, err := xl.listFreeVersions(newtierfi.Volume, newtierfi.Name)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("failed to list free versions %v", err)
|
|
|
|
}
|
|
|
|
if len(freeVersions) != 2 {
|
|
|
|
t.Fatalf("Expected two free versions but got %d", len(freeVersions))
|
|
|
|
}
|
|
|
|
|
|
|
|
// Simulate scanner removing free-version
|
|
|
|
freefi := newtierfi
|
|
|
|
for _, fvID := range fvIDs {
|
|
|
|
freefi.VersionID = fvID
|
2021-11-18 15:15:22 -05:00
|
|
|
_, _, err = xl.DeleteVersion(freefi)
|
|
|
|
fatalErr(err)
|
2021-06-30 22:32:07 -04:00
|
|
|
}
|
2021-11-18 15:15:22 -05:00
|
|
|
report()
|
2021-06-30 22:32:07 -04:00
|
|
|
|
|
|
|
// Check number of free-versions
|
|
|
|
freeVersions, err = xl.listFreeVersions(newtierfi.Volume, newtierfi.Name)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("failed to list free versions %v", err)
|
|
|
|
}
|
|
|
|
if len(freeVersions) != 0 {
|
|
|
|
t.Fatalf("Expected zero free version but got %d", len(freeVersions))
|
|
|
|
}
|
2021-11-18 15:15:22 -05:00
|
|
|
report()
|
2021-06-30 22:32:07 -04:00
|
|
|
|
|
|
|
// Adding a free version to a version with no tiered content.
|
|
|
|
newfi := fi
|
|
|
|
newfi.SetTierFreeVersionID("00000000-0000-0000-0000-0000000000f3")
|
2021-11-18 15:15:22 -05:00
|
|
|
fatalErr(xl.AddFreeVersion(newfi)) // this shouldn't add a free-version
|
|
|
|
report()
|
2021-06-30 22:32:07 -04:00
|
|
|
|
|
|
|
// Check number of free-versions
|
|
|
|
freeVersions, err = xl.listFreeVersions(newtierfi.Volume, newtierfi.Name)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("failed to list free versions %v", err)
|
|
|
|
}
|
|
|
|
if len(freeVersions) != 0 {
|
|
|
|
t.Fatalf("Expected zero free version but got %d", len(freeVersions))
|
|
|
|
}
|
|
|
|
}
|