forked from TrueCloudLab/frostfs-node
[#838] metabase: Add user object type counter
Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
parent
29550fe600
commit
f314da4af3
8 changed files with 247 additions and 227 deletions
|
@ -178,8 +178,6 @@ func TestCounters(t *testing.T) {
|
|||
oo[i] = testutil.GenerateObject()
|
||||
}
|
||||
|
||||
cc := meta.ContainerCounters{Logical: make(map[cid.ID]uint64), Physical: make(map[cid.ID]uint64)}
|
||||
|
||||
t.Run("defaults", func(t *testing.T) {
|
||||
require.Zero(t, mm.getObjectCounter(physical))
|
||||
require.Zero(t, mm.getObjectCounter(logical))
|
||||
|
@ -200,15 +198,16 @@ func TestCounters(t *testing.T) {
|
|||
var totalPayload int64
|
||||
|
||||
expectedLogicalSizes := make(map[string]int64)
|
||||
expectedLogCC := make(map[cid.ID]uint64)
|
||||
expectedPhyCC := make(map[cid.ID]uint64)
|
||||
expected := make(map[cid.ID]meta.ObjectCounters)
|
||||
for i := range oo {
|
||||
cnr, _ := oo[i].ContainerID()
|
||||
oSize := int64(oo[i].PayloadSize())
|
||||
expectedLogicalSizes[cnr.EncodeToString()] += oSize
|
||||
totalPayload += oSize
|
||||
expectedLogCC[cnr]++
|
||||
expectedPhyCC[cnr]++
|
||||
expected[cnr] = meta.ObjectCounters{
|
||||
Logic: 1,
|
||||
Phy: 1,
|
||||
}
|
||||
}
|
||||
|
||||
var prm PutPrm
|
||||
|
@ -227,8 +226,7 @@ func TestCounters(t *testing.T) {
|
|||
|
||||
cc, err := sh.metaBase.ContainerCounters(context.Background())
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, expectedLogCC, cc.Logical)
|
||||
require.Equal(t, expectedPhyCC, cc.Physical)
|
||||
require.Equal(t, meta.ContainerCounters{Counts: expected}, cc)
|
||||
|
||||
t.Run("inhume_GC", func(t *testing.T) {
|
||||
var prm InhumePrm
|
||||
|
@ -244,9 +242,13 @@ func TestCounters(t *testing.T) {
|
|||
require.True(t, ok)
|
||||
expectedLogicalSizes[cid.EncodeToString()] -= int64(oo[i].PayloadSize())
|
||||
|
||||
expectedLogCC[cid]--
|
||||
if expectedLogCC[cid] == 0 {
|
||||
delete(expectedLogCC, cid)
|
||||
if v, ok := expected[cid]; ok {
|
||||
v.Logic--
|
||||
if v.IsZero() {
|
||||
delete(expected, cid)
|
||||
} else {
|
||||
expected[cid] = v
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -257,8 +259,7 @@ func TestCounters(t *testing.T) {
|
|||
|
||||
cc, err := sh.metaBase.ContainerCounters(context.Background())
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, expectedLogCC, cc.Logical)
|
||||
require.Equal(t, expectedPhyCC, cc.Physical)
|
||||
require.Equal(t, meta.ContainerCounters{Counts: expected}, cc)
|
||||
|
||||
oo = oo[inhumedNumber:]
|
||||
})
|
||||
|
@ -281,9 +282,13 @@ func TestCounters(t *testing.T) {
|
|||
require.True(t, ok)
|
||||
expectedLogicalSizes[cid.EncodeToString()] -= int64(oo[i].PayloadSize())
|
||||
|
||||
expectedLogCC[cid]--
|
||||
if expectedLogCC[cid] == 0 {
|
||||
delete(expectedLogCC, cid)
|
||||
if v, ok := expected[cid]; ok {
|
||||
v.Logic--
|
||||
if v.IsZero() {
|
||||
delete(expected, cid)
|
||||
} else {
|
||||
expected[cid] = v
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -294,8 +299,7 @@ func TestCounters(t *testing.T) {
|
|||
|
||||
cc, err = sh.metaBase.ContainerCounters(context.Background())
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, expectedLogCC, cc.Logical)
|
||||
require.Equal(t, expectedPhyCC, cc.Physical)
|
||||
require.Equal(t, meta.ContainerCounters{Counts: expected}, cc)
|
||||
|
||||
oo = oo[inhumedNumber:]
|
||||
})
|
||||
|
@ -322,14 +326,14 @@ func TestCounters(t *testing.T) {
|
|||
cnr, _ := oo[i].ContainerID()
|
||||
expectedLogicalSizes[cnr.EncodeToString()] -= int64(removedPayload)
|
||||
|
||||
expectedLogCC[cnr]--
|
||||
if expectedLogCC[cnr] == 0 {
|
||||
delete(expectedLogCC, cnr)
|
||||
}
|
||||
|
||||
expectedPhyCC[cnr]--
|
||||
if expectedPhyCC[cnr] == 0 {
|
||||
delete(expectedPhyCC, cnr)
|
||||
if v, ok := expected[cnr]; ok {
|
||||
v.Logic--
|
||||
v.Phy--
|
||||
if v.IsZero() {
|
||||
delete(expected, cnr)
|
||||
} else {
|
||||
expected[cnr] = v
|
||||
}
|
||||
}
|
||||
}
|
||||
require.Equal(t, expectedLogicalSizes, mm.containerSizes())
|
||||
|
@ -337,8 +341,7 @@ func TestCounters(t *testing.T) {
|
|||
|
||||
cc, err = sh.metaBase.ContainerCounters(context.Background())
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, expectedLogCC, cc.Logical)
|
||||
require.Equal(t, expectedPhyCC, cc.Physical)
|
||||
require.Equal(t, meta.ContainerCounters{Counts: expected}, cc)
|
||||
})
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue