Dmitrii Stepanov
36efccd862
All checks were successful
DCO action / DCO (pull_request) Successful in 1m23s
Vulncheck / Vulncheck (pull_request) Successful in 1m48s
Tests and linters / Run gofumpt (pull_request) Successful in 1m54s
Build / Build Components (1.22) (pull_request) Successful in 2m23s
Build / Build Components (1.21) (pull_request) Successful in 2m28s
Pre-commit hooks / Pre-commit (pull_request) Successful in 2m53s
Tests and linters / Tests (1.21) (pull_request) Successful in 2m53s
Tests and linters / Staticcheck (pull_request) Successful in 2m48s
Tests and linters / Tests (1.22) (pull_request) Successful in 2m54s
Tests and linters / Tests with -race (pull_request) Successful in 2m58s
Tests and linters / Lint (pull_request) Successful in 3m24s
Tests and linters / gopls check (pull_request) Successful in 3m36s
Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
92 lines
2.5 KiB
Go
92 lines
2.5 KiB
Go
package shard
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/writecache"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-observability/tracing"
|
|
"go.opentelemetry.io/otel/attribute"
|
|
"go.opentelemetry.io/otel/trace"
|
|
)
|
|
|
|
// FlushWriteCachePrm represents parameters of a `FlushWriteCache` operation.
|
|
type FlushWriteCachePrm struct {
|
|
ignoreErrors bool
|
|
seal bool
|
|
}
|
|
|
|
// SetIgnoreErrors sets the flag to ignore read-errors during flush.
|
|
func (p *FlushWriteCachePrm) SetIgnoreErrors(ignore bool) {
|
|
p.ignoreErrors = ignore
|
|
}
|
|
|
|
// SetSeal sets the flag to left writecache in read-only mode after flush.
|
|
func (p *FlushWriteCachePrm) SetSeal(v bool) {
|
|
p.seal = v
|
|
}
|
|
|
|
// errWriteCacheDisabled is returned when an operation on write-cache is performed,
|
|
// but write-cache is disabled.
|
|
var errWriteCacheDisabled = errors.New("write-cache is disabled")
|
|
|
|
// FlushWriteCache flushes all data from the write-cache.
|
|
func (s *Shard) FlushWriteCache(ctx context.Context, p FlushWriteCachePrm) error {
|
|
ctx, span := tracing.StartSpanFromContext(ctx, "Shard.FlushWriteCache",
|
|
trace.WithAttributes(
|
|
attribute.String("shard_id", s.ID().String()),
|
|
attribute.Bool("ignore_errors", p.ignoreErrors),
|
|
attribute.Bool("seal", p.seal),
|
|
))
|
|
defer span.End()
|
|
|
|
if !s.hasWriteCache() {
|
|
return errWriteCacheDisabled
|
|
}
|
|
|
|
s.m.RLock()
|
|
defer s.m.RUnlock()
|
|
|
|
// To write data to the blobstor we need to write to the blobstor and the metabase.
|
|
if s.info.Mode.ReadOnly() {
|
|
return ErrReadOnlyMode
|
|
}
|
|
if s.info.Mode.NoMetabase() {
|
|
return ErrDegradedMode
|
|
}
|
|
|
|
return s.writeCache.Flush(ctx, p.ignoreErrors, p.seal)
|
|
}
|
|
|
|
type SealWriteCachePrm struct {
|
|
IgnoreErrors bool
|
|
RestoreMode bool
|
|
Shrink bool
|
|
}
|
|
|
|
// SealWriteCache flushes all data from the write-cache and moves it to degraded read only mode.
|
|
func (s *Shard) SealWriteCache(ctx context.Context, p SealWriteCachePrm) error {
|
|
ctx, span := tracing.StartSpanFromContext(ctx, "Shard.SealWriteCache",
|
|
trace.WithAttributes(
|
|
attribute.String("shard_id", s.ID().String()),
|
|
attribute.Bool("ignore_errors", p.IgnoreErrors),
|
|
attribute.Bool("restore_mode", p.RestoreMode),
|
|
))
|
|
defer span.End()
|
|
|
|
if !s.hasWriteCache() {
|
|
return errWriteCacheDisabled
|
|
}
|
|
|
|
s.m.RLock()
|
|
defer s.m.RUnlock()
|
|
|
|
if s.info.Mode.ReadOnly() {
|
|
return ErrReadOnlyMode
|
|
}
|
|
if s.info.Mode.NoMetabase() {
|
|
return ErrDegradedMode
|
|
}
|
|
|
|
return s.writeCache.Seal(ctx, writecache.SealPrm{IgnoreErrors: p.IgnoreErrors, RestoreMode: p.RestoreMode, Shrink: p.Shrink})
|
|
}
|