diskcheck

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2021 License: GPL-3.0 Imports: 5 Imported by: 0

Documentation

Overview

Package diskcheck provides a communication channel for checking the disk health.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Checker

type Checker interface {
	Run(ctx context.Context)
	C() chan Health
}

Checker represents the downloader disk health component. The disk checker job is to notify its caller when the disk health state changes.

The interface describes two main concepts:

  • Run: The component's main loop which loops between the health state functions. The running function implicates the current disk health.

  • C: The health state communication channel used by the processor.

Useful implementation details:

  • waitForHealthy, waitForSick: health state monitoring functions that report back to the channel when the state changes. They can be canceled with ctx.

  • diskUsage: the disk usage percentage.

  • Healthy/Sick: the disk health state.

We need to stall the worker pools when the hd capacity drops below a threshold and restart them when we have again enough hd capacity. To achieve that, the processor reads from the communication channel the health state. Our approach implicitly considers that the disk checker will only write to the channel when there is a health state change.

The health checking functions execution order determines the current health state, which enables us to keep the implementation free from saving states.

func New

func New(path string, high int, low int, interval time.Duration) (Checker, error)

New returns a new checker for the provided directory path and thresholds.

type Health

type Health bool

Health represents the disk health state.

We are using two constants to describe the disk health: Sick and Healthy.

const (
	// Healthy represents a disk usage below the given Threshold.
	Healthy Health = Health(true)

	// Sick represents a disk usage above the given Threshold.
	Sick = Health(false)
)

func (Health) String

func (h Health) String() string

Jump to

Keyboard shortcuts

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