2019-01-24 20:15:10 +00:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
2018-11-08 16:18:28 +00:00
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
2019-01-23 19:58:44 +00:00
|
|
|
package tally_test
|
2018-11-08 16:18:28 +00:00
|
|
|
|
|
|
|
import (
|
2019-06-20 20:15:13 +01:00
|
|
|
"fmt"
|
2018-11-08 16:18:28 +00:00
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2019-02-07 19:22:49 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
2019-02-01 18:50:12 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
2022-10-05 11:53:02 +01:00
|
|
|
"go.uber.org/zap"
|
2018-12-07 09:59:31 +00:00
|
|
|
|
2019-12-27 11:48:47 +00:00
|
|
|
"storj.io/common/memory"
|
|
|
|
"storj.io/common/storj"
|
|
|
|
"storj.io/common/testcontext"
|
|
|
|
"storj.io/common/testrand"
|
2020-03-30 10:08:50 +01:00
|
|
|
"storj.io/common/uuid"
|
2019-11-14 19:46:15 +00:00
|
|
|
"storj.io/storj/private/testplanet"
|
2022-10-05 11:53:02 +01:00
|
|
|
"storj.io/storj/satellite"
|
2019-07-28 06:55:36 +01:00
|
|
|
"storj.io/storj/satellite/accounting"
|
2019-10-07 21:55:20 +01:00
|
|
|
"storj.io/storj/satellite/accounting/tally"
|
2021-04-21 13:42:57 +01:00
|
|
|
"storj.io/storj/satellite/metabase"
|
2018-11-08 16:18:28 +00:00
|
|
|
)
|
|
|
|
|
2019-05-10 20:05:42 +01:00
|
|
|
func TestDeleteTalliesBefore(t *testing.T) {
|
2019-04-03 04:55:24 +01:00
|
|
|
tests := []struct {
|
|
|
|
eraseBefore time.Time
|
|
|
|
expectedRaws int
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
eraseBefore: time.Now(),
|
2022-07-20 09:10:29 +01:00
|
|
|
expectedRaws: 3,
|
2019-04-03 04:55:24 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
eraseBefore: time.Now().Add(24 * time.Hour),
|
|
|
|
expectedRaws: 0,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
2019-05-29 14:30:16 +01:00
|
|
|
test := tt
|
2019-04-03 04:55:24 +01:00
|
|
|
testplanet.Run(t, testplanet.Config{
|
|
|
|
SatelliteCount: 1, StorageNodeCount: 0, UplinkCount: 0,
|
|
|
|
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
|
|
|
nodeData := make(map[storj.NodeID]float64)
|
2022-07-20 09:10:29 +01:00
|
|
|
nodeData[storj.NodeID{1}] = float64(1000)
|
|
|
|
nodeData[storj.NodeID{2}] = float64(1000)
|
|
|
|
nodeData[storj.NodeID{3}] = float64(1000)
|
2019-04-03 04:55:24 +01:00
|
|
|
|
2019-05-10 20:05:42 +01:00
|
|
|
err := planet.Satellites[0].DB.StoragenodeAccounting().SaveTallies(ctx, time.Now(), nodeData)
|
2019-04-03 04:55:24 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-07-20 09:10:29 +01:00
|
|
|
err = planet.Satellites[0].DB.StoragenodeAccounting().DeleteTalliesBefore(ctx, test.eraseBefore, 1)
|
2019-04-03 04:55:24 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2019-05-10 20:05:42 +01:00
|
|
|
raws, err := planet.Satellites[0].DB.StoragenodeAccounting().GetTallies(ctx)
|
2019-04-03 04:55:24 +01:00
|
|
|
require.NoError(t, err)
|
2019-05-29 14:30:16 +01:00
|
|
|
assert.Len(t, raws, test.expectedRaws)
|
2019-04-03 04:55:24 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2019-04-09 14:48:35 +01:00
|
|
|
|
2019-04-29 18:46:38 +01:00
|
|
|
func TestOnlyInline(t *testing.T) {
|
|
|
|
testplanet.Run(t, testplanet.Config{
|
2021-09-21 13:20:26 +01:00
|
|
|
SatelliteCount: 1, StorageNodeCount: 4, UplinkCount: 1,
|
2019-04-29 18:46:38 +01:00
|
|
|
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
2019-10-07 21:55:20 +01:00
|
|
|
planet.Satellites[0].Accounting.Tally.Loop.Pause()
|
2022-04-14 12:20:18 +01:00
|
|
|
up := planet.Uplinks[0]
|
2019-06-13 17:58:40 +01:00
|
|
|
|
2019-04-29 18:46:38 +01:00
|
|
|
// Setup: create data for the uplink to upload
|
2019-06-26 11:38:51 +01:00
|
|
|
expectedData := testrand.Bytes(1 * memory.KiB)
|
2019-04-29 18:46:38 +01:00
|
|
|
|
|
|
|
// Setup: get the expected size of the data that will be stored in pointer
|
2019-06-19 09:11:27 +01:00
|
|
|
// Since the data is small enough to be stored inline, when it is encrypted, we only
|
|
|
|
// add 16 bytes of encryption authentication overhead. No encryption block
|
|
|
|
// padding will be added since we are not chunking data that we store inline.
|
|
|
|
const encryptionAuthOverhead = 16 // bytes
|
|
|
|
expectedTotalBytes := len(expectedData) + encryptionAuthOverhead
|
2019-04-29 18:46:38 +01:00
|
|
|
|
|
|
|
// Setup: The data in this tally should match the pointer that the uplink.upload created
|
2019-06-13 17:58:40 +01:00
|
|
|
expectedBucketName := "testbucket"
|
2019-10-07 21:55:20 +01:00
|
|
|
expectedTally := &accounting.BucketTally{
|
2020-08-31 11:14:20 +01:00
|
|
|
BucketLocation: metabase.BucketLocation{
|
2022-04-14 12:20:18 +01:00
|
|
|
ProjectID: up.Projects[0].ID,
|
2020-08-31 11:14:20 +01:00
|
|
|
BucketName: expectedBucketName,
|
|
|
|
},
|
2021-07-01 12:29:25 +01:00
|
|
|
ObjectCount: 1,
|
|
|
|
TotalSegments: 1,
|
|
|
|
TotalBytes: int64(expectedTotalBytes),
|
|
|
|
MetadataSize: 0,
|
2019-04-29 18:46:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Execute test: upload a file, then calculate at rest data
|
2022-04-14 12:20:18 +01:00
|
|
|
err := up.Upload(ctx, planet.Satellites[0], expectedBucketName, "test/path", expectedData)
|
2019-04-29 18:46:38 +01:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2019-10-07 21:55:20 +01:00
|
|
|
// run multiple times to ensure we add tallies
|
2019-04-29 18:46:38 +01:00
|
|
|
for i := 0; i < 2; i++ {
|
2022-10-05 11:53:02 +01:00
|
|
|
collector := tally.NewBucketTallyCollector(planet.Satellites[0].Log.Named("bucket tally"), time.Now(), planet.Satellites[0].Metabase.DB, planet.Satellites[0].DB.Buckets(), planet.Satellites[0].Config.Tally)
|
2021-07-01 12:29:25 +01:00
|
|
|
err := collector.Run(ctx)
|
2019-04-29 18:46:38 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2019-10-07 21:55:20 +01:00
|
|
|
now := time.Now().Add(time.Duration(i) * time.Second)
|
2021-07-01 12:29:25 +01:00
|
|
|
err = planet.Satellites[0].DB.ProjectAccounting().SaveTallies(ctx, now, collector.Bucket)
|
2019-04-29 18:46:38 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2021-07-01 12:29:25 +01:00
|
|
|
assert.Equal(t, 1, len(collector.Bucket))
|
|
|
|
for _, actualTally := range collector.Bucket {
|
2020-11-25 11:33:24 +00:00
|
|
|
// checking the exact metadata size is brittle, instead, verify that it's not zero
|
|
|
|
assert.NotZero(t, actualTally.MetadataSize)
|
|
|
|
actualTally.MetadataSize = expectedTally.MetadataSize
|
2019-10-07 21:55:20 +01:00
|
|
|
assert.Equal(t, expectedTally, actualTally)
|
2019-04-29 18:46:38 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-06-13 17:58:40 +01:00
|
|
|
func TestCalculateBucketAtRestData(t *testing.T) {
|
|
|
|
testplanet.Run(t, testplanet.Config{
|
2020-12-17 13:04:42 +00:00
|
|
|
SatelliteCount: 1, StorageNodeCount: 4, UplinkCount: 2,
|
|
|
|
Reconfigure: testplanet.Reconfigure{
|
|
|
|
Satellite: testplanet.Combine(
|
|
|
|
testplanet.ReconfigureRS(2, 3, 4, 4),
|
|
|
|
testplanet.MaxSegmentSize(20*memory.KiB),
|
|
|
|
),
|
|
|
|
},
|
2019-06-13 17:58:40 +01:00
|
|
|
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
2020-12-17 13:04:42 +00:00
|
|
|
satellite := planet.Satellites[0]
|
|
|
|
|
|
|
|
err := planet.Uplinks[0].Upload(ctx, satellite, "alpha", "inline", make([]byte, 10*memory.KiB))
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
err = planet.Uplinks[0].Upload(ctx, satellite, "alpha", "remote", make([]byte, 30*memory.KiB))
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
err = planet.Uplinks[0].Upload(ctx, satellite, "beta", "remote", make([]byte, 30*memory.KiB))
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
err = planet.Uplinks[1].Upload(ctx, satellite, "alpha", "remote", make([]byte, 30*memory.KiB))
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2021-09-07 09:15:47 +01:00
|
|
|
objects, err := satellite.Metabase.DB.TestingAllObjects(ctx)
|
2020-12-17 13:04:42 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2021-09-07 09:15:47 +01:00
|
|
|
segments, err := satellite.Metabase.DB.TestingAllSegments(ctx)
|
2020-12-17 13:04:42 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
expectedTotal := map[metabase.BucketLocation]*accounting.BucketTally{}
|
|
|
|
ensure := func(loc metabase.BucketLocation) *accounting.BucketTally {
|
|
|
|
if t, ok := expectedTotal[loc]; ok {
|
|
|
|
return t
|
|
|
|
}
|
|
|
|
t := &accounting.BucketTally{BucketLocation: loc}
|
|
|
|
expectedTotal[loc] = t
|
|
|
|
return t
|
|
|
|
}
|
|
|
|
|
|
|
|
streamLocation := map[uuid.UUID]metabase.BucketLocation{}
|
|
|
|
for _, object := range objects {
|
|
|
|
loc := object.Location().Bucket()
|
|
|
|
streamLocation[object.StreamID] = loc
|
|
|
|
t := ensure(loc)
|
|
|
|
t.ObjectCount++
|
|
|
|
t.MetadataSize += int64(len(object.EncryptedMetadata))
|
2019-06-13 17:58:40 +01:00
|
|
|
}
|
2020-12-17 13:04:42 +00:00
|
|
|
for _, segment := range segments {
|
|
|
|
loc := streamLocation[segment.StreamID]
|
|
|
|
t := ensure(loc)
|
2021-07-01 12:29:25 +01:00
|
|
|
t.TotalSegments++
|
|
|
|
t.TotalBytes += int64(segment.EncryptedSize)
|
2020-12-17 13:04:42 +00:00
|
|
|
}
|
|
|
|
require.Len(t, expectedTotal, 3)
|
|
|
|
|
2022-10-05 11:53:02 +01:00
|
|
|
collector := tally.NewBucketTallyCollector(satellite.Log.Named("bucket tally"), time.Now(), satellite.Metabase.DB, planet.Satellites[0].DB.Buckets(), planet.Satellites[0].Config.Tally)
|
2021-07-01 12:29:25 +01:00
|
|
|
err = collector.Run(ctx)
|
2020-12-17 13:04:42 +00:00
|
|
|
require.NoError(t, err)
|
2021-07-01 12:29:25 +01:00
|
|
|
require.Equal(t, expectedTotal, collector.Bucket)
|
2019-06-20 20:15:13 +01:00
|
|
|
})
|
|
|
|
}
|
2019-06-13 17:58:40 +01:00
|
|
|
|
2021-09-21 13:20:26 +01:00
|
|
|
func TestIgnoresExpiredPointers(t *testing.T) {
|
2020-04-10 18:35:58 +01:00
|
|
|
testplanet.Run(t, testplanet.Config{
|
2021-09-21 13:20:26 +01:00
|
|
|
SatelliteCount: 1, StorageNodeCount: 4, UplinkCount: 1,
|
2020-04-10 18:35:58 +01:00
|
|
|
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
2020-12-17 13:04:42 +00:00
|
|
|
satellite := planet.Satellites[0]
|
2020-04-10 18:35:58 +01:00
|
|
|
|
2020-12-17 13:04:42 +00:00
|
|
|
now := time.Now()
|
|
|
|
err := planet.Uplinks[0].UploadWithExpiration(ctx, planet.Satellites[0], "bucket", "path", []byte{1}, now.Add(12*time.Hour))
|
2020-04-10 18:35:58 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-10-05 11:53:02 +01:00
|
|
|
collector := tally.NewBucketTallyCollector(satellite.Log.Named("bucket tally"), now.Add(24*time.Hour), satellite.Metabase.DB, planet.Satellites[0].DB.Buckets(), planet.Satellites[0].Config.Tally)
|
2021-07-01 12:29:25 +01:00
|
|
|
err = collector.Run(ctx)
|
2020-04-10 18:35:58 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2021-07-01 12:29:25 +01:00
|
|
|
// there should be no observed buckets because all of the objects are expired
|
|
|
|
require.Equal(t, collector.Bucket, map[metabase.BucketLocation]*accounting.BucketTally{})
|
2020-04-10 18:35:58 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-10-05 11:53:02 +01:00
|
|
|
func TestLiveAccountingWithObjectsLoop(t *testing.T) {
|
2019-10-31 17:27:38 +00:00
|
|
|
testplanet.Run(t, testplanet.Config{
|
2021-09-21 13:20:26 +01:00
|
|
|
SatelliteCount: 1, StorageNodeCount: 4, UplinkCount: 1,
|
|
|
|
Reconfigure: testplanet.Reconfigure{
|
|
|
|
Satellite: testplanet.MaxSegmentSize(20 * memory.KiB),
|
|
|
|
},
|
2019-10-31 17:27:38 +00:00
|
|
|
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
|
|
|
tally := planet.Satellites[0].Accounting.Tally
|
2020-04-16 13:12:46 +01:00
|
|
|
projectID := planet.Uplinks[0].Projects[0].ID
|
2019-10-31 17:27:38 +00:00
|
|
|
tally.Loop.Pause()
|
|
|
|
|
2021-09-21 13:20:26 +01:00
|
|
|
expectedData := testrand.Bytes(19 * memory.KiB)
|
2019-10-31 17:27:38 +00:00
|
|
|
|
|
|
|
err := planet.Uplinks[0].Upload(ctx, planet.Satellites[0], "testbucket", "test/path", expectedData)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2021-09-07 09:15:47 +01:00
|
|
|
segments, err := planet.Satellites[0].Metabase.DB.TestingAllSegments(ctx)
|
2019-10-31 17:27:38 +00:00
|
|
|
require.NoError(t, err)
|
2020-12-17 13:04:42 +00:00
|
|
|
require.Len(t, segments, 1)
|
2019-10-31 17:27:38 +00:00
|
|
|
|
2020-12-17 13:04:42 +00:00
|
|
|
segmentSize := int64(segments[0].EncryptedSize)
|
2019-10-31 17:27:38 +00:00
|
|
|
|
|
|
|
tally.Loop.TriggerWait()
|
|
|
|
|
|
|
|
expectedSize := segmentSize
|
|
|
|
|
|
|
|
total, err := planet.Satellites[0].Accounting.ProjectUsage.GetProjectStorageTotals(ctx, projectID)
|
2022-10-05 11:53:02 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, expectedSize, total)
|
|
|
|
|
|
|
|
for i := 0; i < 3; i++ {
|
|
|
|
err := planet.Uplinks[0].Upload(ctx, planet.Satellites[0], "testbucket", fmt.Sprintf("test/path/%d", i), expectedData)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
tally.Loop.TriggerWait()
|
|
|
|
|
|
|
|
expectedSize += segmentSize
|
|
|
|
|
|
|
|
total, err := planet.Satellites[0].Accounting.ProjectUsage.GetProjectStorageTotals(ctx, projectID)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, expectedSize, total)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestLiveAccountingWithCustomSQLQuery(t *testing.T) {
|
|
|
|
testplanet.Run(t, testplanet.Config{
|
|
|
|
SatelliteCount: 1, StorageNodeCount: 4, UplinkCount: 1,
|
|
|
|
Reconfigure: testplanet.Reconfigure{
|
|
|
|
Satellite: func(log *zap.Logger, index int, config *satellite.Config) {
|
|
|
|
config.Tally.UseObjectsLoop = false
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
|
|
|
tally := planet.Satellites[0].Accounting.Tally
|
|
|
|
projectID := planet.Uplinks[0].Projects[0].ID
|
|
|
|
tally.Loop.Pause()
|
|
|
|
|
|
|
|
expectedData := testrand.Bytes(19 * memory.KiB)
|
|
|
|
|
|
|
|
err := planet.Uplinks[0].Upload(ctx, planet.Satellites[0], "testbucket", "test/path", expectedData)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
segments, err := planet.Satellites[0].Metabase.DB.TestingAllSegments(ctx)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, segments, 1)
|
|
|
|
|
|
|
|
segmentSize := int64(segments[0].EncryptedSize)
|
|
|
|
|
|
|
|
tally.Loop.TriggerWait()
|
|
|
|
|
|
|
|
expectedSize := segmentSize
|
|
|
|
|
|
|
|
total, err := planet.Satellites[0].Accounting.ProjectUsage.GetProjectStorageTotals(ctx, projectID)
|
2019-10-31 17:27:38 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, expectedSize, total)
|
|
|
|
|
2021-09-21 13:20:26 +01:00
|
|
|
for i := 0; i < 3; i++ {
|
2019-10-31 17:27:38 +00:00
|
|
|
err := planet.Uplinks[0].Upload(ctx, planet.Satellites[0], "testbucket", fmt.Sprintf("test/path/%d", i), expectedData)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
tally.Loop.TriggerWait()
|
|
|
|
|
|
|
|
expectedSize += segmentSize
|
|
|
|
|
|
|
|
total, err := planet.Satellites[0].Accounting.ProjectUsage.GetProjectStorageTotals(ctx, projectID)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, expectedSize, total)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-09-21 13:20:26 +01:00
|
|
|
func TestEmptyProjectUpdatesLiveAccounting(t *testing.T) {
|
2020-01-29 14:34:12 +00:00
|
|
|
testplanet.Run(t, testplanet.Config{
|
2021-09-21 13:20:26 +01:00
|
|
|
SatelliteCount: 1, StorageNodeCount: 4, UplinkCount: 2,
|
|
|
|
Reconfigure: testplanet.Reconfigure{
|
|
|
|
Satellite: testplanet.MaxSegmentSize(20 * memory.KiB),
|
|
|
|
},
|
2020-01-29 14:34:12 +00:00
|
|
|
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
|
|
|
planet.Satellites[0].Accounting.Tally.Loop.Pause()
|
|
|
|
|
2020-04-16 13:12:46 +01:00
|
|
|
project1 := planet.Uplinks[1].Projects[0].ID
|
2020-01-29 14:34:12 +00:00
|
|
|
|
2021-09-21 13:20:26 +01:00
|
|
|
data := testrand.Bytes(30 * memory.KiB)
|
2020-01-29 14:34:12 +00:00
|
|
|
|
|
|
|
// we need an extra bucket with data for this test. If no buckets are found at all,
|
|
|
|
// the update block is skipped in tally
|
|
|
|
err := planet.Uplinks[0].Upload(ctx, planet.Satellites[0], "bucket", "test", data)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
err = planet.Uplinks[1].Upload(ctx, planet.Satellites[0], "bucket", "test", data)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
planet.Satellites[0].Accounting.Tally.Loop.TriggerWait()
|
|
|
|
planet.Satellites[0].Accounting.Tally.Loop.Pause()
|
|
|
|
|
|
|
|
total, err := planet.Satellites[0].Accounting.ProjectUsage.GetProjectStorageTotals(ctx, project1)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.True(t, total >= int64(len(data)))
|
|
|
|
|
|
|
|
err = planet.Uplinks[1].DeleteObject(ctx, planet.Satellites[0], "bucket", "test")
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
planet.Satellites[0].Accounting.Tally.Loop.TriggerWait()
|
|
|
|
|
|
|
|
p1Total, err := planet.Satellites[0].Accounting.ProjectUsage.GetProjectStorageTotals(ctx, project1)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Zero(t, p1Total)
|
|
|
|
})
|
|
|
|
}
|
2022-04-08 20:10:03 +01:00
|
|
|
|
|
|
|
func TestTallyOnCopiedObject(t *testing.T) {
|
|
|
|
testplanet.Run(t, testplanet.Config{
|
|
|
|
SatelliteCount: 1, StorageNodeCount: 4, UplinkCount: 1,
|
|
|
|
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
|
|
|
planet.Satellites[0].Accounting.Tally.Loop.Pause()
|
|
|
|
|
|
|
|
testCases := []struct {
|
|
|
|
name string
|
|
|
|
size memory.Size
|
|
|
|
expectedTallyAfterCopy accounting.BucketTally
|
|
|
|
expectedTallyAfterDelete accounting.BucketTally
|
|
|
|
}{
|
|
|
|
{"inline", memory.KiB,
|
|
|
|
accounting.BucketTally{
|
|
|
|
ObjectCount: 2,
|
|
|
|
TotalBytes: 2080,
|
|
|
|
TotalSegments: 2,
|
|
|
|
}, accounting.BucketTally{
|
|
|
|
ObjectCount: 1,
|
|
|
|
TotalBytes: 1040,
|
|
|
|
TotalSegments: 1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{"remote", 8 * memory.KiB,
|
|
|
|
accounting.BucketTally{
|
|
|
|
ObjectCount: 2,
|
|
|
|
TotalBytes: 29696,
|
|
|
|
TotalSegments: 2,
|
|
|
|
},
|
|
|
|
accounting.BucketTally{
|
|
|
|
ObjectCount: 1,
|
|
|
|
TotalBytes: 14848,
|
|
|
|
TotalSegments: 1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2022-04-20 11:25:54 +01:00
|
|
|
findTally := func(bucket string, tallies []accounting.BucketTally) accounting.BucketTally {
|
|
|
|
for _, v := range tallies {
|
|
|
|
if v.BucketName == bucket {
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
}
|
|
|
|
t.Fatalf("unable to find tally for %s", bucket)
|
|
|
|
return accounting.BucketTally{}
|
|
|
|
}
|
|
|
|
|
2022-04-08 20:10:03 +01:00
|
|
|
for _, tc := range testCases {
|
|
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
|
|
err := planet.Uplinks[0].CreateBucket(ctx, planet.Satellites[0], tc.name)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
data := testrand.Bytes(tc.size)
|
|
|
|
|
|
|
|
err = planet.Uplinks[0].Upload(ctx, planet.Satellites[0], tc.name, "ancestor", data)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
project, err := planet.Uplinks[0].GetProject(ctx, planet.Satellites[0])
|
|
|
|
require.NoError(t, err)
|
|
|
|
defer ctx.Check(project.Close)
|
|
|
|
|
|
|
|
_, err = project.CopyObject(ctx, tc.name, "ancestor", tc.name, "copy", nil)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
planet.Satellites[0].Accounting.Tally.Loop.TriggerWait()
|
|
|
|
planet.Satellites[0].Accounting.Tally.Loop.Pause()
|
|
|
|
|
|
|
|
tallies, err := planet.Satellites[0].DB.ProjectAccounting().GetTallies(ctx)
|
|
|
|
require.NoError(t, err)
|
2022-04-20 11:25:54 +01:00
|
|
|
lastTally := findTally(tc.name, tallies)
|
2022-04-08 20:10:03 +01:00
|
|
|
require.Equal(t, tc.name, lastTally.BucketName)
|
|
|
|
require.Equal(t, tc.expectedTallyAfterCopy.ObjectCount, lastTally.ObjectCount)
|
|
|
|
require.Equal(t, tc.expectedTallyAfterCopy.TotalBytes, lastTally.TotalBytes)
|
|
|
|
require.Equal(t, tc.expectedTallyAfterCopy.TotalSegments, lastTally.TotalSegments)
|
|
|
|
|
|
|
|
_, err = project.DeleteObject(ctx, tc.name, "ancestor")
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
planet.Satellites[0].Accounting.Tally.Loop.TriggerWait()
|
|
|
|
planet.Satellites[0].Accounting.Tally.Loop.Pause()
|
|
|
|
|
|
|
|
tallies, err = planet.Satellites[0].DB.ProjectAccounting().GetTallies(ctx)
|
|
|
|
require.NoError(t, err)
|
2022-04-20 11:25:54 +01:00
|
|
|
lastTally = findTally(tc.name, tallies)
|
2022-04-08 20:10:03 +01:00
|
|
|
require.Equal(t, tc.name, lastTally.BucketName)
|
|
|
|
require.Equal(t, tc.expectedTallyAfterDelete.ObjectCount, lastTally.ObjectCount)
|
|
|
|
require.Equal(t, tc.expectedTallyAfterDelete.TotalBytes, lastTally.TotalBytes)
|
|
|
|
require.Equal(t, tc.expectedTallyAfterDelete.TotalSegments, lastTally.TotalSegments)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|