package writecachebitcask import ( "context" "encoding/binary" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/common" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/shard/mode" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/writecache" objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object" oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id" ) func (c *cache) Get(_ context.Context, addr oid.Address) (*objectSDK.Object, error) { region := c.locateRegion(addr) return c.regions[region].get(addr) } func (c *cache) Head(_ context.Context, addr oid.Address) (*objectSDK.Object, error) { region := c.locateRegion(addr) return c.regions[region].get(addr) } func (c *cache) Put(ctx context.Context, req common.PutPrm) (common.PutRes, error) { if uint64(len(req.RawData)) > c.maxObjectSize { return common.PutRes{}, writecache.ErrBigObject } if mode.Mode(c.mode.Load()).ReadOnly() { return common.PutRes{}, writecache.ErrReadOnly } region := c.locateRegion(req.Address) return common.PutRes{}, c.regions[region].put(ctx, req.Address, req.RawData) } func (c *cache) Delete(ctx context.Context, addr oid.Address) error { if mode.Mode(c.mode.Load()).ReadOnly() { return writecache.ErrReadOnly } region := c.locateRegion(addr) return c.regions[region].delete(ctx, addr) } func (c *cache) locateRegion(addr oid.Address) int { id := addr.Object() h := binary.LittleEndian.Uint32(id[:4]) region := h & (uint32(c.regionCount) - 1) return int(region) }