Skip to main content

Module data_volume

Module data_volume 

Source
Expand description

Naming and lifecycle of the named container volumes that keep a container-backed resource’s data (an RDS database, an ElastiCache RDB, an EC2 instance’s data dir) across a container being recreated.

A volume belongs to exactly one scope, and its name carries the scope’s tag:

  • Data directory (--storage-mode persistent --data-path <dir>): the tag is a short hash of the canonical --data-path together with a random id minted the first time fakecloud uses the directory and stored in it (SCOPE_FILE). The same data dir reattaches the same volumes across restarts. A different data dir (a copy included, since its path differs), the same path after the directory was wiped (a new id), or a second fakecloud on the same daemon (two containers mounting different host dirs at the same in-container path differ by id) never sees them, so a fresh data dir can’t inherit another one’s database. The volumes are labelled with the scope tag and the data path, so docker volume ls --filter label=fakecloud-data-path=<dir> finds the ones a data dir owns.
  • Process (memory mode): nothing outlives the process’s state, so the tag is unique to the process and the volume carries the fakecloud-instance=fakecloud-<pid> ownership label the startup reaper uses to remove it once that process is gone.

Volumes created before scoping existed used an unscoped legacy name. A resource restored from a data dir written by such a build keeps using its legacy volume (docker has no volume rename, and copying a database between volumes needs an extra container and can fail half way). Each service records the choice on the resource as a DataVolumeBinding: resources created by this build are bound to their scoped volume from the start, and a resource persisted without a binding is bound once by resolve_binding against the daemon’s volume list.

Enums§

DataVolumeBinding
Which data volume a persisted resource mounts.
VolumeScope
Which lifetime a fakecloud process’s container volumes are tied to.

Constants§

DATA_PATH_LABEL
Label carrying the canonical --data-path of a data-dir scoped volume.
INSTANCE_LABEL
Ownership label shared with containers and networks (see the reaper).
SCOPE_FILE
File in the data dir holding the random half of its volume scope.
SCOPE_LABEL
Label carrying the scope tag a volume belongs to.

Functions§

current_scope
The scope this process names its volumes in: the data dir once init_data_dir_scope ran, otherwise the process.
ensure_volume
Create name labelled for scope unless it already exists (a volume from an earlier run of the same scope, or an adopted legacy volume, is reused as is). Best effort: if the create fails, the container’s -v still creates the volume, just without labels.
incarnation_id
A stable incarnation id derived from immutable facts of one resource incarnation (e.g. its ARN and creation timestamp): a delete and a recreate under the same identifier get different ids, so runtime records, container names and data volumes keyed by it never collide.
init_data_dir_scope
Tie this process’s volumes to data_path. Called once by the server in persistent mode, before any container runtime is built. A later call returns the scope already in place (it can’t change under volumes already named for it).
is_scoped_volume_name
Whether name is a volume scoped_volume_name produced for scope_tag.
legacy_volume_name
The unscoped name a build before data-dir scoping gave the same volume: fakecloud-<service>-data-<parts...>.
list_volumes
Names of every volume on the daemon, or None when the CLI can’t answer (so a caller doesn’t mistake an unreachable daemon for “no volumes”).
remove_process_volumes
On a clean shutdown in memory mode, remove every volume this process created: its state is gone, so nothing can reattach them. Run after the runtimes stopped their containers (a mounted volume can’t be removed). A no-op for a data-dir scope, whose volumes must outlive the process. A killed process’s volumes are left to the startup reaper instead.
remove_volume
Remove a volume, ignoring a missing one.
resolve_binding
Bind a resource persisted without a binding (written by a pre-scoping build, or never bound because the daemon couldn’t be listed) against the daemon’s volumes: its scoped volume once that exists (it has been used since), else the legacy volume a pre-scoping build left for it, else a new scoped one.
sanitize
Replace characters outside Docker’s [a-zA-Z0-9_.-] volume-name set.
scoped_volume_name
fakecloud-<service>-data-<scope tag>-<parts...>.
volume_exists
Whether the daemon has a volume named name (false if it can’t answer).