[#1121] metrics: Change mode of shard components
Signed-off-by: Alexander Chuprov <a.chuprov@yadro.com>
parent
b6240f569b
commit
20fc9eb5dc
|
@ -171,8 +171,8 @@ func (m *writeCacheMetrics) SetEstimateSize(db, fstree uint64) {
|
|||
m.metrics.SetEstimateSize(m.shardID, m.path, writecache.StorageTypeFSTree.String(), fstree)
|
||||
}
|
||||
|
||||
func (m *writeCacheMetrics) SetMode(mode mode.Mode) {
|
||||
m.metrics.SetMode(m.shardID, mode.String())
|
||||
func (m *writeCacheMetrics) SetMode(mod mode.ComponentMode) {
|
||||
m.metrics.SetMode(m.shardID, mod.String())
|
||||
}
|
||||
|
||||
func (m *writeCacheMetrics) SetActualCounters(db, fstree uint64) {
|
||||
|
|
|
@ -38,16 +38,16 @@ var (
|
|||
)
|
||||
|
||||
// Open boltDB instance for metabase.
|
||||
func (db *DB) Open(_ context.Context, mode mode.Mode) error {
|
||||
func (db *DB) Open(_ context.Context, m mode.Mode) error {
|
||||
db.modeMtx.Lock()
|
||||
defer db.modeMtx.Unlock()
|
||||
db.mode = mode
|
||||
db.metrics.SetMode(mode)
|
||||
db.mode = m
|
||||
db.metrics.SetMode(mode.GetComponentMode(m))
|
||||
|
||||
if mode.NoMetabase() {
|
||||
if m.NoMetabase() {
|
||||
return nil
|
||||
}
|
||||
return db.openDB(mode)
|
||||
return db.openDB(m)
|
||||
}
|
||||
|
||||
func (db *DB) openDB(mode mode.Mode) error {
|
||||
|
@ -239,15 +239,15 @@ func (db *DB) Reload(opts ...Option) (bool, error) {
|
|||
return false, err
|
||||
}
|
||||
|
||||
db.mode = mode.Degraded
|
||||
db.metrics.SetMode(mode.Degraded)
|
||||
db.mode = mode.Disabled
|
||||
db.metrics.SetMode(mode.ComponentDisabled)
|
||||
db.info.Path = c.info.Path
|
||||
if err := db.openBolt(); err != nil {
|
||||
return false, metaerr.Wrap(fmt.Errorf("%w: %v", ErrDegradedMode, err))
|
||||
}
|
||||
|
||||
db.mode = mode.ReadWrite
|
||||
db.metrics.SetMode(mode.ReadWrite)
|
||||
db.metrics.SetMode(mode.ComponentReadWrite)
|
||||
return true, nil
|
||||
}
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ import (
|
|||
type Metrics interface {
|
||||
SetParentID(parentID string)
|
||||
|
||||
SetMode(m mode.Mode)
|
||||
SetMode(m mode.ComponentMode)
|
||||
Close()
|
||||
|
||||
AddMethodDuration(method string, d time.Duration, success bool)
|
||||
|
@ -18,6 +18,6 @@ type Metrics interface {
|
|||
type noopMetrics struct{}
|
||||
|
||||
func (m *noopMetrics) SetParentID(string) {}
|
||||
func (m *noopMetrics) SetMode(mode.Mode) {}
|
||||
func (m *noopMetrics) SetMode(mode.ComponentMode) {}
|
||||
func (m *noopMetrics) Close() {}
|
||||
func (m *noopMetrics) AddMethodDuration(string, time.Duration, bool) {}
|
||||
|
|
|
@ -35,6 +35,6 @@ func (db *DB) SetMode(m mode.Mode) error {
|
|||
}
|
||||
|
||||
db.mode = m
|
||||
db.metrics.SetMode(m)
|
||||
db.metrics.SetMode(mode.GetComponentMode(m))
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -69,7 +69,7 @@ func (db *DB) SetShardID(id []byte, mode metamode.Mode) error {
|
|||
|
||||
err := db.writeShardID(id)
|
||||
if err == nil {
|
||||
db.metrics.SetMode(mode)
|
||||
db.metrics.SetMode(metamode.GetComponentMode(mode))
|
||||
}
|
||||
|
||||
if cErr := db.close(); cErr != nil {
|
||||
|
|
|
@ -26,7 +26,7 @@ func (m *metabaseMetrics) SetParentID(parentID string) {
|
|||
m.shardID = parentID
|
||||
}
|
||||
|
||||
func (m *metabaseMetrics) SetMode(mode mode.Mode) {
|
||||
func (m *metabaseMetrics) SetMode(mode mode.ComponentMode) {
|
||||
m.m.SetMode(m.shardID, m.path, mode.String())
|
||||
}
|
||||
|
||||
|
|
|
@ -24,8 +24,8 @@ func (m *piloramaMetrics) SetParentID(id string) {
|
|||
m.shardID = id
|
||||
}
|
||||
|
||||
func (m *piloramaMetrics) SetMode(mode mode.Mode) {
|
||||
m.m.SetMode(m.shardID, mode)
|
||||
func (m *piloramaMetrics) SetMode(mod mode.ComponentMode) {
|
||||
m.m.SetMode(m.shardID, mod)
|
||||
}
|
||||
|
||||
func (m *piloramaMetrics) Close() {
|
||||
|
|
|
@ -109,7 +109,7 @@ func (t *boltForest) SetMode(m mode.Mode) error {
|
|||
}
|
||||
|
||||
t.mode = m
|
||||
t.metrics.SetMode(m)
|
||||
t.metrics.SetMode(mode.GetComponentMode(m))
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -123,8 +123,8 @@ func (t *boltForest) Open(_ context.Context, mode mode.Mode) error {
|
|||
return t.openBolt(mode)
|
||||
}
|
||||
|
||||
func (t *boltForest) openBolt(mode mode.Mode) error {
|
||||
readOnly := mode.ReadOnly()
|
||||
func (t *boltForest) openBolt(m mode.Mode) error {
|
||||
readOnly := m.ReadOnly()
|
||||
err := util.MkdirAllX(filepath.Dir(t.path), t.perm)
|
||||
if err != nil {
|
||||
return metaerr.Wrap(fmt.Errorf("can't create dir %s for the pilorama: %w", t.path, err))
|
||||
|
@ -143,7 +143,7 @@ func (t *boltForest) openBolt(mode mode.Mode) error {
|
|||
|
||||
t.db.MaxBatchSize = t.maxBatchSize
|
||||
t.db.MaxBatchDelay = t.maxBatchDelay
|
||||
t.metrics.SetMode(mode)
|
||||
t.metrics.SetMode(mode.GetComponentMode(m))
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ import (
|
|||
type Metrics interface {
|
||||
SetParentID(id string)
|
||||
|
||||
SetMode(m mode.Mode)
|
||||
SetMode(m mode.ComponentMode)
|
||||
Close()
|
||||
|
||||
AddMethodDuration(method string, d time.Duration, success bool)
|
||||
|
@ -18,6 +18,6 @@ type Metrics interface {
|
|||
type noopMetrics struct{}
|
||||
|
||||
func (m *noopMetrics) SetParentID(string) {}
|
||||
func (m *noopMetrics) SetMode(mode.Mode) {}
|
||||
func (m *noopMetrics) SetMode(mode.ComponentMode) {}
|
||||
func (m *noopMetrics) Close() {}
|
||||
func (m *noopMetrics) AddMethodDuration(string, time.Duration, bool) {}
|
||||
|
|
|
@ -37,7 +37,7 @@ func (s *Shard) handleMetabaseFailure(stage string, err error) error {
|
|||
|
||||
err = s.SetMode(mode.DegradedReadOnly)
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not switch to mode %s", mode.DegradedReadOnly)
|
||||
return fmt.Errorf("could not switch to mode %s", mode.Mode(mode.DegradedReadOnly))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -29,6 +29,22 @@ const (
|
|||
DegradedReadOnly Mode = Degraded | ReadOnly
|
||||
)
|
||||
|
||||
// ComponentMode represents the enumeration of Shard component work modes.
|
||||
type ComponentMode uint32
|
||||
|
||||
const (
|
||||
// ComponentReadWrite ReadWrite is a Mode value for component that is available
|
||||
// for read and write operations. Default component mode.
|
||||
ComponentReadWrite ComponentMode = 0
|
||||
|
||||
// ComponentReadOnly ReadOnly is a Mode value for component that does not
|
||||
// accept write operation but is readable.
|
||||
ComponentReadOnly ComponentMode = 0b001
|
||||
|
||||
// ComponentDisabled Disabled mode is a mode where a component is disabled.
|
||||
ComponentDisabled ComponentMode = math.MaxUint32
|
||||
)
|
||||
|
||||
func (m Mode) String() string {
|
||||
switch m {
|
||||
default:
|
||||
|
@ -46,6 +62,19 @@ func (m Mode) String() string {
|
|||
}
|
||||
}
|
||||
|
||||
func (m ComponentMode) String() string {
|
||||
switch m {
|
||||
default:
|
||||
return "UNDEFINED"
|
||||
case ComponentReadWrite:
|
||||
return "READ_WRITE"
|
||||
case ComponentReadOnly:
|
||||
return "READ_ONLY"
|
||||
case ComponentDisabled:
|
||||
return "CLOSED"
|
||||
}
|
||||
}
|
||||
|
||||
// NoMetabase returns true iff m is operating without the metabase.
|
||||
func (m Mode) NoMetabase() bool {
|
||||
return m&Degraded != 0
|
||||
|
@ -56,6 +85,26 @@ func (m Mode) ReadOnly() bool {
|
|||
return m&ReadOnly != 0
|
||||
}
|
||||
|
||||
// ReadOnly returns true iff m prohibits modifying operations with shard.
|
||||
func (m ComponentMode) ReadOnly() bool {
|
||||
return m&ComponentReadOnly != 0
|
||||
}
|
||||
|
||||
func (m Mode) Disabled() bool {
|
||||
return m == Disabled
|
||||
}
|
||||
|
||||
func (m ComponentMode) Disabled() bool {
|
||||
return m == ComponentDisabled
|
||||
}
|
||||
|
||||
// GetComponentMode maps a ShardMode to a ComponentMode.
|
||||
func GetComponentMode(m Mode) ComponentMode {
|
||||
if m.NoMetabase() {
|
||||
return ComponentDisabled
|
||||
}
|
||||
if m.ReadOnly() {
|
||||
return ComponentReadOnly
|
||||
}
|
||||
return ComponentReadWrite
|
||||
}
|
||||
|
|
|
@ -112,7 +112,7 @@ func (c *cache) Open(_ context.Context, mode mode.Mode) error {
|
|||
|
||||
// Init runs necessary services.
|
||||
func (c *cache) Init() error {
|
||||
c.metrics.SetMode(c.mode)
|
||||
c.metrics.SetMode(mode.GetComponentMode(c.mode))
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
c.cancel = cancel
|
||||
c.runFlushLoop(ctx)
|
||||
|
|
|
@ -294,7 +294,7 @@ func (c *cache) Flush(ctx context.Context, ignoreErrors, seal bool) error {
|
|||
if err := c.setMode(ctx, m, ignoreErrors); err != nil {
|
||||
return err
|
||||
}
|
||||
c.metrics.SetMode(m)
|
||||
c.metrics.SetMode(mode.GetComponentMode(m))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ type Metrics interface {
|
|||
Evict(st StorageType)
|
||||
|
||||
SetEstimateSize(db, fstree uint64)
|
||||
SetMode(m mode.Mode)
|
||||
SetMode(m mode.ComponentMode)
|
||||
SetActualCounters(db, fstree uint64)
|
||||
SetPath(path string)
|
||||
Close()
|
||||
|
@ -49,7 +49,7 @@ func (metricsStub) Put(time.Duration, bool, StorageType) {}
|
|||
|
||||
func (metricsStub) SetEstimateSize(uint64, uint64) {}
|
||||
|
||||
func (metricsStub) SetMode(mode.Mode) {}
|
||||
func (metricsStub) SetMode(mode.ComponentMode) {}
|
||||
|
||||
func (metricsStub) SetActualCounters(uint64, uint64) {}
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ func (c *cache) SetMode(m mode.Mode) error {
|
|||
|
||||
err := c.setMode(ctx, m, true)
|
||||
if err == nil {
|
||||
c.metrics.SetMode(m)
|
||||
c.metrics.SetMode(mode.GetComponentMode(m))
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ func (c *cache) Seal(ctx context.Context, ignoreErrors bool) error {
|
|||
// flush will be done by setMode
|
||||
err := c.setMode(ctx, mode.DegradedReadOnly, ignoreErrors)
|
||||
if err == nil {
|
||||
c.metrics.SetMode(mode.DegradedReadOnly)
|
||||
c.metrics.SetMode(mode.ComponentDisabled)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ import (
|
|||
)
|
||||
|
||||
type PiloramaMetrics interface {
|
||||
SetMode(shardID string, m mode.Mode)
|
||||
SetMode(shardID string, m mode.ComponentMode)
|
||||
Close(shardID string)
|
||||
|
||||
AddMethodDuration(shardID string, method string, d time.Duration, success bool)
|
||||
|
@ -33,7 +33,7 @@ type piloramaMetrics struct {
|
|||
reqDuration *prometheus.HistogramVec
|
||||
}
|
||||
|
||||
func (m *piloramaMetrics) SetMode(shardID string, mode mode.Mode) {
|
||||
func (m *piloramaMetrics) SetMode(shardID string, mode mode.ComponentMode) {
|
||||
m.mode.SetMode(shardID, mode.String())
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue