2023-08-31 12:47:06 +00:00
|
|
|
package shard
|
2022-09-09 11:36:34 +00:00
|
|
|
|
|
|
|
import (
|
2023-03-23 14:59:14 +00:00
|
|
|
"context"
|
2022-09-09 11:36:34 +00:00
|
|
|
"path/filepath"
|
2023-08-23 07:43:16 +00:00
|
|
|
"sync"
|
2022-09-09 11:36:34 +00:00
|
|
|
"testing"
|
2023-10-31 11:16:34 +00:00
|
|
|
"time"
|
2022-09-09 11:36:34 +00:00
|
|
|
|
2023-03-07 13:38:26 +00:00
|
|
|
objectcore "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/object"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/fstree"
|
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"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/pilorama"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/shard/mode"
|
2023-11-02 10:50:52 +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"
|
2022-09-09 11:36:34 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
type metricsStore struct {
|
2024-03-12 14:36:26 +00:00
|
|
|
mtx sync.Mutex
|
|
|
|
objCounters map[string]uint64
|
|
|
|
cnrSize map[string]int64
|
|
|
|
cnrCount map[string]uint64
|
|
|
|
pldSize int64
|
|
|
|
mode mode.Mode
|
|
|
|
errCounter int64
|
|
|
|
refillCount int64
|
|
|
|
refillSize int64
|
|
|
|
refillPercent uint32
|
|
|
|
refillStatus string
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewMetricStore() *metricsStore {
|
|
|
|
return &metricsStore{
|
|
|
|
objCounters: map[string]uint64{
|
|
|
|
"phy": 0,
|
|
|
|
"logic": 0,
|
|
|
|
},
|
|
|
|
cnrSize: make(map[string]int64),
|
|
|
|
cnrCount: make(map[string]uint64),
|
|
|
|
}
|
2022-09-09 11:36:34 +00:00
|
|
|
}
|
|
|
|
|
2023-08-25 08:43:35 +00:00
|
|
|
func (m *metricsStore) SetShardID(_ string) {}
|
2022-10-12 17:55:35 +00:00
|
|
|
|
2023-08-25 08:43:35 +00:00
|
|
|
func (m *metricsStore) SetObjectCounter(objectType string, v uint64) {
|
|
|
|
m.mtx.Lock()
|
|
|
|
defer m.mtx.Unlock()
|
2022-12-01 11:59:22 +00:00
|
|
|
m.objCounters[objectType] = v
|
2022-09-09 11:36:34 +00:00
|
|
|
}
|
|
|
|
|
2023-08-30 12:24:31 +00:00
|
|
|
func (m *metricsStore) getObjectCounter(objectType string) uint64 {
|
|
|
|
m.mtx.Lock()
|
|
|
|
defer m.mtx.Unlock()
|
|
|
|
return m.objCounters[objectType]
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *metricsStore) containerSizes() map[string]int64 {
|
|
|
|
m.mtx.Lock()
|
|
|
|
defer m.mtx.Unlock()
|
|
|
|
|
|
|
|
r := make(map[string]int64, len(m.cnrSize))
|
|
|
|
for c, s := range m.cnrSize {
|
|
|
|
r[c] = s
|
|
|
|
}
|
|
|
|
return r
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *metricsStore) payloadSize() int64 {
|
|
|
|
m.mtx.Lock()
|
|
|
|
defer m.mtx.Unlock()
|
|
|
|
return m.pldSize
|
|
|
|
}
|
|
|
|
|
2023-08-25 08:43:35 +00:00
|
|
|
func (m *metricsStore) AddToObjectCounter(objectType string, delta int) {
|
|
|
|
m.mtx.Lock()
|
|
|
|
defer m.mtx.Unlock()
|
2022-09-09 11:36:34 +00:00
|
|
|
switch {
|
|
|
|
case delta > 0:
|
2022-12-01 11:59:22 +00:00
|
|
|
m.objCounters[objectType] += uint64(delta)
|
2022-09-09 11:36:34 +00:00
|
|
|
case delta < 0:
|
|
|
|
uDelta := uint64(-delta)
|
|
|
|
|
2022-12-01 11:59:22 +00:00
|
|
|
if m.objCounters[objectType] >= uDelta {
|
|
|
|
m.objCounters[objectType] -= uDelta
|
2022-09-09 11:36:34 +00:00
|
|
|
} else {
|
2022-12-01 11:59:22 +00:00
|
|
|
m.objCounters[objectType] = 0
|
2022-09-09 11:36:34 +00:00
|
|
|
}
|
|
|
|
case delta == 0:
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-23 07:43:16 +00:00
|
|
|
func (m *metricsStore) IncObjectCounter(objectType string) {
|
|
|
|
m.mtx.Lock()
|
|
|
|
defer m.mtx.Unlock()
|
2022-12-01 11:59:22 +00:00
|
|
|
m.objCounters[objectType] += 1
|
2022-09-09 11:36:34 +00:00
|
|
|
}
|
|
|
|
|
2023-06-14 08:00:44 +00:00
|
|
|
func (m *metricsStore) SetMode(mode mode.Mode) {
|
2023-08-23 07:43:16 +00:00
|
|
|
m.mtx.Lock()
|
|
|
|
defer m.mtx.Unlock()
|
2023-06-14 08:00:44 +00:00
|
|
|
m.mode = mode
|
2022-12-01 11:59:22 +00:00
|
|
|
}
|
|
|
|
|
2023-08-23 07:43:16 +00:00
|
|
|
func (m *metricsStore) AddToContainerSize(cnr string, size int64) {
|
|
|
|
m.mtx.Lock()
|
|
|
|
defer m.mtx.Unlock()
|
2022-12-01 11:59:22 +00:00
|
|
|
m.cnrSize[cnr] += size
|
2022-12-09 13:52:13 +00:00
|
|
|
}
|
|
|
|
|
2023-01-25 14:01:25 +00:00
|
|
|
func (m *metricsStore) AddToPayloadSize(size int64) {
|
2023-08-23 07:43:16 +00:00
|
|
|
m.mtx.Lock()
|
|
|
|
defer m.mtx.Unlock()
|
2023-01-25 14:01:25 +00:00
|
|
|
m.pldSize += size
|
|
|
|
}
|
|
|
|
|
2023-06-01 14:28:04 +00:00
|
|
|
func (m *metricsStore) IncErrorCounter() {
|
2023-08-23 07:43:16 +00:00
|
|
|
m.mtx.Lock()
|
|
|
|
defer m.mtx.Unlock()
|
2023-06-01 14:28:04 +00:00
|
|
|
m.errCounter += 1
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *metricsStore) ClearErrorCounter() {
|
2023-08-23 07:43:16 +00:00
|
|
|
m.mtx.Lock()
|
|
|
|
defer m.mtx.Unlock()
|
2023-06-01 14:28:04 +00:00
|
|
|
m.errCounter = 0
|
|
|
|
}
|
|
|
|
|
2023-06-13 16:48:15 +00:00
|
|
|
func (m *metricsStore) DeleteShardMetrics() {
|
2023-08-23 07:43:16 +00:00
|
|
|
m.mtx.Lock()
|
|
|
|
defer m.mtx.Unlock()
|
2023-06-01 14:28:04 +00:00
|
|
|
m.errCounter = 0
|
|
|
|
}
|
|
|
|
|
2023-11-02 10:50:52 +00:00
|
|
|
func (m *metricsStore) SetContainerObjectsCount(cnrID string, objectType string, value uint64) {
|
|
|
|
m.mtx.Lock()
|
|
|
|
defer m.mtx.Unlock()
|
|
|
|
m.cnrCount[cnrID+objectType] = value
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *metricsStore) IncContainerObjectsCount(cnrID string, objectType string) {
|
|
|
|
m.mtx.Lock()
|
|
|
|
defer m.mtx.Unlock()
|
|
|
|
m.cnrCount[cnrID+objectType]++
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *metricsStore) SubContainerObjectsCount(cnrID string, objectType string, value uint64) {
|
|
|
|
m.mtx.Lock()
|
|
|
|
defer m.mtx.Unlock()
|
|
|
|
existed := m.cnrCount[cnrID+objectType]
|
|
|
|
if existed < value {
|
|
|
|
panic("existed value smaller than value to sustract")
|
|
|
|
}
|
|
|
|
if existed == value {
|
|
|
|
delete(m.cnrCount, cnrID+objectType)
|
|
|
|
} else {
|
|
|
|
m.cnrCount[cnrID+objectType] -= value
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *metricsStore) getContainerCount(cnrID, objectType string) (uint64, bool) {
|
|
|
|
m.mtx.Lock()
|
|
|
|
defer m.mtx.Unlock()
|
|
|
|
v, ok := m.cnrCount[cnrID+objectType]
|
|
|
|
return v, ok
|
|
|
|
}
|
|
|
|
|
2024-03-12 14:36:26 +00:00
|
|
|
func (m *metricsStore) IncRefillObjectsCount(_ string, size int, success bool) {
|
|
|
|
m.mtx.Lock()
|
|
|
|
defer m.mtx.Unlock()
|
|
|
|
|
|
|
|
m.refillCount++
|
|
|
|
m.refillSize += int64(size)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *metricsStore) SetRefillPercent(_ string, percent uint32) {
|
|
|
|
m.mtx.Lock()
|
|
|
|
defer m.mtx.Unlock()
|
|
|
|
|
|
|
|
m.refillPercent = percent
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *metricsStore) SetRefillStatus(_ string, status string) {
|
|
|
|
m.mtx.Lock()
|
|
|
|
defer m.mtx.Unlock()
|
|
|
|
|
|
|
|
m.refillStatus = status
|
|
|
|
}
|
|
|
|
|
2024-09-03 09:18:10 +00:00
|
|
|
func (m *metricsStore) SetEvacuationInProgress(bool) {
|
|
|
|
}
|
|
|
|
|
2022-09-09 11:36:34 +00:00
|
|
|
func TestCounters(t *testing.T) {
|
2023-05-05 11:08:10 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2022-09-09 11:36:34 +00:00
|
|
|
dir := t.TempDir()
|
|
|
|
sh, mm := shardWithMetrics(t, dir)
|
2024-01-09 13:26:43 +00:00
|
|
|
defer func() { require.NoError(t, sh.Close()) }()
|
2022-09-09 11:36:34 +00:00
|
|
|
|
2022-12-09 13:52:13 +00:00
|
|
|
sh.SetMode(mode.ReadOnly)
|
2023-06-14 08:00:44 +00:00
|
|
|
require.Equal(t, mode.ReadOnly, mm.mode)
|
2022-12-09 13:52:13 +00:00
|
|
|
sh.SetMode(mode.ReadWrite)
|
2023-06-14 08:00:44 +00:00
|
|
|
require.Equal(t, mode.ReadWrite, mm.mode)
|
2022-12-09 13:52:13 +00:00
|
|
|
|
2022-09-09 11:36:34 +00:00
|
|
|
const objNumber = 10
|
2023-07-06 12:36:41 +00:00
|
|
|
oo := make([]*objectSDK.Object, objNumber)
|
2024-08-30 16:20:55 +00:00
|
|
|
for i := range objNumber {
|
2023-03-20 14:10:26 +00:00
|
|
|
oo[i] = testutil.GenerateObject()
|
2022-09-09 11:36:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
t.Run("defaults", func(t *testing.T) {
|
2023-08-30 12:24:31 +00:00
|
|
|
require.Zero(t, mm.getObjectCounter(physical))
|
|
|
|
require.Zero(t, mm.getObjectCounter(logical))
|
|
|
|
require.Empty(t, mm.containerSizes())
|
|
|
|
require.Zero(t, mm.payloadSize())
|
2023-11-02 10:50:52 +00:00
|
|
|
|
|
|
|
for _, obj := range oo {
|
|
|
|
contID, _ := obj.ContainerID()
|
|
|
|
v, ok := mm.getContainerCount(contID.EncodeToString(), physical)
|
|
|
|
require.Zero(t, v)
|
|
|
|
require.False(t, ok)
|
|
|
|
v, ok = mm.getContainerCount(contID.EncodeToString(), logical)
|
|
|
|
require.Zero(t, v)
|
|
|
|
require.False(t, ok)
|
2023-12-05 14:00:16 +00:00
|
|
|
v, ok = mm.getContainerCount(contID.EncodeToString(), user)
|
|
|
|
require.Zero(t, v)
|
|
|
|
require.False(t, ok)
|
2023-11-02 10:50:52 +00:00
|
|
|
}
|
2022-09-09 11:36:34 +00:00
|
|
|
})
|
|
|
|
|
2023-01-25 14:01:25 +00:00
|
|
|
var totalPayload int64
|
|
|
|
|
2023-10-31 11:16:34 +00:00
|
|
|
expectedLogicalSizes := make(map[string]int64)
|
2023-12-04 14:35:11 +00:00
|
|
|
expected := make(map[cid.ID]meta.ObjectCounters)
|
2022-12-01 11:59:22 +00:00
|
|
|
for i := range oo {
|
|
|
|
cnr, _ := oo[i].ContainerID()
|
2023-01-25 14:01:25 +00:00
|
|
|
oSize := int64(oo[i].PayloadSize())
|
2023-10-31 11:16:34 +00:00
|
|
|
expectedLogicalSizes[cnr.EncodeToString()] += oSize
|
2023-01-25 14:01:25 +00:00
|
|
|
totalPayload += oSize
|
2023-12-04 14:35:11 +00:00
|
|
|
expected[cnr] = 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-12-01 11:59:22 +00:00
|
|
|
}
|
|
|
|
|
2023-08-31 12:47:06 +00:00
|
|
|
var prm PutPrm
|
2022-09-09 11:36:34 +00:00
|
|
|
|
2024-08-30 16:20:55 +00:00
|
|
|
for i := range objNumber {
|
2023-08-30 15:25:56 +00:00
|
|
|
prm.SetObject(oo[i])
|
2022-09-09 11:36:34 +00:00
|
|
|
|
2023-08-30 15:25:56 +00:00
|
|
|
_, err := sh.Put(context.Background(), prm)
|
|
|
|
require.NoError(t, err)
|
|
|
|
}
|
2022-09-09 11:36:34 +00:00
|
|
|
|
2023-08-30 15:25:56 +00:00
|
|
|
require.Equal(t, uint64(objNumber), mm.getObjectCounter(physical))
|
|
|
|
require.Equal(t, uint64(objNumber), mm.getObjectCounter(logical))
|
2023-12-05 14:00:16 +00:00
|
|
|
require.Equal(t, uint64(objNumber), mm.getObjectCounter(user))
|
2023-10-31 11:16:34 +00:00
|
|
|
require.Equal(t, expectedLogicalSizes, mm.containerSizes())
|
2023-08-30 15:25:56 +00:00
|
|
|
require.Equal(t, totalPayload, mm.payloadSize())
|
2022-09-09 11:36:34 +00:00
|
|
|
|
2023-11-02 10:50:52 +00:00
|
|
|
cc, err := sh.metaBase.ContainerCounters(context.Background())
|
|
|
|
require.NoError(t, err)
|
2023-12-04 14:35:11 +00:00
|
|
|
require.Equal(t, meta.ContainerCounters{Counts: expected}, cc)
|
2023-11-02 10:50:52 +00:00
|
|
|
|
2022-09-09 11:36:34 +00:00
|
|
|
t.Run("inhume_GC", func(t *testing.T) {
|
2023-08-31 12:47:06 +00:00
|
|
|
var prm InhumePrm
|
2022-09-09 11:36:34 +00:00
|
|
|
inhumedNumber := objNumber / 4
|
|
|
|
|
2024-08-30 16:20:55 +00:00
|
|
|
for i := range inhumedNumber {
|
2022-09-09 11:36:34 +00:00
|
|
|
prm.MarkAsGarbage(objectcore.AddressOf(oo[i]))
|
|
|
|
|
2023-04-04 11:40:01 +00:00
|
|
|
_, err := sh.Inhume(context.Background(), prm)
|
2022-09-09 11:36:34 +00:00
|
|
|
require.NoError(t, err)
|
2023-10-31 11:16:34 +00:00
|
|
|
|
|
|
|
cid, ok := oo[i].ContainerID()
|
|
|
|
require.True(t, ok)
|
|
|
|
expectedLogicalSizes[cid.EncodeToString()] -= int64(oo[i].PayloadSize())
|
2023-11-02 10:50:52 +00:00
|
|
|
|
2023-12-04 14:35:11 +00:00
|
|
|
if v, ok := expected[cid]; 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(expected, cid)
|
|
|
|
} else {
|
|
|
|
expected[cid] = v
|
|
|
|
}
|
2023-11-02 10:50:52 +00:00
|
|
|
}
|
2022-09-09 11:36:34 +00:00
|
|
|
}
|
|
|
|
|
2023-08-30 12:24:31 +00:00
|
|
|
require.Equal(t, uint64(objNumber), mm.getObjectCounter(physical))
|
|
|
|
require.Equal(t, uint64(objNumber-inhumedNumber), mm.getObjectCounter(logical))
|
2023-12-05 14:00:16 +00:00
|
|
|
require.Equal(t, uint64(objNumber-inhumedNumber), mm.getObjectCounter(user))
|
2023-10-31 11:16:34 +00:00
|
|
|
require.Equal(t, expectedLogicalSizes, mm.containerSizes())
|
2023-08-30 12:24:31 +00:00
|
|
|
require.Equal(t, totalPayload, mm.payloadSize())
|
2022-09-09 11:36:34 +00:00
|
|
|
|
2023-11-02 10:50:52 +00:00
|
|
|
cc, err := sh.metaBase.ContainerCounters(context.Background())
|
|
|
|
require.NoError(t, err)
|
2023-12-04 14:35:11 +00:00
|
|
|
require.Equal(t, meta.ContainerCounters{Counts: expected}, cc)
|
2023-11-02 10:50:52 +00:00
|
|
|
|
2022-09-09 11:36:34 +00:00
|
|
|
oo = oo[inhumedNumber:]
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("inhume_TS", func(t *testing.T) {
|
2023-08-31 12:47:06 +00:00
|
|
|
var prm InhumePrm
|
2023-03-20 14:10:26 +00:00
|
|
|
ts := objectcore.AddressOf(testutil.GenerateObject())
|
2022-09-09 11:36:34 +00:00
|
|
|
|
2023-08-30 12:24:31 +00:00
|
|
|
phy := mm.getObjectCounter(physical)
|
|
|
|
logic := mm.getObjectCounter(logical)
|
2023-12-05 14:00:16 +00:00
|
|
|
custom := mm.getObjectCounter(user)
|
2022-09-09 11:36:34 +00:00
|
|
|
|
|
|
|
inhumedNumber := int(phy / 4)
|
|
|
|
prm.SetTarget(ts, addrFromObjs(oo[:inhumedNumber])...)
|
|
|
|
|
2023-04-04 11:40:01 +00:00
|
|
|
_, err := sh.Inhume(context.Background(), prm)
|
2022-09-09 11:36:34 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2024-08-30 16:20:55 +00:00
|
|
|
for i := range inhumedNumber {
|
2023-10-31 11:16:34 +00:00
|
|
|
cid, ok := oo[i].ContainerID()
|
|
|
|
require.True(t, ok)
|
|
|
|
expectedLogicalSizes[cid.EncodeToString()] -= int64(oo[i].PayloadSize())
|
2023-11-02 10:50:52 +00:00
|
|
|
|
2023-12-04 14:35:11 +00:00
|
|
|
if v, ok := expected[cid]; 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(expected, cid)
|
|
|
|
} else {
|
|
|
|
expected[cid] = v
|
|
|
|
}
|
2023-11-02 10:50:52 +00:00
|
|
|
}
|
2023-10-31 11:16:34 +00:00
|
|
|
}
|
|
|
|
|
2023-08-30 12:24:31 +00:00
|
|
|
require.Equal(t, phy, mm.getObjectCounter(physical))
|
|
|
|
require.Equal(t, logic-uint64(inhumedNumber), mm.getObjectCounter(logical))
|
2023-12-05 14:00:16 +00:00
|
|
|
require.Equal(t, custom-uint64(inhumedNumber), mm.getObjectCounter(user))
|
2023-10-31 11:16:34 +00:00
|
|
|
require.Equal(t, expectedLogicalSizes, mm.containerSizes())
|
2023-08-30 12:24:31 +00:00
|
|
|
require.Equal(t, totalPayload, mm.payloadSize())
|
2022-09-09 11:36:34 +00:00
|
|
|
|
2023-11-02 10:50:52 +00:00
|
|
|
cc, err = sh.metaBase.ContainerCounters(context.Background())
|
|
|
|
require.NoError(t, err)
|
2023-12-04 14:35:11 +00:00
|
|
|
require.Equal(t, meta.ContainerCounters{Counts: expected}, cc)
|
2023-11-02 10:50:52 +00:00
|
|
|
|
2022-09-09 11:36:34 +00:00
|
|
|
oo = oo[inhumedNumber:]
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Delete", func(t *testing.T) {
|
2023-08-31 12:47:06 +00:00
|
|
|
var prm DeletePrm
|
2022-09-09 11:36:34 +00:00
|
|
|
|
2023-08-30 12:24:31 +00:00
|
|
|
phy := mm.getObjectCounter(physical)
|
|
|
|
logic := mm.getObjectCounter(logical)
|
2023-12-05 14:00:16 +00:00
|
|
|
custom := mm.getObjectCounter(user)
|
2022-09-09 11:36:34 +00:00
|
|
|
|
|
|
|
deletedNumber := int(phy / 4)
|
|
|
|
prm.SetAddresses(addrFromObjs(oo[:deletedNumber])...)
|
|
|
|
|
2023-04-12 14:01:29 +00:00
|
|
|
_, err := sh.Delete(context.Background(), prm)
|
2022-09-09 11:36:34 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2023-08-30 12:24:31 +00:00
|
|
|
require.Equal(t, phy-uint64(deletedNumber), mm.getObjectCounter(physical))
|
|
|
|
require.Equal(t, logic-uint64(deletedNumber), mm.getObjectCounter(logical))
|
2023-12-05 14:00:16 +00:00
|
|
|
require.Equal(t, custom-uint64(deletedNumber), mm.getObjectCounter(user))
|
2023-01-25 14:01:25 +00:00
|
|
|
var totalRemovedpayload uint64
|
2022-12-01 11:59:22 +00:00
|
|
|
for i := range oo[:deletedNumber] {
|
2023-01-25 14:01:25 +00:00
|
|
|
removedPayload := oo[i].PayloadSize()
|
|
|
|
totalRemovedpayload += removedPayload
|
|
|
|
|
2022-12-01 11:59:22 +00:00
|
|
|
cnr, _ := oo[i].ContainerID()
|
2023-10-31 11:16:34 +00:00
|
|
|
expectedLogicalSizes[cnr.EncodeToString()] -= int64(removedPayload)
|
2023-11-02 10:50:52 +00:00
|
|
|
|
2023-12-04 14:35:11 +00:00
|
|
|
if v, ok := expected[cnr]; ok {
|
|
|
|
v.Logic--
|
|
|
|
v.Phy--
|
2023-12-05 14:00:16 +00:00
|
|
|
v.User--
|
2023-12-27 15:23:12 +00:00
|
|
|
expected[cnr] = v
|
2023-11-02 10:50:52 +00:00
|
|
|
}
|
2022-12-01 11:59:22 +00:00
|
|
|
}
|
2023-10-31 11:16:34 +00:00
|
|
|
require.Equal(t, expectedLogicalSizes, mm.containerSizes())
|
2023-08-30 12:24:31 +00:00
|
|
|
require.Equal(t, totalPayload-int64(totalRemovedpayload), mm.payloadSize())
|
2023-11-02 10:50:52 +00:00
|
|
|
|
|
|
|
cc, err = sh.metaBase.ContainerCounters(context.Background())
|
|
|
|
require.NoError(t, err)
|
2023-12-04 14:35:11 +00:00
|
|
|
require.Equal(t, meta.ContainerCounters{Counts: expected}, cc)
|
2022-09-09 11:36:34 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-08-31 12:47:06 +00:00
|
|
|
func shardWithMetrics(t *testing.T, path string) (*Shard, *metricsStore) {
|
2022-09-09 11:36:34 +00:00
|
|
|
blobOpts := []blobstor.Option{
|
|
|
|
blobstor.WithStorages([]blobstor.SubStorage{
|
|
|
|
{
|
|
|
|
Storage: fstree.New(
|
|
|
|
fstree.WithDirNameLen(2),
|
|
|
|
fstree.WithPath(filepath.Join(path, "blob")),
|
|
|
|
fstree.WithDepth(1)),
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
}
|
|
|
|
|
2024-03-12 14:36:26 +00:00
|
|
|
mm := NewMetricStore()
|
2022-09-09 11:36:34 +00:00
|
|
|
|
2023-08-31 12:47:06 +00:00
|
|
|
sh := New(
|
|
|
|
WithID(NewIDFromBytes([]byte{})),
|
|
|
|
WithBlobStorOptions(blobOpts...),
|
|
|
|
WithPiloramaOptions(pilorama.WithPath(filepath.Join(path, "pilorama"))),
|
|
|
|
WithMetaBaseOptions(
|
2022-09-09 11:36:34 +00:00
|
|
|
meta.WithPath(filepath.Join(path, "meta")),
|
|
|
|
meta.WithEpochState(epochState{})),
|
2023-08-31 12:47:06 +00:00
|
|
|
WithMetricsWriter(mm),
|
2023-10-31 11:21:42 +00:00
|
|
|
WithGCRemoverSleepInterval(time.Hour),
|
2022-09-09 11:36:34 +00:00
|
|
|
)
|
2023-08-31 16:26:47 +00:00
|
|
|
require.NoError(t, sh.Open(context.Background()))
|
2023-03-23 14:59:14 +00:00
|
|
|
require.NoError(t, sh.Init(context.Background()))
|
2022-09-09 11:36:34 +00:00
|
|
|
|
|
|
|
return sh, mm
|
|
|
|
}
|
|
|
|
|
2023-07-06 12:36:41 +00:00
|
|
|
func addrFromObjs(oo []*objectSDK.Object) []oid.Address {
|
2022-09-09 11:36:34 +00:00
|
|
|
aa := make([]oid.Address, len(oo))
|
|
|
|
|
2024-08-30 16:20:55 +00:00
|
|
|
for i := range len(oo) {
|
2022-09-09 11:36:34 +00:00
|
|
|
aa[i] = objectcore.AddressOf(oo[i])
|
|
|
|
}
|
|
|
|
|
|
|
|
return aa
|
|
|
|
}
|