[#1634] meta: Add epoch state

It allows performing expiration checks on the stored objects.

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
Pavel Karpy 2022-07-27 21:34:25 +03:00 committed by Pavel Karpy
parent a97dee008c
commit 9aba0ba512
9 changed files with 76 additions and 7 deletions

View file

@ -24,6 +24,13 @@ type matcher struct {
matchBucket func(*bbolt.Bucket, string, string, func([]byte, []byte) error) error
}
// EpochState is an interface that provides access to the
// current epoch number.
type EpochState interface {
// CurrentEpoch must return current epoch height.
CurrentEpoch() uint64
}
// DB represents local metabase of storage node.
type DB struct {
*cfg
@ -50,6 +57,8 @@ type cfg struct {
info Info
log *logger.Logger
epochState EpochState
}
func defaultCfg() *cfg {
@ -71,6 +80,10 @@ func New(opts ...Option) *DB {
opts[i](c)
}
if c.epochState == nil {
panic("metabase: epoch state is not specified")
}
return &DB{
cfg: c,
matchers: map[object.SearchMatchType]matcher{
@ -311,3 +324,10 @@ func WithMaxBatchDelay(d time.Duration) Option {
}
}
}
// WithEpochState return option to specify a source of current epoch height.
func WithEpochState(s EpochState) Option {
return func(c *cfg) {
c.epochState = s
}
}