dmflakey

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2023 License: Apache-2.0 Imports: 9 Imported by: 1

README

go-dmflakey

Go bindings for the dm-flakey device.

Key Features

  • AllowWrites: The device is available for <up interval> seconds.

  • DropWrites: All write I/O is silently ignored for <down interval> seconds. Read I/O is handled correctly.

  • ErrorWrites: All write I/O is failed with an error signalled for <down interval> seconds. Read I/O is handled correctly.

Both <up> and <down> interval can be configured by WithIntervalFeatOpt(interval).

TODO: ErrorReads, CorruptBIOByte, RandomReadCorrupt, RandomWriteCorrupt.

Example

  • Simulate power failure and cause data loss
// init flakey device named by /dev/mapper/go-dmflakey with empty ext4 filesystem
flakey, _ := InitFlakey("go-dmflakey", workDir, FSTypeEXT4)

flakeyDevice := flakey.DevicePath()

// mount that flakey device into temp dir
args := []string{"mount", flakeyDevice, targetDir}
exec.Command(args[0], args[1:]).Run()

// write file in targetDir without syncfs/fsync/fdatasync
// ...

// drop all write IO created by previous step
flakey.DropWrites()

// remount and allow all write IO to simulate power failure
exec.Command("umount", targetDir)
flakey.AllowWrites()
exec.Command(args[0], args[1:]).Run()

// check the file
  • How to cause data loss during bbolt bench?

Checkout contrib-test-boltdb.

  • What if power failure after pulling image?

It's reproducer for container not starting in few nodes "standard_init_linux.go:219: exec user process caused: exec format error".

Checkout contrib-test-containerd.

Requirements

The package needs to invoke the following commands to init flakey device:

  • dmsetup.8 - low level logical volume management

  • mkfs.8 - build a Linux filesystem

All of them are supported by most of linux distributions.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FSType

type FSType string

FSType represents the filesystem name.

const (
	FSTypeEXT4 FSType = "ext4"
	FSTypeXFS  FSType = "xfs"
)

Supported filesystems.

type FeatOpt

type FeatOpt func(*featCfg)

FeatOpt is used to configure failure feature.

func WithIntervalFeatOpt

func WithIntervalFeatOpt(interval time.Duration) FeatOpt

WithIntervalFeatOpt updates the up time for the feature.

func WithSyncFSFeatOpt

func WithSyncFSFeatOpt(syncFS bool) FeatOpt

WithSyncFSFeatOpt is to determine if the caller wants to synchronize filesystem before inject failure.

type Flakey

type Flakey interface {
	// DevicePath returns the flakey device path.
	DevicePath() string

	// Filesystem returns filesystem's type.
	Filesystem() FSType

	// AllowWrites allows write I/O.
	AllowWrites(opts ...FeatOpt) error

	// DropWrites drops all write I/O silently.
	DropWrites(opts ...FeatOpt) error

	// ErrorWrites drops all write I/O and returns error.
	ErrorWrites(opts ...FeatOpt) error

	// ErrorReads makes all read I/O is failed with an error signalled.
	ErrorReads(opts ...FeatOpt) error

	// CorruptBIOByte corruptes one byte in write bio.
	CorruptBIOByte(nth int, read bool, value uint8, flags int, opts ...FeatOpt) error

	// RandomReadCorrupt replaces random byte in a read bio with a random value.
	RandomReadCorrupt(probability int, opts ...FeatOpt) error

	// RandomWriteCorrupt replaces random byte in a write bio with a random value.
	RandomWriteCorrupt(probability int, opts ...FeatOpt) error

	// Teardown releases the flakey device.
	Teardown() error
}

Flakey is to inject failure into device.

func InitFlakey

func InitFlakey(flakeyDevice, dataStorePath string, fsType FSType) (_ Flakey, retErr error)

InitFlakey creates an filesystem on a loopback device and returns Flakey on it.

The device-mapper device will be /dev/mapper/$flakeyDevice. And the filesystem image will be created at $dataStorePath/$flakeyDevice.img. By default, the device is available for 2 minutes and size is 10 GiB.

Directories

Path Synopsis
contrib module

Jump to

Keyboard shortcuts

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