frostfs-node/scripts/populate-metabase/main.go
Aleksey Savchuk 57be7d4c0b
[#1223] scripts/populate-metabase: Add attributes number option
Add option to choose number of object attributes

Signed-off-by: Aleksey Savchuk <a.savchuk@yadro.com>
2024-08-16 11:33:31 +03:00

98 lines
2.6 KiB
Go

package main
import (
"context"
"flag"
"fmt"
"os"
meta "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/metabase"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/shard/mode"
"git.frostfs.info/TrueCloudLab/frostfs-node/scripts/populate-metabase/util"
cidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id/test"
objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
)
var (
path = flag.String("path", "", "Path to metabase")
numContainers = flag.Uint("containers", 0, "Number of containers to be created")
numRegular = flag.Uint("regular-objs", 0, "Regular objects per container")
numTombstone = flag.Uint("tombstone-objs", 0, "Tombstone objects per container")
numLock = flag.Uint("lock-objs", 0, "Lock objects per container")
numAttributes = flag.Uint("attributes", 0, "Number of attributes per object")
)
type epochState struct{}
func (s epochState) CurrentEpoch() uint64 {
return 0
}
func main() {
flag.Parse()
if *path == "" {
exit("path to metabase not specified")
}
db := meta.New([]meta.Option{
meta.WithPath(*path),
meta.WithPermissions(0o600),
meta.WithEpochState(epochState{}),
}...)
exitOnErr("can't open the metabase", db.Open(context.Background(), mode.ReadWrite))
exitOnErr("can't init the metabase", db.Init())
defer func() {
exitOnErr("can't close the metabase", db.Close())
}()
var i uint
for i = 0; i < *numContainers; i++ {
cid := cidtest.ID()
err := util.PopulateWithObjects(db, *numRegular, func() *objectSDK.Object {
return util.GenerateObject([]util.ObjectOption{
util.WithContainerID(cid),
util.WithType(objectSDK.TypeRegular),
util.WithPayloadSize(32),
util.WithAttributes(*numAttributes),
}...)
})
exitOnErr("can't put an object", err)
err = util.PopulateWithObjects(db, *numTombstone, func() *objectSDK.Object {
return util.GenerateObject([]util.ObjectOption{
util.WithContainerID(cid),
util.WithType(objectSDK.TypeTombstone),
util.WithPayloadSize(32),
util.WithAttributes(*numAttributes),
}...)
})
exitOnErr("can't put an object", err)
err = util.PopulateWithObjects(db, *numLock, func() *objectSDK.Object {
return util.GenerateObject([]util.ObjectOption{
util.WithContainerID(cid),
util.WithType(objectSDK.TypeLock),
util.WithPayloadSize(32),
util.WithAttributes(*numAttributes),
}...)
})
exitOnErr("can't put an object", err)
}
}
func exit(msg string) {
fmt.Fprintln(os.Stderr, msg)
os.Exit(1)
}
func exitOnErr(msg string, err error) {
if err == nil {
return
}
fmt.Fprintln(os.Stderr, fmt.Errorf("%s: %w", msg, err))
os.Exit(1)
}