protector

package
v0.10.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 26, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package protector provides a set of protectors that stop the query services when the resource usage exceeds the limit.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Memory

type Memory interface {
	AvailableBytes() int64
	GetLimit() uint64
	AcquireResource(ctx context.Context, size uint64) error
	// ShouldCache returns true if the file size is smaller than the threshold.
	ShouldCache(fileSize int64) bool
	run.PreRunner
	run.Config
	run.Service
	// State returns the current memory pressure state.
	State() State
}

Memory is an interface for monitoring and limiting memory usage to prevent OOM.

func NewMemory

func NewMemory(omr observability.MetricsRegistry) Memory

NewMemory creates a new Memory protector.

type Nop added in v0.9.0

type Nop struct{}

Nop is a no-op implementation of Memory interface for testing.

func (Nop) AcquireResource added in v0.9.0

func (Nop) AcquireResource(_ context.Context, _ uint64) error

AcquireResource always succeeds.

func (Nop) AvailableBytes added in v0.9.0

func (Nop) AvailableBytes() int64

AvailableBytes always returns -1 (unlimited).

func (Nop) FlagSet added in v0.9.0

func (Nop) FlagSet() *run.FlagSet

FlagSet returns an empty flag set.

func (Nop) GetLimit added in v0.9.0

func (Nop) GetLimit() uint64

GetLimit always returns 0 (no limit).

func (Nop) GracefulStop added in v0.9.0

func (Nop) GracefulStop()

GracefulStop does nothing.

func (Nop) Name added in v0.9.0

func (Nop) Name() string

Name returns the protector name.

func (Nop) PreRun added in v0.9.0

func (Nop) PreRun(context.Context) error

PreRun does nothing.

func (Nop) Serve added in v0.9.0

func (Nop) Serve() run.StopNotify

Serve returns a closed channel.

func (Nop) ShouldCache added in v0.9.0

func (Nop) ShouldCache(int64) bool

ShouldCache always returns false.

func (Nop) State added in v0.9.0

func (n Nop) State() State

State implements Memory.

func (Nop) Validate added in v0.9.0

func (Nop) Validate() error

Validate always succeeds.

type State added in v0.9.0

type State int

State represents memory pressure levels for load shedding.

const (
	// StateLow indicates normal memory usage, accept all requests.
	StateLow State = iota
	// StateHigh indicates high memory pressure, reject new requests.
	StateHigh
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL