counters

package
v0.39.0-cdp-engine Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2025 License: AGPL-3.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrIncorrectValue = errors.New("incorrect value")
)

ErrIncorrectValue indicates that a processed value is lower or equal than current value.

Functions

This section is empty.

Types

type PersistentStrictMonotonicCounter added in v0.33.30

type PersistentStrictMonotonicCounter struct {
	// contains filtered or unexported fields
}

PersistentStrictMonotonicCounter represents the consumer progress with strict monotonic counter.

func NewPersistentStrictMonotonicCounter added in v0.33.30

func NewPersistentStrictMonotonicCounter(consumerProgress storage.ConsumerProgress) (*PersistentStrictMonotonicCounter, error)

NewPersistentStrictMonotonicCounter creates a new PersistentStrictMonotonicCounter. The consumer progress and associated db entry must not be accessed outside of calls to the returned object, otherwise the state may become inconsistent.

No errors are expected during normal operation.

func (*PersistentStrictMonotonicCounter) Set added in v0.33.30

func (m *PersistentStrictMonotonicCounter) Set(processed uint64) error

Set sets the processed index, ensuring it is strictly monotonically increasing.

Expected errors during normal operation:

  • codes.ErrIncorrectValue - if stored value is >= processed (requirement of strict monotonic increase is violated).
  • generic error in case of unexpected failure from the database layer or encoding failure.

func (*PersistentStrictMonotonicCounter) Value added in v0.33.30

Value loads the current stored index.

No errors are expected during normal operation.

type StrictMonotonicCounter added in v0.39.0

type StrictMonotonicCounter struct {
	// contains filtered or unexported fields
}

StrictMonotonicCounter is a helper struct which implements a strict monotonic counter. StrictMonotonicCounter is implemented using atomic operations and doesn't allow to set a value which is lower or equal to the already stored one. The counter is implemented solely with non-blocking atomic operations for concurrency safety.

func NewMonotonicCounter added in v0.39.0

func NewMonotonicCounter(initialValue uint64) StrictMonotonicCounter

NewMonotonicCounter creates new counter with initial value

func (*StrictMonotonicCounter) Increment added in v0.39.0

func (c *StrictMonotonicCounter) Increment() uint64

Increment atomically increments counter and returns updated value

func (*StrictMonotonicCounter) Set added in v0.39.0

func (c *StrictMonotonicCounter) Set(newValue uint64) bool

Set updates value of counter if and only if it's strictly larger than value which is already stored. Returns true if update was successful or false if stored value is larger.

func (*StrictMonotonicCounter) Value added in v0.39.0

func (c *StrictMonotonicCounter) Value() uint64

Value returns value which is stored in atomic variable

Jump to

Keyboard shortcuts

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