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 (optional)") numLock = flag.Uint("lock-objs", 0, "Lock objects per container (optional)") ) 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), }...) }) 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), }...) }) 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), }...) }) 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) }