forked from TrueCloudLab/frostfs-node
[#328] container/load: Implement simple Iterator and Writer providers
Implement functions to wrap Writer or Iterator. The resulting wrapper provides WriterProvider or IteratorProvider interface respectively. Such a wrapper can be used as a single storage instance provider regardless of context. Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
2622e11ae3
commit
4415f8dc5b
1 changed files with 30 additions and 1 deletions
|
@ -1,9 +1,38 @@
|
||||||
package loadcontroller
|
package loadcontroller
|
||||||
|
|
||||||
import "github.com/nspcc-dev/neofs-api-go/pkg/container"
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/nspcc-dev/neofs-api-go/pkg/container"
|
||||||
|
)
|
||||||
|
|
||||||
func usedSpaceFilterEpochEQ(epoch uint64) UsedSpaceFilter {
|
func usedSpaceFilterEpochEQ(epoch uint64) UsedSpaceFilter {
|
||||||
return func(a container.UsedSpaceAnnouncement) bool {
|
return func(a container.UsedSpaceAnnouncement) bool {
|
||||||
return a.Epoch() == epoch
|
return a.Epoch() == epoch
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type storageWrapper struct {
|
||||||
|
w Writer
|
||||||
|
i Iterator
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s storageWrapper) InitIterator(context.Context) (Iterator, error) {
|
||||||
|
return s.i, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s storageWrapper) InitWriter(context.Context) (Writer, error) {
|
||||||
|
return s.w, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func SimpleIteratorProvider(i Iterator) IteratorProvider {
|
||||||
|
return &storageWrapper{
|
||||||
|
i: i,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func SimpleWriterProvider(w Writer) WriterProvider {
|
||||||
|
return &storageWrapper{
|
||||||
|
w: w,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue