forked from TrueCloudLab/frostfs-node
[#1048] metabase: Fix drop buckets during resync
Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
parent
5d58b44bc8
commit
c09c701613
2 changed files with 82 additions and 21 deletions
57
pkg/local_object_storage/metabase/reset_test.go
Normal file
57
pkg/local_object_storage/metabase/reset_test.go
Normal file
|
@ -0,0 +1,57 @@
|
|||
package meta
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/internal/testutil"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/shard/mode"
|
||||
"github.com/stretchr/testify/require"
|
||||
"go.etcd.io/bbolt"
|
||||
)
|
||||
|
||||
type epochState struct{ e uint64 }
|
||||
|
||||
func (s epochState) CurrentEpoch() uint64 {
|
||||
return s.e
|
||||
}
|
||||
|
||||
func TestResetDropsContainerBuckets(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
db := New(
|
||||
[]Option{
|
||||
WithPath(filepath.Join(t.TempDir(), "metabase")),
|
||||
WithPermissions(0o600),
|
||||
WithEpochState(epochState{}),
|
||||
}...,
|
||||
)
|
||||
|
||||
require.NoError(t, db.Open(context.Background(), mode.ReadWrite))
|
||||
require.NoError(t, db.Init())
|
||||
|
||||
defer func() { require.NoError(t, db.Close()) }()
|
||||
|
||||
for idx := 0; idx < 100; idx++ {
|
||||
var putPrm PutPrm
|
||||
putPrm.SetObject(testutil.GenerateObject())
|
||||
putPrm.SetStorageID([]byte(fmt.Sprintf("0/%d", idx)))
|
||||
_, err := db.Put(context.Background(), putPrm)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
require.NoError(t, db.Reset())
|
||||
|
||||
var bucketCount int
|
||||
require.NoError(t, db.boltDB.Update(func(tx *bbolt.Tx) error {
|
||||
return tx.ForEach(func(name []byte, b *bbolt.Bucket) error {
|
||||
_, exists := mStaticBuckets[string(name)]
|
||||
require.True(t, exists, "unexpected bucket:"+string(name))
|
||||
bucketCount++
|
||||
return nil
|
||||
})
|
||||
}))
|
||||
require.Equal(t, len(mStaticBuckets), bucketCount)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue