frostfs-node/pkg/local_object_storage/shard/shard.go
Leonard Lyubich 383c483be7 [#176] localstore: Draft storage engine shard structure and ops
Implement the primary structure and operation of the local object
storage shard.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
2020-12-11 17:19:37 +03:00

46 lines
648 B
Go

package shard
import (
"sync"
)
// Shard represents single shard of NeoFS Local Storage Engine.
type Shard struct {
*cfg
mtx *sync.RWMutex
weight WeightValues
}
// Option represents Shard's constructor option.
type Option func(*cfg)
type cfg struct {
id *ID
}
func defaultCfg() *cfg {
return new(cfg)
}
// New creates, initializes and returns new Shard instance.
func New(opts ...Option) *Shard {
c := defaultCfg()
for i := range opts {
opts[i](c)
}
return &Shard{
cfg: c,
mtx: new(sync.RWMutex),
}
}
// WithID returns option to set shard identifier.
func WithID(id *ID) Option {
return func(c *cfg) {
c.id = id
}
}