compare

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2026 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

Package compare provides a virtual Backend that runs multiple backends in parallel, uses the first (master) backend's results as the response, and logs discrepancies between backends for testing and validation purposes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Backend

type Backend = smtypes.Backend

Shared interface aliases keep the compare backend decoupled from the root package.

type CompareBackend

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

CompareBackend is a virtual Backend that runs multiple backends in parallel, returns the first (master) backend's results, and logs discrepancies.

All backends execute concurrently so overall latency is determined by the slowest backend. Callers should set an appropriate timeout on the context to bound latency when using slow or unreliable secondaries.

func NewCompareBackend

func NewCompareBackend(backends []Backend, opts ...Option) (*CompareBackend, error)

NewCompareBackend creates a CompareBackend with at least two backends. The first backend is the master; its results are always returned to the caller. Secondary backends run in parallel with the master; result mismatches are logged as warnings and secondary errors are logged as errors.

func (*CompareBackend) AbortSelfTest

func (c *CompareBackend) AbortSelfTest(ctx context.Context, devicePath string) error

AbortSelfTest aborts a running self-test on all backends and returns the master's error.

func (*CompareBackend) CheckHealth

func (c *CompareBackend) CheckHealth(ctx context.Context, devicePath string) (bool, error)

CheckHealth checks device health from all backends and returns the master's result.

func (*CompareBackend) Close

func (c *CompareBackend) Close() error

Close closes all backends, combining any errors into a single return value.

func (*CompareBackend) DisableSMART

func (c *CompareBackend) DisableSMART(ctx context.Context, devicePath string) error

DisableSMART disables SMART on all backends and returns the master's error.

func (*CompareBackend) DiscoverDevices

func (c *CompareBackend) DiscoverDevices(ctx context.Context) ([]DiscoveryResult, error)

DiscoverDevices discovers devices from all backends and returns the master's result. Backends that do not implement DiscoveryBackend fall back to ScanDevices + GetSMARTInfo.

func (*CompareBackend) EnableSMART

func (c *CompareBackend) EnableSMART(ctx context.Context, devicePath string) error

EnableSMART enables SMART on all backends and returns the master's error.

func (*CompareBackend) GetAvailableSelfTests

func (c *CompareBackend) GetAvailableSelfTests(ctx context.Context, devicePath string) (*SelfTestInfo, error)

GetAvailableSelfTests retrieves self-test info from all backends and returns the master's result.

func (*CompareBackend) GetDeviceInfo

func (c *CompareBackend) GetDeviceInfo(ctx context.Context, devicePath string) (map[string]any, error)

GetDeviceInfo retrieves device info from all backends and returns the master's result.

func (*CompareBackend) GetSMARTInfo

func (c *CompareBackend) GetSMARTInfo(ctx context.Context, devicePath string) (*SMARTInfo, error)

GetSMARTInfo retrieves SMART information from all backends and returns the master's result.

func (*CompareBackend) Name

func (c *CompareBackend) Name() string

Name returns "compare".

func (*CompareBackend) RunSelfTest

func (c *CompareBackend) RunSelfTest(ctx context.Context, devicePath string, testType string) error

RunSelfTest runs a self-test on all backends and returns the master's error.

func (*CompareBackend) ScanDevices

func (c *CompareBackend) ScanDevices(ctx context.Context) ([]Device, error)

ScanDevices scans for storage devices from all backends and returns the master's result.

type Device

type Device = smtypes.Device

Shared type aliases reuse the module's SMART domain model in the compare backend.

type DiscoveryBackend

type DiscoveryBackend = smtypes.DiscoveryBackend

Shared interface aliases keep the compare backend decoupled from the root package.

type DiscoveryResult

type DiscoveryResult = smtypes.DiscoveryResult

Shared type aliases reuse the module's SMART domain model in the compare backend.

type LogAdapter

type LogAdapter = smtypes.LogAdapter

Shared interface aliases keep the compare backend decoupled from the root package.

type Option

type Option func(*CompareBackend)

Option configures a CompareBackend.

func WithLogHandler

func WithLogHandler(logger LogAdapter) Option

WithLogHandler sets a custom LogAdapter for the compare backend.

func WithSlogHandler

func WithSlogHandler(logger *slog.Logger) Option

WithSlogHandler sets a custom slog.Logger for the compare backend.

func WithTLogHandler

func WithTLogHandler(logger *tlog.Logger) Option

WithTLogHandler sets a custom tlog.Logger for the compare backend.

type SMARTInfo

type SMARTInfo = smtypes.SMARTInfo

Shared type aliases reuse the module's SMART domain model in the compare backend.

type SelfTestInfo

type SelfTestInfo = smtypes.SelfTestInfo

Shared type aliases reuse the module's SMART domain model in the compare backend.

type SmartctlInfo

type SmartctlInfo = smtypes.SmartctlInfo

Shared type aliases reuse the module's SMART domain model in the compare backend.

Jump to

Keyboard shortcuts

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