[#222] Use write cache options in storage app

Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
Alex Vanin 2020-12-01 12:26:19 +03:00
parent 69ba295077
commit 92c95150cd
3 changed files with 31 additions and 4 deletions

View file

@ -117,6 +117,7 @@ const (
cfgShardUseWriteCache = "use_write_cache" cfgShardUseWriteCache = "use_write_cache"
cfgBlobStorSection = "blobstor" cfgBlobStorSection = "blobstor"
cfgWriteCacheSection = "writecache"
cfgBlobStorCompress = "compress" cfgBlobStorCompress = "compress"
cfgBlobStorShallowDepth = "shallow_depth" cfgBlobStorShallowDepth = "shallow_depth"
cfgBlobStorTreePath = "path" cfgBlobStorTreePath = "path"
@ -442,6 +443,15 @@ func initShardOptions(c *cfg) {
configPath(prefix, cfgShardUseWriteCache), configPath(prefix, cfgShardUseWriteCache),
) )
writeCachePrefix := configPath(prefix, cfgWriteCacheSection)
writeCachePath := c.viper.GetString(
configPath(writeCachePrefix, cfgBlobStorTreePath),
)
if useCache && writeCachePath == "" {
break
}
blobPrefix := configPath(prefix, cfgBlobStorSection) blobPrefix := configPath(prefix, cfgBlobStorSection)
blobPath := c.viper.GetString( blobPath := c.viper.GetString(
@ -517,10 +527,14 @@ func initShardOptions(c *cfg) {
meta.WithPermissions(metaPerm), meta.WithPermissions(metaPerm),
), ),
shard.WithWriteCache(useCache), shard.WithWriteCache(useCache),
shard.WithWriteCacheOptions(
blobstor.WithTreeRootPath(writeCachePath),
),
}) })
c.log.Info("storage shard options", c.log.Info("storage shard options",
zap.Bool("with write cache", useCache), zap.Bool("with write cache", useCache),
zap.String("with write cache path", writeCachePath),
zap.String("BLOB path", blobPath), zap.String("BLOB path", blobPath),
zap.Stringer("BLOB permissions", blobPerm), zap.Stringer("BLOB permissions", blobPerm),
zap.Bool("BLOB compress", compressObjects), zap.Bool("BLOB compress", compressObjects),

View file

@ -16,6 +16,9 @@ type Info struct {
// Information about the BLOB storage. // Information about the BLOB storage.
BlobStorInfo blobstor.Info BlobStorInfo blobstor.Info
// Information about the Write Cache.
WriteCacheInfo blobstor.Info
// Weight parameters of the shard. // Weight parameters of the shard.
WeightValues WeightValues WeightValues WeightValues
} }

View file

@ -32,6 +32,8 @@ type cfg struct {
metaOpts []meta.Option metaOpts []meta.Option
writeCacheOpts []blobstor.Option
log *logger.Logger log *logger.Logger
} }
@ -51,10 +53,11 @@ func New(opts ...Option) *Shard {
if c.useWriteCache { if c.useWriteCache {
writeCache = blobstor.New( writeCache = blobstor.New(
append(c.blobOpts, append(
c.writeCacheOpts,
blobstor.WithBlobovniczaShallowDepth(0), blobstor.WithBlobovniczaShallowDepth(0),
blobstor.WithBlobovniczaShallowWidth(1), blobstor.WithBlobovniczaShallowWidth(1))...,
blobstor.WithLogger(c.log), )...,
// ? what about path
) )
} }
@ -88,6 +91,13 @@ func WithMetaBaseOptions(opts ...meta.Option) Option {
} }
} }
// WithMetaBaseOptions returns option to set internal metabase options.
func WithWriteCacheOptions(opts ...blobstor.Option) Option {
return func(c *cfg) {
c.writeCacheOpts = opts
}
}
// WithLogger returns option to set Shard's logger. // WithLogger returns option to set Shard's logger.
func WithLogger(l *logger.Logger) Option { func WithLogger(l *logger.Logger) Option {
return func(c *cfg) { return func(c *cfg) {