2022-09-21 10:43:31 +00:00
|
|
|
package shard
|
|
|
|
|
|
|
|
import (
|
2023-04-12 14:01:29 +00:00
|
|
|
"context"
|
2022-09-21 10:43:31 +00:00
|
|
|
"errors"
|
2023-04-12 14:01:29 +00:00
|
|
|
|
2023-05-31 09:24:04 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-observability/tracing"
|
2023-04-12 14:01:29 +00:00
|
|
|
"go.opentelemetry.io/otel/attribute"
|
|
|
|
"go.opentelemetry.io/otel/trace"
|
2022-09-21 10:43:31 +00:00
|
|
|
)
|
|
|
|
|
2022-09-26 08:54:21 +00:00
|
|
|
// FlushWriteCachePrm represents parameters of a `FlushWriteCache` operation.
|
|
|
|
type FlushWriteCachePrm struct {
|
|
|
|
ignoreErrors bool
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetIgnoreErrors sets the flag to ignore read-errors during flush.
|
|
|
|
func (p *FlushWriteCachePrm) SetIgnoreErrors(ignore bool) {
|
|
|
|
p.ignoreErrors = ignore
|
|
|
|
}
|
|
|
|
|
2022-09-21 10:43:31 +00:00
|
|
|
// errWriteCacheDisabled is returned when an operation on write-cache is performed,
|
|
|
|
// but write-cache is disabled.
|
|
|
|
var errWriteCacheDisabled = errors.New("write-cache is disabled")
|
|
|
|
|
2022-11-08 12:20:58 +00:00
|
|
|
// FlushWriteCache flushes all data from the write-cache.
|
2023-04-12 14:01:29 +00:00
|
|
|
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),
|
|
|
|
))
|
|
|
|
defer span.End()
|
|
|
|
|
2022-09-21 10:43:31 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2023-04-12 14:01:29 +00:00
|
|
|
return s.writeCache.Flush(ctx, p.ignoreErrors)
|
2022-09-21 10:43:31 +00:00
|
|
|
}
|