fuweid / go-dmflakey

Go bindings for the dm-flakey device

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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.

About

Go bindings for the dm-flakey device

License:Apache License 2.0


Languages

Language:Go 100.0%