[#373] local storage: Pass parent ID

This is required to add shard ID as metric label.

Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
Dmitrii Stepanov 2023-06-07 14:39:03 +03:00
parent d5aaec1107
commit d8ecc69d00
16 changed files with 47 additions and 0 deletions

View file

@ -256,3 +256,7 @@ func (b *Blobovniczas) SetCompressor(cc *compression.Config) {
func (b *Blobovniczas) SetReportErrorFunc(f func(string, error)) {
b.reportError = f
}
func (b *Blobovniczas) SetParentID(parentID string) {
b.metrics.SetParentID(parentID)
}

View file

@ -9,6 +9,8 @@ import (
type Metrics interface {
BlobovnicaMetrics(path string) blobovnicza.Metrics
SetParentID(parentID string)
SetMode(readOnly bool)
Close()
@ -25,6 +27,7 @@ type noopMetrics struct{}
func (m *noopMetrics) BlobovnicaMetrics(string) blobovnicza.Metrics {
return &blobovnicza.NoopMetrics{}
}
func (m *noopMetrics) SetParentID(string) {}
func (m *noopMetrics) SetMode(bool) {}
func (m *noopMetrics) Close() {}
func (m *noopMetrics) Delete(time.Duration, bool, bool) {}

View file

@ -72,6 +72,13 @@ func (b *BlobStor) SetLogger(l *logger.Logger) {
b.log = l
}
func (b *BlobStor) SetParentID(parentID string) {
b.metrics.SetParentID(parentID)
for _, ss := range b.storage {
ss.Storage.SetParentID(parentID)
}
}
// WithStorages provides sub-blobstors.
func WithStorages(st []SubStorage) Option {
return func(c *cfg) {

View file

@ -19,6 +19,7 @@ type Storage interface {
// SetReportErrorFunc allows to provide a function to be called on disk errors.
// This function MUST be called before Open.
SetReportErrorFunc(f func(string, error))
SetParentID(parentID string)
Get(context.Context, GetPrm) (GetRes, error)
GetRange(context.Context, GetRangePrm) (GetRangeRes, error)

View file

@ -554,3 +554,7 @@ func (t *FSTree) SetCompressor(cc *compression.Config) {
func (t *FSTree) SetReportErrorFunc(_ func(string, error)) {
// Do nothing, FSTree can encounter only one error which is returned.
}
func (t *FSTree) SetParentID(parentID string) {
t.metrics.SetParentID(parentID)
}

View file

@ -3,6 +3,8 @@ package fstree
import "time"
type Metrics interface {
SetParentID(parentID string)
SetMode(readOnly bool)
Close()
@ -16,6 +18,7 @@ type Metrics interface {
type noopMetrics struct{}
func (m *noopMetrics) SetParentID(string) {}
func (m *noopMetrics) SetMode(bool) {}
func (m *noopMetrics) Close() {}
func (m *noopMetrics) Iterate(time.Duration, bool) {}

View file

@ -13,3 +13,4 @@ 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) SetReportErrorFunc(f func(string, error)) { s.reportError = f }
func (s *memstoreImpl) SetParentID(string) {}

View file

@ -3,6 +3,7 @@ package blobstor
import "time"
type Metrics interface {
SetParentID(parentID string)
SetMode(readOnly bool)
Close()
@ -16,6 +17,7 @@ type Metrics interface {
type noopMetrics struct{}
func (m *noopMetrics) SetParentID(string) {}
func (m *noopMetrics) SetMode(bool) {}
func (m *noopMetrics) Close() {}
func (m *noopMetrics) Delete(time.Duration, bool, bool) {}

View file

@ -214,3 +214,5 @@ func (s *TestStore) Iterate(ctx context.Context, req common.IteratePrm) (common.
panic(fmt.Sprintf("unexpected storage call: Iterate(%+v)", req))
}
}
func (s *TestStore) SetParentID(string) {}

View file

@ -294,6 +294,11 @@ func (db *DB) SetLogger(l *logger.Logger) {
db.log = l
}
// SetParentID sets parent ID to nested components. It is used after the shard ID was generated to use it in logs.
func (db *DB) SetParentID(parentID string) {
db.metrics.SetParentID(parentID)
}
// WithLogger returns option to set logger of DB.
func WithLogger(l *logger.Logger) Option {
return func(c *cfg) {

View file

@ -7,6 +7,8 @@ import (
)
type Metrics interface {
SetParentID(parentID string)
SetMode(m mode.Mode)
Close()
@ -15,6 +17,7 @@ type Metrics interface {
type noopMetrics struct{}
func (m *noopMetrics) SetParentID(string) {}
func (m *noopMetrics) SetMode(mode.Mode) {}
func (m *noopMetrics) Close() {}
func (m *noopMetrics) AddMethodDuration(string, time.Duration, bool) {}

View file

@ -158,6 +158,10 @@ func (t *boltForest) Close() error {
return err
}
func (t *boltForest) SetParentID(id string) {
t.metrics.SetParentID(id)
}
// TreeMove implements the Forest interface.
func (t *boltForest) TreeMove(ctx context.Context, d CIDDescriptor, treeID string, m *Move) (*Move, error) {
_, span := tracing.StartSpanFromContext(ctx, "boltForest.TreeMove",

View file

@ -119,6 +119,7 @@ func (f *memoryForest) SetMode(mode.Mode) error {
func (f *memoryForest) Close() error {
return nil
}
func (f *memoryForest) SetParentID(string) {}
// TreeGetByPath implements the Forest interface.
func (f *memoryForest) TreeGetByPath(_ context.Context, cid cid.ID, treeID string, attr string, path []string, latest bool) ([]Node, error) {

View file

@ -61,6 +61,7 @@ type ForestStorage interface {
Open(bool) error
Close() error
SetMode(m mode.Mode) error
SetParentID(id string)
Forest
}

View file

@ -7,6 +7,8 @@ import (
)
type Metrics interface {
SetParentID(id string)
SetMode(m mode.Mode)
Close()
@ -15,6 +17,7 @@ type Metrics interface {
type noopMetrics struct{}
func (m *noopMetrics) SetParentID(string) {}
func (m *noopMetrics) SetMode(mode.Mode) {}
func (m *noopMetrics) Close() {}
func (m *noopMetrics) AddMethodDuration(string, time.Duration, bool) {}

View file

@ -55,6 +55,9 @@ func (s *Shard) UpdateID() (err error) {
if s.hasWriteCache() {
s.writeCache.SetLogger(s.log)
}
s.metaBase.SetParentID(s.info.ID.String())
s.blobStor.SetParentID(s.info.ID.String())
s.pilorama.SetParentID(s.info.ID.String())
if len(id) != 0 {
return nil