feat: enforce tiered storage reservations

This commit is contained in:
2026-08-31 09:48:04 +00:00
parent 583b539f86
commit 611100f67c
12 changed files with 780 additions and 6 deletions
+14
View File
@@ -25,6 +25,8 @@ type Options struct {
DataDir string
BusyTimeout time.Duration
SegmentTargetSize uint64
QuotaLimits QuotaLimits
FreeSpaceProbe FreeSpaceProbe
FaultInjector FaultInjector
}
@@ -33,6 +35,8 @@ type Store struct {
unlock func() error
dataDir string
segmentTarget uint64
quotaLimits QuotaLimits
freeSpaceProbe FreeSpaceProbe
faultInjector FaultInjector
activeSegments map[[16]byte]*activeSegment
mu sync.Mutex
@@ -52,6 +56,15 @@ func Open(ctx context.Context, options Options) (*Store, error) {
if options.SegmentTargetSize > DefaultSegmentLimit {
return nil, fmt.Errorf("segment target exceeds hard record limit")
}
if options.QuotaLimits == (QuotaLimits{}) {
options.QuotaLimits = DefaultQuotaLimits()
}
if err := options.QuotaLimits.Validate(); err != nil {
return nil, err
}
if options.FreeSpaceProbe == nil {
options.FreeSpaceProbe = FreeSpaceProbeFunc(filesystemFreeBytes)
}
if err := ensurePrivateDirectory(options.DataDir); err != nil {
return nil, err
}
@@ -88,6 +101,7 @@ func Open(ctx context.Context, options Options) (*Store, error) {
db.SetMaxIdleConns(1)
store := &Store{
db: db, unlock: unlock, dataDir: options.DataDir, segmentTarget: options.SegmentTargetSize,
quotaLimits: options.QuotaLimits, freeSpaceProbe: options.FreeSpaceProbe,
faultInjector: options.FaultInjector, activeSegments: make(map[[16]byte]*activeSegment),
}
if err := db.PingContext(ctx); err != nil {