feat: enforce tiered storage reservations
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user