2022-08-19 12:36:37 +00:00
|
|
|
package meta_test
|
|
|
|
|
|
|
|
import (
|
2023-04-12 14:01:29 +00:00
|
|
|
"context"
|
2022-08-19 12:36:37 +00:00
|
|
|
"testing"
|
|
|
|
|
2023-03-07 13:38:26 +00:00
|
|
|
objectcore "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/object"
|
2023-03-20 14:10:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/internal/testutil"
|
2023-03-07 13:38:26 +00:00
|
|
|
meta "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/metabase"
|
2023-11-01 17:53:24 +00:00
|
|
|
cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id"
|
2023-07-06 12:36:41 +00:00
|
|
|
objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
|
2023-03-07 13:38:26 +00:00
|
|
|
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
|
|
|
|
oidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id/test"
|
2022-08-19 12:36:37 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
const objCount = 10
|
|
|
|
|
2022-09-09 11:33:38 +00:00
|
|
|
func TestCounters(t *testing.T) {
|
2023-05-05 14:02:27 +00:00
|
|
|
t.Parallel()
|
2022-08-19 12:36:37 +00:00
|
|
|
|
2022-09-09 11:33:38 +00:00
|
|
|
t.Run("defaults", func(t *testing.T) {
|
2023-05-05 14:02:27 +00:00
|
|
|
t.Parallel()
|
|
|
|
db := newDB(t)
|
|
|
|
c, err := db.ObjectCounters()
|
2022-09-09 11:33:38 +00:00
|
|
|
require.NoError(t, err)
|
2023-12-04 14:35:11 +00:00
|
|
|
require.Zero(t, c.Phy)
|
|
|
|
require.Zero(t, c.Logic)
|
|
|
|
require.Zero(t, c.User)
|
2023-11-01 17:53:24 +00:00
|
|
|
|
|
|
|
cc, err := db.ContainerCounters(context.Background())
|
|
|
|
require.NoError(t, err)
|
2023-12-04 14:35:11 +00:00
|
|
|
require.Zero(t, len(cc.Counts))
|
2022-09-09 11:33:38 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("put", func(t *testing.T) {
|
2023-05-05 14:02:27 +00:00
|
|
|
t.Parallel()
|
|
|
|
db := newDB(t)
|
2023-07-06 12:36:41 +00:00
|
|
|
oo := make([]*objectSDK.Object, 0, objCount)
|
2022-09-09 11:33:38 +00:00
|
|
|
for i := 0; i < objCount; i++ {
|
2023-03-20 14:10:26 +00:00
|
|
|
oo = append(oo, testutil.GenerateObject())
|
2022-09-09 11:33:38 +00:00
|
|
|
}
|
2022-08-19 12:36:37 +00:00
|
|
|
|
2022-09-09 11:33:38 +00:00
|
|
|
var prm meta.PutPrm
|
2023-12-04 14:35:11 +00:00
|
|
|
exp := make(map[cid.ID]meta.ObjectCounters)
|
2022-08-19 12:36:37 +00:00
|
|
|
|
2022-09-09 11:33:38 +00:00
|
|
|
for i := 0; i < objCount; i++ {
|
|
|
|
prm.SetObject(oo[i])
|
2023-11-01 17:53:24 +00:00
|
|
|
cnrID, _ := oo[i].ContainerID()
|
2023-12-04 14:35:11 +00:00
|
|
|
c := meta.ObjectCounters{}
|
|
|
|
exp[cnrID] = meta.ObjectCounters{
|
|
|
|
Logic: 1,
|
|
|
|
Phy: 1,
|
2023-12-05 14:00:16 +00:00
|
|
|
User: 1,
|
2023-12-04 14:35:11 +00:00
|
|
|
}
|
2022-08-19 12:36:37 +00:00
|
|
|
|
2023-05-05 14:02:27 +00:00
|
|
|
_, err := db.Put(context.Background(), prm)
|
2022-09-09 11:33:38 +00:00
|
|
|
require.NoError(t, err)
|
2022-08-19 12:36:37 +00:00
|
|
|
|
2023-12-04 14:35:11 +00:00
|
|
|
c, err = db.ObjectCounters()
|
2022-09-09 11:33:38 +00:00
|
|
|
require.NoError(t, err)
|
2022-08-19 12:36:37 +00:00
|
|
|
|
2023-12-04 14:35:11 +00:00
|
|
|
require.Equal(t, uint64(i+1), c.Phy)
|
|
|
|
require.Equal(t, uint64(i+1), c.Logic)
|
2023-11-01 17:53:24 +00:00
|
|
|
|
|
|
|
cc, err := db.ContainerCounters(context.Background())
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2023-12-04 14:35:11 +00:00
|
|
|
require.Equal(t, meta.ContainerCounters{Counts: exp}, cc)
|
2022-09-09 11:33:38 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("delete", func(t *testing.T) {
|
2023-05-05 14:02:27 +00:00
|
|
|
t.Parallel()
|
|
|
|
db := newDB(t)
|
2022-09-09 11:33:38 +00:00
|
|
|
oo := putObjs(t, db, objCount, false)
|
|
|
|
|
2023-12-04 14:35:11 +00:00
|
|
|
exp := make(map[cid.ID]meta.ObjectCounters)
|
2023-11-01 17:53:24 +00:00
|
|
|
for _, obj := range oo {
|
|
|
|
cnrID, _ := obj.ContainerID()
|
2023-12-04 14:35:11 +00:00
|
|
|
exp[cnrID] = meta.ObjectCounters{
|
|
|
|
Logic: 1,
|
|
|
|
Phy: 1,
|
2023-12-05 14:00:16 +00:00
|
|
|
User: 1,
|
2023-12-04 14:35:11 +00:00
|
|
|
}
|
2023-11-01 17:53:24 +00:00
|
|
|
}
|
|
|
|
|
2022-09-09 11:33:38 +00:00
|
|
|
var prm meta.DeletePrm
|
|
|
|
for i := objCount - 1; i >= 0; i-- {
|
|
|
|
prm.SetAddresses(objectcore.AddressOf(oo[i]))
|
|
|
|
|
2023-04-12 14:01:29 +00:00
|
|
|
res, err := db.Delete(context.Background(), prm)
|
2022-09-09 11:33:38 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, uint64(1), res.AvailableObjectsRemoved())
|
|
|
|
|
2023-05-05 14:02:27 +00:00
|
|
|
c, err := db.ObjectCounters()
|
2022-09-09 11:33:38 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2023-12-04 14:35:11 +00:00
|
|
|
require.Equal(t, uint64(i), c.Phy)
|
|
|
|
require.Equal(t, uint64(i), c.Logic)
|
2023-12-05 14:00:16 +00:00
|
|
|
require.Equal(t, uint64(i), c.User)
|
2023-11-01 17:53:24 +00:00
|
|
|
|
|
|
|
cnrID, _ := oo[i].ContainerID()
|
2023-12-04 14:35:11 +00:00
|
|
|
if v, ok := exp[cnrID]; ok {
|
|
|
|
v.Phy--
|
|
|
|
v.Logic--
|
2023-12-05 14:00:16 +00:00
|
|
|
v.User--
|
2023-12-04 14:35:11 +00:00
|
|
|
if v.IsZero() {
|
|
|
|
delete(exp, cnrID)
|
2023-11-01 17:53:24 +00:00
|
|
|
} else {
|
2023-12-04 14:35:11 +00:00
|
|
|
exp[cnrID] = v
|
2023-11-01 17:53:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cc, err := db.ContainerCounters(context.Background())
|
|
|
|
require.NoError(t, err)
|
2023-12-04 14:35:11 +00:00
|
|
|
require.Equal(t, meta.ContainerCounters{Counts: exp}, cc)
|
2022-09-09 11:33:38 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("inhume", func(t *testing.T) {
|
2023-05-05 14:02:27 +00:00
|
|
|
t.Parallel()
|
|
|
|
db := newDB(t)
|
2022-09-09 11:33:38 +00:00
|
|
|
oo := putObjs(t, db, objCount, false)
|
|
|
|
|
2023-12-04 14:35:11 +00:00
|
|
|
exp := make(map[cid.ID]meta.ObjectCounters)
|
2023-11-01 17:53:24 +00:00
|
|
|
for _, obj := range oo {
|
|
|
|
cnrID, _ := obj.ContainerID()
|
2023-12-04 14:35:11 +00:00
|
|
|
exp[cnrID] = meta.ObjectCounters{
|
|
|
|
Logic: 1,
|
|
|
|
Phy: 1,
|
2023-12-05 14:00:16 +00:00
|
|
|
User: 1,
|
2023-12-04 14:35:11 +00:00
|
|
|
}
|
2023-11-01 17:53:24 +00:00
|
|
|
}
|
|
|
|
|
2022-09-09 11:33:38 +00:00
|
|
|
inhumedObjs := make([]oid.Address, objCount/2)
|
|
|
|
|
|
|
|
for i, o := range oo {
|
|
|
|
if i == len(inhumedObjs) {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
inhumedObjs[i] = objectcore.AddressOf(o)
|
|
|
|
}
|
|
|
|
|
2023-11-01 17:53:24 +00:00
|
|
|
for _, addr := range inhumedObjs {
|
2023-12-04 14:35:11 +00:00
|
|
|
if v, ok := exp[addr.Container()]; ok {
|
|
|
|
v.Logic--
|
2023-12-05 14:00:16 +00:00
|
|
|
v.User--
|
2023-12-04 14:35:11 +00:00
|
|
|
if v.IsZero() {
|
|
|
|
delete(exp, addr.Container())
|
2023-11-01 17:53:24 +00:00
|
|
|
} else {
|
2023-12-04 14:35:11 +00:00
|
|
|
exp[addr.Container()] = v
|
2023-11-01 17:53:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-09 11:33:38 +00:00
|
|
|
var prm meta.InhumePrm
|
|
|
|
prm.SetTombstoneAddress(oidtest.Address())
|
|
|
|
prm.SetAddresses(inhumedObjs...)
|
|
|
|
|
2023-04-12 14:01:29 +00:00
|
|
|
res, err := db.Inhume(context.Background(), prm)
|
2022-08-19 12:36:37 +00:00
|
|
|
require.NoError(t, err)
|
2022-09-09 11:33:38 +00:00
|
|
|
require.Equal(t, uint64(len(inhumedObjs)), res.AvailableInhumed())
|
2023-12-05 14:00:16 +00:00
|
|
|
require.Equal(t, uint64(len(inhumedObjs)), res.UserInhumed())
|
2022-08-19 12:36:37 +00:00
|
|
|
|
2023-05-05 14:02:27 +00:00
|
|
|
c, err := db.ObjectCounters()
|
2022-08-19 12:36:37 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2023-12-04 14:35:11 +00:00
|
|
|
require.Equal(t, uint64(objCount), c.Phy)
|
|
|
|
require.Equal(t, uint64(objCount-len(inhumedObjs)), c.Logic)
|
2023-12-05 14:00:16 +00:00
|
|
|
require.Equal(t, uint64(objCount-len(inhumedObjs)), c.User)
|
2023-11-01 17:53:24 +00:00
|
|
|
|
|
|
|
cc, err := db.ContainerCounters(context.Background())
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2023-12-04 14:35:11 +00:00
|
|
|
require.Equal(t, meta.ContainerCounters{Counts: exp}, cc)
|
2022-09-09 11:33:38 +00:00
|
|
|
})
|
2022-08-19 12:36:37 +00:00
|
|
|
|
2022-09-09 11:33:38 +00:00
|
|
|
t.Run("put_split", func(t *testing.T) {
|
2023-05-05 14:02:27 +00:00
|
|
|
t.Parallel()
|
|
|
|
db := newDB(t)
|
2023-03-20 14:10:26 +00:00
|
|
|
parObj := testutil.GenerateObject()
|
2022-09-09 11:33:38 +00:00
|
|
|
|
2023-12-04 14:35:11 +00:00
|
|
|
exp := make(map[cid.ID]meta.ObjectCounters)
|
2023-11-01 17:53:24 +00:00
|
|
|
|
2022-09-09 11:33:38 +00:00
|
|
|
// put objects and check that parent info
|
|
|
|
// does not affect the counter
|
|
|
|
for i := 0; i < objCount; i++ {
|
2023-03-20 14:10:26 +00:00
|
|
|
o := testutil.GenerateObject()
|
2022-09-09 11:33:38 +00:00
|
|
|
if i < objCount/2 { // half of the objs will have the parent
|
|
|
|
o.SetParent(parObj)
|
2023-12-05 14:00:16 +00:00
|
|
|
o.SetSplitID(objectSDK.NewSplitID())
|
2022-09-09 11:33:38 +00:00
|
|
|
}
|
|
|
|
|
2023-11-01 17:53:24 +00:00
|
|
|
cnrID, _ := o.ContainerID()
|
2023-12-04 14:35:11 +00:00
|
|
|
exp[cnrID] = meta.ObjectCounters{
|
|
|
|
Logic: 1,
|
|
|
|
Phy: 1,
|
2023-12-05 14:00:16 +00:00
|
|
|
User: 1,
|
2023-12-04 14:35:11 +00:00
|
|
|
}
|
2023-11-01 17:53:24 +00:00
|
|
|
|
2022-09-09 11:33:38 +00:00
|
|
|
require.NoError(t, putBig(db, o))
|
|
|
|
|
2023-05-05 14:02:27 +00:00
|
|
|
c, err := db.ObjectCounters()
|
2022-09-09 11:33:38 +00:00
|
|
|
require.NoError(t, err)
|
2023-12-04 14:35:11 +00:00
|
|
|
require.Equal(t, uint64(i+1), c.Phy)
|
|
|
|
require.Equal(t, uint64(i+1), c.Logic)
|
2023-12-05 14:00:16 +00:00
|
|
|
require.Equal(t, uint64(i+1), c.User)
|
2023-11-01 17:53:24 +00:00
|
|
|
|
|
|
|
cc, err := db.ContainerCounters(context.Background())
|
|
|
|
require.NoError(t, err)
|
2023-12-04 14:35:11 +00:00
|
|
|
require.Equal(t, meta.ContainerCounters{Counts: exp}, cc)
|
2022-09-09 11:33:38 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("delete_split", func(t *testing.T) {
|
2023-05-05 14:02:27 +00:00
|
|
|
t.Parallel()
|
|
|
|
db := newDB(t)
|
2022-09-09 11:33:38 +00:00
|
|
|
oo := putObjs(t, db, objCount, true)
|
|
|
|
|
2023-12-04 14:35:11 +00:00
|
|
|
exp := make(map[cid.ID]meta.ObjectCounters)
|
2023-11-01 17:53:24 +00:00
|
|
|
for _, obj := range oo {
|
|
|
|
cnrID, _ := obj.ContainerID()
|
2023-12-04 14:35:11 +00:00
|
|
|
exp[cnrID] = meta.ObjectCounters{
|
|
|
|
Logic: 1,
|
|
|
|
Phy: 1,
|
2023-12-05 14:00:16 +00:00
|
|
|
User: 1,
|
2023-12-04 14:35:11 +00:00
|
|
|
}
|
2023-11-01 17:53:24 +00:00
|
|
|
}
|
|
|
|
|
2022-09-09 11:33:38 +00:00
|
|
|
// delete objects that have parent info
|
|
|
|
// and check that it does not affect
|
|
|
|
// the counter
|
|
|
|
for i, o := range oo {
|
2023-11-01 17:53:24 +00:00
|
|
|
addr := objectcore.AddressOf(o)
|
|
|
|
require.NoError(t, metaDelete(db, addr))
|
2022-09-09 11:33:38 +00:00
|
|
|
|
|
|
|
c, err := db.ObjectCounters()
|
|
|
|
require.NoError(t, err)
|
2023-12-04 14:35:11 +00:00
|
|
|
require.Equal(t, uint64(objCount-i-1), c.Phy)
|
2023-12-05 14:00:16 +00:00
|
|
|
require.Equal(t, uint64(objCount-i-1), c.Logic)
|
|
|
|
require.Equal(t, uint64(objCount-i-1), c.User)
|
2023-11-01 17:53:24 +00:00
|
|
|
|
2023-12-04 14:35:11 +00:00
|
|
|
if v, ok := exp[addr.Container()]; ok {
|
|
|
|
v.Logic--
|
|
|
|
v.Phy--
|
2023-12-05 14:00:16 +00:00
|
|
|
v.User--
|
2023-12-04 14:35:11 +00:00
|
|
|
if v.IsZero() {
|
|
|
|
delete(exp, addr.Container())
|
2023-11-01 17:53:24 +00:00
|
|
|
} else {
|
2023-12-04 14:35:11 +00:00
|
|
|
exp[addr.Container()] = v
|
2023-11-01 17:53:24 +00:00
|
|
|
}
|
|
|
|
}
|
2022-09-09 11:33:38 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("inhume_split", func(t *testing.T) {
|
2023-05-05 14:02:27 +00:00
|
|
|
t.Parallel()
|
|
|
|
db := newDB(t)
|
2022-09-09 11:33:38 +00:00
|
|
|
oo := putObjs(t, db, objCount, true)
|
2022-08-19 12:36:37 +00:00
|
|
|
|
2023-12-04 14:35:11 +00:00
|
|
|
exp := make(map[cid.ID]meta.ObjectCounters)
|
2023-11-01 17:53:24 +00:00
|
|
|
for _, obj := range oo {
|
|
|
|
cnrID, _ := obj.ContainerID()
|
2023-12-04 14:35:11 +00:00
|
|
|
exp[cnrID] = meta.ObjectCounters{
|
|
|
|
Logic: 1,
|
|
|
|
Phy: 1,
|
2023-12-05 14:00:16 +00:00
|
|
|
User: 1,
|
2023-12-04 14:35:11 +00:00
|
|
|
}
|
2023-11-01 17:53:24 +00:00
|
|
|
}
|
|
|
|
|
2022-09-09 11:33:38 +00:00
|
|
|
inhumedObjs := make([]oid.Address, objCount/2)
|
|
|
|
|
|
|
|
for i, o := range oo {
|
|
|
|
if i == len(inhumedObjs) {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
inhumedObjs[i] = objectcore.AddressOf(o)
|
|
|
|
}
|
|
|
|
|
2023-11-01 17:53:24 +00:00
|
|
|
for _, addr := range inhumedObjs {
|
2023-12-04 14:35:11 +00:00
|
|
|
if v, ok := exp[addr.Container()]; ok {
|
|
|
|
v.Logic--
|
2023-12-05 14:00:16 +00:00
|
|
|
v.User--
|
2023-12-04 14:35:11 +00:00
|
|
|
if v.IsZero() {
|
|
|
|
delete(exp, addr.Container())
|
2023-11-01 17:53:24 +00:00
|
|
|
} else {
|
2023-12-04 14:35:11 +00:00
|
|
|
exp[addr.Container()] = v
|
2023-11-01 17:53:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-09 11:33:38 +00:00
|
|
|
var prm meta.InhumePrm
|
|
|
|
prm.SetTombstoneAddress(oidtest.Address())
|
|
|
|
prm.SetAddresses(inhumedObjs...)
|
|
|
|
|
2023-05-05 14:02:27 +00:00
|
|
|
_, err := db.Inhume(context.Background(), prm)
|
2022-08-19 12:36:37 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2023-05-05 14:02:27 +00:00
|
|
|
c, err := db.ObjectCounters()
|
2022-08-19 12:36:37 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2023-12-04 14:35:11 +00:00
|
|
|
require.Equal(t, uint64(objCount), c.Phy)
|
|
|
|
require.Equal(t, uint64(objCount-len(inhumedObjs)), c.Logic)
|
2023-12-05 14:00:16 +00:00
|
|
|
require.Equal(t, uint64(objCount-len(inhumedObjs)), c.User)
|
2023-11-01 17:53:24 +00:00
|
|
|
|
|
|
|
cc, err := db.ContainerCounters(context.Background())
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2023-12-04 14:35:11 +00:00
|
|
|
require.Equal(t, meta.ContainerCounters{Counts: exp}, cc)
|
2022-09-09 11:33:38 +00:00
|
|
|
})
|
2022-08-19 12:36:37 +00:00
|
|
|
}
|
|
|
|
|
2022-09-09 11:33:38 +00:00
|
|
|
func TestCounters_Expired(t *testing.T) {
|
|
|
|
// That test is about expired objects without
|
|
|
|
// GCMark yet. Such objects should be treated as
|
|
|
|
// logically available: decrementing logic counter
|
|
|
|
// should be done explicitly and only in `Delete`
|
|
|
|
// and `Inhume` operations, otherwise, it would be
|
|
|
|
// impossible to maintain logic counter.
|
2022-08-19 12:36:37 +00:00
|
|
|
|
2022-09-09 11:33:38 +00:00
|
|
|
const epoch = 123
|
2022-08-19 12:36:37 +00:00
|
|
|
|
2022-09-09 11:33:38 +00:00
|
|
|
es := &epochState{epoch}
|
|
|
|
db := newDB(t, meta.WithEpochState(es))
|
2022-08-19 12:36:37 +00:00
|
|
|
|
2022-09-09 11:33:38 +00:00
|
|
|
oo := make([]oid.Address, objCount)
|
|
|
|
for i := range oo {
|
2023-07-06 12:36:41 +00:00
|
|
|
oo[i] = putWithExpiration(t, db, objectSDK.TypeRegular, epoch+1)
|
2022-09-09 11:33:38 +00:00
|
|
|
}
|
|
|
|
|
2023-12-04 14:35:11 +00:00
|
|
|
exp := make(map[cid.ID]meta.ObjectCounters)
|
2023-11-01 17:53:24 +00:00
|
|
|
for _, addr := range oo {
|
2023-12-04 14:35:11 +00:00
|
|
|
exp[addr.Container()] = meta.ObjectCounters{
|
|
|
|
Logic: 1,
|
|
|
|
Phy: 1,
|
2023-12-05 14:00:16 +00:00
|
|
|
User: 1,
|
2023-12-04 14:35:11 +00:00
|
|
|
}
|
2023-11-01 17:53:24 +00:00
|
|
|
}
|
|
|
|
|
2022-09-09 11:33:38 +00:00
|
|
|
// 1. objects are available and counters are correct
|
2022-08-19 12:36:37 +00:00
|
|
|
|
2022-09-09 11:33:38 +00:00
|
|
|
c, err := db.ObjectCounters()
|
|
|
|
require.NoError(t, err)
|
2023-12-04 14:35:11 +00:00
|
|
|
require.Equal(t, uint64(objCount), c.Phy)
|
|
|
|
require.Equal(t, uint64(objCount), c.Logic)
|
2023-12-05 14:00:16 +00:00
|
|
|
require.Equal(t, uint64(objCount), c.User)
|
2022-09-09 11:33:38 +00:00
|
|
|
|
2023-11-01 17:53:24 +00:00
|
|
|
cc, err := db.ContainerCounters(context.Background())
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2023-12-04 14:35:11 +00:00
|
|
|
require.Equal(t, meta.ContainerCounters{Counts: exp}, cc)
|
2023-11-01 17:53:24 +00:00
|
|
|
|
2022-09-09 11:33:38 +00:00
|
|
|
for _, o := range oo {
|
|
|
|
_, err := metaGet(db, o, true)
|
2022-08-19 12:36:37 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
}
|
|
|
|
|
2022-09-09 11:33:38 +00:00
|
|
|
// 2. objects are expired, not available but logic counter
|
|
|
|
// is the same
|
2022-08-19 12:36:37 +00:00
|
|
|
|
2022-09-09 11:33:38 +00:00
|
|
|
es.e = epoch + 2
|
2022-08-19 12:36:37 +00:00
|
|
|
|
2022-09-09 11:33:38 +00:00
|
|
|
c, err = db.ObjectCounters()
|
|
|
|
require.NoError(t, err)
|
2023-12-04 14:35:11 +00:00
|
|
|
require.Equal(t, uint64(objCount), c.Phy)
|
|
|
|
require.Equal(t, uint64(objCount), c.Logic)
|
2023-12-05 14:00:16 +00:00
|
|
|
require.Equal(t, uint64(objCount), c.User)
|
2022-09-09 11:33:38 +00:00
|
|
|
|
2023-11-01 17:53:24 +00:00
|
|
|
cc, err = db.ContainerCounters(context.Background())
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2023-12-04 14:35:11 +00:00
|
|
|
require.Equal(t, meta.ContainerCounters{Counts: exp}, cc)
|
2023-11-01 17:53:24 +00:00
|
|
|
|
2022-09-09 11:33:38 +00:00
|
|
|
for _, o := range oo {
|
|
|
|
_, err := metaGet(db, o, true)
|
2022-10-31 07:08:30 +00:00
|
|
|
require.ErrorIs(t, err, meta.ErrObjectIsExpired)
|
2022-08-19 12:36:37 +00:00
|
|
|
}
|
2022-09-09 11:33:38 +00:00
|
|
|
|
|
|
|
// 3. inhuming an expired object with GCMark (like it would
|
|
|
|
// the GC do) should decrease the logic counter despite the
|
|
|
|
// expiration fact
|
|
|
|
|
|
|
|
var inhumePrm meta.InhumePrm
|
|
|
|
inhumePrm.SetGCMark()
|
|
|
|
inhumePrm.SetAddresses(oo[0])
|
|
|
|
|
2023-04-12 14:01:29 +00:00
|
|
|
inhumeRes, err := db.Inhume(context.Background(), inhumePrm)
|
2022-09-09 11:33:38 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, uint64(1), inhumeRes.AvailableInhumed())
|
2023-12-05 14:00:16 +00:00
|
|
|
require.Equal(t, uint64(1), inhumeRes.UserInhumed())
|
2022-09-09 11:33:38 +00:00
|
|
|
|
|
|
|
c, err = db.ObjectCounters()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2023-12-04 14:35:11 +00:00
|
|
|
require.Equal(t, uint64(len(oo)), c.Phy)
|
|
|
|
require.Equal(t, uint64(len(oo)-1), c.Logic)
|
2023-12-05 14:00:16 +00:00
|
|
|
require.Equal(t, uint64(len(oo)-1), c.User)
|
2022-09-09 11:33:38 +00:00
|
|
|
|
2023-12-04 14:35:11 +00:00
|
|
|
if v, ok := exp[oo[0].Container()]; ok {
|
|
|
|
v.Logic--
|
2023-12-05 14:00:16 +00:00
|
|
|
v.User--
|
2023-12-04 14:35:11 +00:00
|
|
|
if v.IsZero() {
|
|
|
|
delete(exp, oo[0].Container())
|
2023-11-01 17:53:24 +00:00
|
|
|
} else {
|
2023-12-04 14:35:11 +00:00
|
|
|
exp[oo[0].Container()] = v
|
2023-11-01 17:53:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cc, err = db.ContainerCounters(context.Background())
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2023-12-04 14:35:11 +00:00
|
|
|
require.Equal(t, meta.ContainerCounters{Counts: exp}, cc)
|
2023-11-01 17:53:24 +00:00
|
|
|
|
2022-09-09 11:33:38 +00:00
|
|
|
// 4. `Delete` an object with GCMark should decrease the
|
|
|
|
// phy counter but does not affect the logic counter (after
|
|
|
|
// that step they should be equal)
|
|
|
|
|
|
|
|
var deletePrm meta.DeletePrm
|
|
|
|
deletePrm.SetAddresses(oo[0])
|
|
|
|
|
2023-04-12 14:01:29 +00:00
|
|
|
deleteRes, err := db.Delete(context.Background(), deletePrm)
|
2022-09-09 11:33:38 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Zero(t, deleteRes.AvailableObjectsRemoved())
|
2023-12-05 14:00:16 +00:00
|
|
|
require.Zero(t, deleteRes.UserObjectsRemoved())
|
2022-09-09 11:33:38 +00:00
|
|
|
|
2023-12-04 14:35:11 +00:00
|
|
|
if v, ok := exp[oo[0].Container()]; ok {
|
|
|
|
v.Phy--
|
|
|
|
if v.IsZero() {
|
|
|
|
delete(exp, oo[0].Container())
|
2023-11-01 17:53:24 +00:00
|
|
|
} else {
|
2023-12-04 14:35:11 +00:00
|
|
|
exp[oo[0].Container()] = v
|
2023-11-01 17:53:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-09 11:33:38 +00:00
|
|
|
oo = oo[1:]
|
|
|
|
|
|
|
|
c, err = db.ObjectCounters()
|
|
|
|
require.NoError(t, err)
|
2023-12-04 14:35:11 +00:00
|
|
|
require.Equal(t, uint64(len(oo)), c.Phy)
|
|
|
|
require.Equal(t, uint64(len(oo)), c.Logic)
|
2023-12-05 14:00:16 +00:00
|
|
|
require.Equal(t, uint64(len(oo)), c.User)
|
2022-09-09 11:33:38 +00:00
|
|
|
|
2023-11-01 17:53:24 +00:00
|
|
|
cc, err = db.ContainerCounters(context.Background())
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2023-12-04 14:35:11 +00:00
|
|
|
require.Equal(t, meta.ContainerCounters{Counts: exp}, cc)
|
2023-11-01 17:53:24 +00:00
|
|
|
|
2022-09-09 11:33:38 +00:00
|
|
|
// 5 `Delete` an expired object (like it would the control
|
|
|
|
// service do) should decrease both counters despite the
|
|
|
|
// expiration fact
|
|
|
|
|
|
|
|
deletePrm.SetAddresses(oo[0])
|
|
|
|
|
2023-04-12 14:01:29 +00:00
|
|
|
deleteRes, err = db.Delete(context.Background(), deletePrm)
|
2022-09-09 11:33:38 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, uint64(1), deleteRes.AvailableObjectsRemoved())
|
2023-12-05 14:00:16 +00:00
|
|
|
require.Equal(t, uint64(1), deleteRes.UserObjectsRemoved())
|
2022-09-09 11:33:38 +00:00
|
|
|
|
2023-12-04 14:35:11 +00:00
|
|
|
if v, ok := exp[oo[0].Container()]; ok {
|
|
|
|
v.Phy--
|
|
|
|
v.Logic--
|
2023-12-05 14:00:16 +00:00
|
|
|
v.User--
|
2023-12-04 14:35:11 +00:00
|
|
|
if v.IsZero() {
|
|
|
|
delete(exp, oo[0].Container())
|
2023-11-01 17:53:24 +00:00
|
|
|
} else {
|
2023-12-04 14:35:11 +00:00
|
|
|
exp[oo[0].Container()] = v
|
2023-11-01 17:53:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-09 11:33:38 +00:00
|
|
|
oo = oo[1:]
|
|
|
|
|
|
|
|
c, err = db.ObjectCounters()
|
|
|
|
require.NoError(t, err)
|
2023-12-04 14:35:11 +00:00
|
|
|
require.Equal(t, uint64(len(oo)), c.Phy)
|
|
|
|
require.Equal(t, uint64(len(oo)), c.Logic)
|
2023-12-05 14:00:16 +00:00
|
|
|
require.Equal(t, uint64(len(oo)), c.User)
|
2023-11-01 17:53:24 +00:00
|
|
|
|
|
|
|
cc, err = db.ContainerCounters(context.Background())
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2023-12-04 14:35:11 +00:00
|
|
|
require.Equal(t, meta.ContainerCounters{Counts: exp}, cc)
|
2022-08-19 12:36:37 +00:00
|
|
|
}
|
|
|
|
|
2023-07-06 12:36:41 +00:00
|
|
|
func putObjs(t *testing.T, db *meta.DB, count int, withParent bool) []*objectSDK.Object {
|
2022-08-19 12:36:37 +00:00
|
|
|
var prm meta.PutPrm
|
|
|
|
var err error
|
2023-03-20 14:10:26 +00:00
|
|
|
parent := testutil.GenerateObject()
|
2022-08-19 12:36:37 +00:00
|
|
|
|
2023-07-06 12:36:41 +00:00
|
|
|
oo := make([]*objectSDK.Object, 0, count)
|
2022-08-19 12:36:37 +00:00
|
|
|
for i := 0; i < count; i++ {
|
2023-03-20 14:10:26 +00:00
|
|
|
o := testutil.GenerateObject()
|
2022-08-19 12:36:37 +00:00
|
|
|
if withParent {
|
|
|
|
o.SetParent(parent)
|
2023-12-05 14:00:16 +00:00
|
|
|
o.SetSplitID(objectSDK.NewSplitID())
|
2022-08-19 12:36:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
oo = append(oo, o)
|
|
|
|
|
|
|
|
prm.SetObject(o)
|
2023-04-12 14:01:29 +00:00
|
|
|
_, err = db.Put(context.Background(), prm)
|
2022-08-19 12:36:37 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-09-09 11:33:38 +00:00
|
|
|
c, err := db.ObjectCounters()
|
2022-08-19 12:36:37 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2023-12-04 14:35:11 +00:00
|
|
|
require.Equal(t, uint64(i+1), c.Phy)
|
|
|
|
require.Equal(t, uint64(i+1), c.Logic)
|
2022-08-19 12:36:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return oo
|
|
|
|
}
|