Documentation
¶
Overview ¶
Package blockio prepares disposable device-mapper storage for one BlueStore OSD and injects bounded main-device delay or EIO. The main device also carries BlueFS traffic. Restoring its table does not restart or recover the OSD.
Run, AttachOSD, Apply, Restore, Status and Terminate each give their work a two-minute deadline, including waiting for the backend lock where needed. An earlier caller deadline takes precedence.
Index ¶
- Constants
- type Config
- type Container
- func (b *Container) Apply(ctx context.Context, profile Profile) error
- func (b *Container) AttachOSD(ctx context.Context, cluster *ceph.Container) (*ceph.OSDContainer, error)
- func (b *Container) GetContainerID() string
- func (b *Container) Restore(ctx context.Context) error
- func (b *Container) Status(ctx context.Context) (Status, error)
- func (b *Container) Terminate(ctx context.Context, opts ...testcontainers.TerminateOption) error
- type Identity
- type Option
- type Profile
- type Status
- type Tables
Examples ¶
Constants ¶
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct{ Size int64 }
Config selects the logical backing size. Size is sector aligned, between MinSize and MaxSize; zero selects DefaultSize. The helper holds the sparse file on its own bounded tmpfs. Written pages consume Docker-host memory.
type Container ¶
type Container struct {
testcontainers.Container
// contains filtered or unexported fields
}
Container owns one backing file, loop, mapping and privileged keeper. Keep a non-nil value returned with an error. Terminate retains the keeper and its backing when a consumer or control step may remain active. Do not stop, restart or remove the embedded keeper while the backend is held.
func Run ¶
func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*Container, error)
Run prepares one disposable backend with the explicitly selected helper image. The image supplies sh, sleep, python3, dmsetup, losetup and blockdev; the Docker host grants privileged /dev access and registered linear support. Individual faults check their own registered target before use. No host module is loaded. Customizers reach the keeper; its identity, private tmpfs, command and image must remain intact. Register its CleanupContainer before the cluster's so cluster teardown precedes backing release.
Example ¶
package main
import (
"context"
"os"
"time"
"github.com/JSYoo5B/ceph-testcontainers-go/ceph"
"github.com/JSYoo5B/ceph-testcontainers-go/fault/blockio"
)
func main() {
ctx := context.Background()
// Select an image containing the documented device-mapper helper tools.
backend, err := blockio.Run(ctx, os.Getenv("CEPH_TEST_BLOCKIO_HELPER_IMAGE"), blockio.WithConfig(blockio.Config{Size: 1 << 30}))
if backend != nil {
defer func() { _ = backend.Terminate(ctx) }()
}
if err != nil {
panic(err)
}
cluster, err := ceph.Run(ctx, ceph.DefaultImage,
ceph.WithClusterConfig(ceph.ClusterConfig{}.WithNoInitialOSDs().WithPoolDefaults(1, 1)),
ceph.WithOSDStorage(ceph.OSDStorage{}.WithStartupBenchmark(ceph.OSDBenchmarkSkip)))
if cluster != nil {
// This defer runs before backend cleanup: the OSD consumes its device.
defer func() { _ = cluster.Terminate(ctx) }()
}
if err != nil {
panic(err)
}
if _, err := backend.AttachOSD(ctx, cluster); err != nil {
panic(err)
}
if err := backend.Apply(ctx, blockio.Profile{Delay: 250 * time.Millisecond}); err != nil {
panic(err)
}
// Exercise the SUT and observe its I/O independently of the requested table.
if _, err := backend.Status(ctx); err != nil {
panic(err)
}
if err := backend.Restore(ctx); err != nil {
panic(err)
}
// Restore changes the device table; restarting an exited OSD is separate.
}
Output:
func (*Container) Apply ¶
Apply installs one bounded main-device fault. A successful return confirms the requested table is active; it does not prove a client observed it. An error may leave an owned inactive table, suspension or pending kernel step. Inspect Status and retry Restore instead of replaying an uncertain request.
func (*Container) AttachOSD ¶
func (b *Container) AttachOSD(ctx context.Context, cluster *ceph.Container) (*ceph.OSDContainer, error)
AttachOSD creates and starts one OSD on this backend. It accepts only a ready linear backend and allows one attachment attempt, including partial startup. The two-minute operation deadline also covers OSD startup. Increasing the cluster startup timeout cannot extend that deadline. The cluster restores its registered block fault before stopping daemons; this separately owned keeper stays until the caller terminates the backend.
func (*Container) GetContainerID ¶
GetContainerID implements the container contract for partial startup too.
func (*Container) Restore ¶
Restore returns only this backend's recorded tables to its linear mapping. It settles prior steps before new ones, refuses foreign identity/tables, and remains retryable after cancellation or partial failure. OSD restart and acknowledged-data recovery are separate caller operations.
func (*Container) Status ¶
Status reads the owned identity and live/inactive tables separately from the last requested profile. Polling may confirm a recorded step, but never dispatches another mutation. A pending creation has no invented identity.
func (*Container) Terminate ¶
func (b *Container) Terminate(ctx context.Context, opts ...testcontainers.TerminateOption) error
Terminate restores the owned table, excludes cluster claims and all device openers/I/O, then releases mapping, loop, file and keeper in that order. Terminate the attached cluster first. A failure retains remaining resources and the same handle for retry; it never forces a busy or foreign mapping.
type Identity ¶
Identity identifies the mapping observed for this disposable backend. It is observation only: Run accepts no existing mapping, loop or physical disk.
type Option ¶
type Option struct {
// contains filtered or unexported fields
}
Option carries Config to Run; its Customize changes no container settings.
func WithConfig ¶
WithConfig carries the one optional Config to Run.
func (Option) Customize ¶
func (Option) Customize(*testcontainers.GenericContainerRequest) error
Customize implements testcontainers.ContainerCustomizer.
type Profile ¶
Profile selects exactly one main-device fault. Delay is a positive whole number of milliseconds, at most MaxDelay. EIO makes every sector return an I/O error. It can abort the OSD; client operations may time out instead of returning EIO. A profile never implies independent observation of its effect.
type Status ¶
type Status struct {
Requested Profile
Identity *Identity
Tables *Tables
PendingStep string
Released bool
}
Status keeps requested settings separate from independently read kernel tables. Identity and Tables are nil until observed; PendingStep names an operation whose completion has not been confirmed. Released means that the owned mapping, loop, file and helper have all been released.