counters

package
v0.35.17-crescendo-pre... Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2024 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, defaultIndex uint64) (*PersistentStrictMonotonicCounter, error)

NewPersistentStrictMonotonicCounter creates a new PersistentStrictMonotonicCounter which inserts the default processed index to the storage layer and creates new counter with defaultIndex value. 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 larger than processed.
  • 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 StrictMonotonousCounter

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

StrictMonotonousCounter is a helper struct which implements a strict monotonous counter. StrictMonotonousCounter 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 NewMonotonousCounter

func NewMonotonousCounter(initialValue uint64) StrictMonotonousCounter

NewMonotonousCounter creates new counter with initial value

func (*StrictMonotonousCounter) Increment added in v0.33.30

func (c *StrictMonotonousCounter) Increment() uint64

Increment atomically increments counter and returns updated value

func (*StrictMonotonousCounter) Set

func (c *StrictMonotonousCounter) 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 (*StrictMonotonousCounter) Value

func (c *StrictMonotonousCounter) 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