chaos

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrChaosSimulated = errors.New("chaos: simulated failure")

ErrChaosSimulated is returned by SetErrorRate to simulate real cluster failures. Unlike types.ErrWriteDropped (which Helix treats as an operational state), this error is treated as a genuine write failure by AdaptiveDualWrite and the CQL client's DualClusterError path.

Functions

This section is empty.

Types

type Batch

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

Batch wraps a cql.Batch to inject chaos.

func (*Batch) Consistency

func (b *Batch) Consistency(c cql.Consistency) cql.Batch

func (*Batch) Exec

func (b *Batch) Exec() error

func (*Batch) ExecCAS

func (b *Batch) ExecCAS(dest ...any) (applied bool, iter cql.Iter, err error)

func (*Batch) ExecCASContext

func (b *Batch) ExecCASContext(ctx context.Context, dest ...any) (applied bool, iter cql.Iter, err error)

func (*Batch) ExecContext

func (b *Batch) ExecContext(ctx context.Context) error

func (*Batch) IterContext

func (b *Batch) IterContext(ctx context.Context) cql.Iter

func (*Batch) MapExecCAS

func (b *Batch) MapExecCAS(dest map[string]any) (applied bool, iter cql.Iter, err error)

func (*Batch) MapExecCASContext

func (b *Batch) MapExecCASContext(ctx context.Context, dest map[string]any) (applied bool, iter cql.Iter, err error)

func (*Batch) Query

func (b *Batch) Query(stmt string, args ...any) cql.Batch

func (*Batch) SerialConsistency

func (b *Batch) SerialConsistency(c cql.Consistency) cql.Batch

func (*Batch) Size

func (b *Batch) Size() int

func (*Batch) Statements

func (b *Batch) Statements() []cql.BatchEntry

func (*Batch) WithTimestamp

func (b *Batch) WithTimestamp(ts int64) cql.Batch

type ErrorIter

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

ErrorIter is a cql.Iter implementation that always returns an error.

func (*ErrorIter) Close

func (i *ErrorIter) Close() error

func (*ErrorIter) Columns

func (i *ErrorIter) Columns() []cql.ColumnInfo

func (*ErrorIter) MapScan

func (i *ErrorIter) MapScan(m map[string]any) bool

func (*ErrorIter) NumRows

func (i *ErrorIter) NumRows() int

func (*ErrorIter) PageState

func (i *ErrorIter) PageState() []byte

func (*ErrorIter) Scan

func (i *ErrorIter) Scan(dest ...any) bool

func (*ErrorIter) Scanner

func (i *ErrorIter) Scanner() cql.Scanner

func (*ErrorIter) SliceMap

func (i *ErrorIter) SliceMap() ([]map[string]any, error)

func (*ErrorIter) Warnings

func (i *ErrorIter) Warnings() []string

type ErrorScanner

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

ErrorScanner is a cql.Scanner implementation that always returns an error.

func (*ErrorScanner) Err

func (s *ErrorScanner) Err() error

func (*ErrorScanner) Next

func (s *ErrorScanner) Next() bool

func (*ErrorScanner) Scan

func (s *ErrorScanner) Scan(dest ...any) error

type Query

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

Query wraps a cql.Query to inject chaos.

func (*Query) Consistency

func (q *Query) Consistency(c cql.Consistency) cql.Query

func (*Query) Exec

func (q *Query) Exec() error

func (*Query) ExecContext

func (q *Query) ExecContext(ctx context.Context) error

func (*Query) Iter

func (q *Query) Iter() cql.Iter

func (*Query) IterContext

func (q *Query) IterContext(ctx context.Context) cql.Iter

func (*Query) MapScan

func (q *Query) MapScan(m map[string]any) error

func (*Query) MapScanCAS

func (q *Query) MapScanCAS(dest map[string]any) (applied bool, err error)

func (*Query) MapScanCASContext

func (q *Query) MapScanCASContext(ctx context.Context, dest map[string]any) (applied bool, err error)

func (*Query) MapScanContext

func (q *Query) MapScanContext(ctx context.Context, m map[string]any) error

func (*Query) PageSize

func (q *Query) PageSize(n int) cql.Query

func (*Query) PageState

func (q *Query) PageState(state []byte) cql.Query

func (*Query) Release

func (q *Query) Release()

func (*Query) Scan

func (q *Query) Scan(dest ...any) error

func (*Query) ScanCAS

func (q *Query) ScanCAS(dest ...any) (applied bool, err error)

func (*Query) ScanCASContext

func (q *Query) ScanCASContext(ctx context.Context, dest ...any) (applied bool, err error)

func (*Query) ScanContext

func (q *Query) ScanContext(ctx context.Context, dest ...any) error

func (*Query) SerialConsistency

func (q *Query) SerialConsistency(c cql.Consistency) cql.Query

func (*Query) Statement

func (q *Query) Statement() string

func (*Query) Values

func (q *Query) Values() []any

func (*Query) WithTimestamp

func (q *Query) WithTimestamp(ts int64) cql.Query

type Session

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

Session wraps a cql.Session to inject chaos.

func NewSession

func NewSession(wrapped cql.Session) *Session

NewSession creates a new chaos session wrapping the provided real session.

func (*Session) Batch

func (s *Session) Batch(kind cql.BatchType) cql.Batch

Batch creates a new batch of the given type.

func (*Session) Close

func (s *Session) Close()

Close is a no-op for the chaos session. The underlying session lifecycle is managed externally (e.g., by testutil.CQLCluster). This allows the chaos session to be reused across multiple helix client instances in simulation tests without prematurely closing the database connection.

func (*Session) Counters added in v1.1.0

func (s *Session) Counters() (exec, scan, drop int64)

Counters returns the cumulative operation counts since creation or last ResetCounters call. exec is the number of successful Exec/ExecCAS calls, scan is the number of successful Scan/Iter/MapScan calls, and drop is the number of operations rejected by chaos injection.

func (*Session) Query

func (s *Session) Query(stmt string, values ...any) cql.Query

Query creates a new query for the given statement.

func (*Session) ResetCounters added in v1.1.0

func (s *Session) ResetCounters()

ResetCounters zeroes all operation counters.

func (*Session) SetConfig

func (s *Session) SetConfig(cfg SessionConfig)

SetConfig updates the chaos configuration for the session.

func (*Session) SetErrorRate

func (s *Session) SetErrorRate(rate float64)

SetErrorRate sets a probability of error for operations. The injected error is ErrChaosSimulated (a real error), not types.ErrWriteDropped. This ensures AdaptiveDualWrite treats chaos failures as genuine write errors and accumulates strikes for degradation detection.

func (*Session) SetLatency

func (s *Session) SetLatency(d time.Duration)

SetLatency sets a fixed latency for all operations.

type SessionConfig

type SessionConfig struct {
	LatencyFunc func() time.Duration // Return 0 for no delay
	ErrorFunc   func() error         // Return nil for no error
	DropRate    float64              // 0.0-1.0 probability to drop
}

SessionConfig holds the chaos configuration for a session.

Jump to

Keyboard shortcuts

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