forked from TrueCloudLab/frostfs-node
[#586] Fix writecache benchmarks and refactor hacky NeedsCompression
Signed-off-by: Alejandro Lopez <a.lopez@yadro.com>
This commit is contained in:
parent
023b90342c
commit
8f994163ee
17 changed files with 161 additions and 92 deletions
|
@ -252,6 +252,10 @@ func (b *Blobovniczas) SetCompressor(cc *compression.Config) {
|
|||
b.compression = cc
|
||||
}
|
||||
|
||||
func (b *Blobovniczas) Compressor() *compression.Config {
|
||||
return b.compression
|
||||
}
|
||||
|
||||
// SetReportErrorFunc implements common.Storage.
|
||||
func (b *Blobovniczas) SetReportErrorFunc(f func(string, error)) {
|
||||
b.reportError = f
|
||||
|
|
|
@ -128,3 +128,7 @@ func WithMetrics(m Metrics) Option {
|
|||
c.metrics = m
|
||||
}
|
||||
}
|
||||
|
||||
func (b *BlobStor) Compressor() *compression.Config {
|
||||
return &b.cfg.compression
|
||||
}
|
||||
|
|
|
@ -146,33 +146,33 @@ func TestBlobstor_needsCompression(t *testing.T) {
|
|||
b := newBlobStor(t, true, "audio/*", "*/x-mpeg", "*/mpeg", "application/x-midi")
|
||||
|
||||
obj := newObjectWithCt("video/mpeg")
|
||||
require.False(t, b.NeedsCompression(obj))
|
||||
require.False(t, b.compression.NeedsCompression(obj))
|
||||
|
||||
obj = newObjectWithCt("audio/aiff")
|
||||
require.False(t, b.NeedsCompression(obj))
|
||||
require.False(t, b.compression.NeedsCompression(obj))
|
||||
|
||||
obj = newObjectWithCt("application/x-midi")
|
||||
require.False(t, b.NeedsCompression(obj))
|
||||
require.False(t, b.compression.NeedsCompression(obj))
|
||||
|
||||
obj = newObjectWithCt("text/plain")
|
||||
require.True(t, b.NeedsCompression(obj))
|
||||
require.True(t, b.compression.NeedsCompression(obj))
|
||||
|
||||
obj = newObjectWithCt("")
|
||||
require.True(t, b.NeedsCompression(obj))
|
||||
require.True(t, b.compression.NeedsCompression(obj))
|
||||
})
|
||||
t.Run("content-types omitted", func(t *testing.T) {
|
||||
b := newBlobStor(t, true)
|
||||
obj := newObjectWithCt("video/mpeg")
|
||||
require.True(t, b.NeedsCompression(obj))
|
||||
require.True(t, b.compression.NeedsCompression(obj))
|
||||
})
|
||||
t.Run("compress disabled", func(t *testing.T) {
|
||||
b := newBlobStor(t, false, "video/mpeg")
|
||||
|
||||
obj := newObjectWithCt("video/mpeg")
|
||||
require.False(t, b.NeedsCompression(obj))
|
||||
require.False(t, b.compression.NeedsCompression(obj))
|
||||
|
||||
obj = newObjectWithCt("text/plain")
|
||||
require.False(t, b.NeedsCompression(obj))
|
||||
require.False(t, b.compression.NeedsCompression(obj))
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -15,7 +15,10 @@ type Storage interface {
|
|||
|
||||
Type() string
|
||||
Path() string
|
||||
|
||||
SetCompressor(cc *compression.Config)
|
||||
Compressor() *compression.Config
|
||||
|
||||
// SetReportErrorFunc allows to provide a function to be called on disk errors.
|
||||
// This function MUST be called before Open.
|
||||
SetReportErrorFunc(f func(string, error))
|
||||
|
|
|
@ -550,6 +550,10 @@ func (t *FSTree) SetCompressor(cc *compression.Config) {
|
|||
t.Config = cc
|
||||
}
|
||||
|
||||
func (t *FSTree) Compressor() *compression.Config {
|
||||
return t.Config
|
||||
}
|
||||
|
||||
// SetReportErrorFunc implements common.Storage.
|
||||
func (t *FSTree) SetReportErrorFunc(_ func(string, error)) {
|
||||
// Do nothing, FSTree can encounter only one error which is returned.
|
||||
|
|
|
@ -12,5 +12,6 @@ func (s *memstoreImpl) Close() error { return nil }
|
|||
func (s *memstoreImpl) Type() string { return Type }
|
||||
func (s *memstoreImpl) Path() string { return s.rootPath }
|
||||
func (s *memstoreImpl) SetCompressor(cc *compression.Config) { s.compression = cc }
|
||||
func (s *memstoreImpl) Compressor() *compression.Config { return s.compression }
|
||||
func (s *memstoreImpl) SetReportErrorFunc(f func(string, error)) { s.reportError = f }
|
||||
func (s *memstoreImpl) SetParentID(string) {}
|
||||
|
|
|
@ -9,7 +9,6 @@ import (
|
|||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/common"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/util/logicerr"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-observability/tracing"
|
||||
objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
)
|
||||
|
@ -72,11 +71,3 @@ func (b *BlobStor) Put(ctx context.Context, prm common.PutPrm) (common.PutRes, e
|
|||
|
||||
return common.PutRes{}, ErrNoPlaceFound
|
||||
}
|
||||
|
||||
// NeedsCompression returns true if the object should be compressed.
|
||||
// For an object to be compressed 2 conditions must hold:
|
||||
// 1. Compression is enabled in settings.
|
||||
// 2. Object MIME Content-Type is allowed for compression.
|
||||
func (b *BlobStor) NeedsCompression(obj *objectSDK.Object) bool {
|
||||
return b.cfg.compression.NeedsCompression(obj)
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ type cfg struct {
|
|||
Type func() string
|
||||
Path func() string
|
||||
SetCompressor func(cc *compression.Config)
|
||||
Compressor func() *compression.Config
|
||||
SetReportErrorFunc func(f func(string, error))
|
||||
|
||||
Get func(common.GetPrm) (common.GetRes, error)
|
||||
|
@ -45,6 +46,10 @@ func WithSetCompressor(f func(*compression.Config)) Option {
|
|||
return func(c *cfg) { c.overrides.SetCompressor = f }
|
||||
}
|
||||
|
||||
func WithCompressor(f func() *compression.Config) Option {
|
||||
return func(c *cfg) { c.overrides.Compressor = f }
|
||||
}
|
||||
|
||||
func WithReportErrorFunc(f func(func(string, error))) Option {
|
||||
return func(c *cfg) { c.overrides.SetReportErrorFunc = f }
|
||||
}
|
||||
|
|
|
@ -128,6 +128,19 @@ func (s *TestStore) SetCompressor(cc *compression.Config) {
|
|||
}
|
||||
}
|
||||
|
||||
func (s *TestStore) Compressor() *compression.Config {
|
||||
s.mu.RLock()
|
||||
defer s.mu.RUnlock()
|
||||
switch {
|
||||
case s.overrides.Compressor != nil:
|
||||
return s.overrides.Compressor()
|
||||
case s.st != nil:
|
||||
return s.st.Compressor()
|
||||
default:
|
||||
panic("unexpected storage call: Compressor()")
|
||||
}
|
||||
}
|
||||
|
||||
func (s *TestStore) SetReportErrorFunc(f func(string, error)) {
|
||||
s.mu.RLock()
|
||||
defer s.mu.RUnlock()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue