Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite volume storage, refactor some of the old code #16

Merged
merged 8 commits into from
Jun 5, 2023

Conversation

kolayne
Copy link
Owner

@kolayne kolayne commented Jun 3, 2023

The following features are introduced by this PR:

  • Volumes list is preserved on plugin restart (fixes Feature: preserve volumes list on plugin restart #7)
  • Everywhere outside the constructor (NewDockerOnTop) all the volumes and their metadata is accessed in a thread-safe manner, synchronized via filesystem access (there's a new requirement: the /var/lib/docker-on-top/ is located on a filesystem that supports the flock system call) (fixes Thread-safety! #15)
  • When started, the plugin checks all the existing volumes for unclean unmount (e.g. in case of reboot that didn't let the docker daemon properly cleanup) and attempts to fix it. There are some cases it is unable to detect (e.g. when it was down at the moment some container exited and for a long enough time after that) but the behavior is still better than before, and a reboot always fixes everything

Wrote a doc for which directories exist for volumes and how they are supposed to be managed. It will be used for storage implementation (#7)
The plugin now determines the active mounts for a volume (not overlay) using the activemounts/ subdirectory corresponding to the volume. It resolves the race condition problem with parallel mounts/unmounts on the same volume.

Gets us closer to fixing #15! However, not there yet, as we are still using go's `map`, which is thread-unsafe.
- Removed the `volumes` field of `Driver`, instead introduced the metadata.json per-volume internal file, which currently stores the base directory path and the volatility.
- Rewrote the methods that used the in-memory volume storage to use the filesystem instead.
- Renamed dotBaseDir to `dotRootDir` and turned it into a field of `Driver`.

Fixes #7.
As far as I can see, fixes #15!

The code is starting to get bulky, probably, restructuring is needed...
A large refactoring! Created several files and restructured the code between them, renamed a couple of entities, wrote documentation for some non-trivial functions/methods.

Also fixed a few minor bugs:
- A file descriptor leak in `lockedFile.Open` if an error occurs in `syscall.Flock`
- An error returned on every unmount, even when no actual error occurred
When creating a `DockerOnTop` object, go through the existing volumes with some sort of a health check: if an overlay is mounted for the volume, do nothing with it, otherwise ensure the active mounts and the workdir/ directory are clean - this protects from a case when the machine is rebooted without giving the docker daemon enough time to properly clean up.
dockerOnTop.go Outdated Show resolved Hide resolved
dockerOnTop.go Outdated Show resolved Hide resolved
dockerOnTop.go Outdated Show resolved Hide resolved
dockerOnTop.go Outdated Show resolved Hide resolved
dockerOnTop.go Outdated Show resolved Hide resolved
volumeTreeManagement.go Outdated Show resolved Hide resolved
volumeTreeManagement.go Outdated Show resolved Hide resolved
lockedFile.go Outdated Show resolved Hide resolved
lockedFile.go Outdated Show resolved Hide resolved
lockedFile.go Outdated Show resolved Hide resolved
When starting, the plugin now checks for each volume whether its state is clean, dirty but overlay-unmounted, or overlay-mounted. Info logs describe all the detected volumes, a detailed warning log message is issued if there's at least one overlay-mounted volume to explain which consequences it might have.
@kolayne kolayne force-pushed the preserve-volumes-list branch 2 times, most recently from 2a10633 to 4c9d685 Compare June 4, 2023 19:26
dockerOnTop.go Outdated Show resolved Hide resolved
dockerOnTop.go Outdated Show resolved Hide resolved
driver.go Outdated Show resolved Hide resolved
driver.go Outdated Show resolved Hide resolved
driver.go Outdated Show resolved Hide resolved
driver.go Outdated Show resolved Hide resolved
driver.go Outdated Show resolved Hide resolved
lockedFile.go Outdated Show resolved Hide resolved
volumeTreeManagement.go Outdated Show resolved Hide resolved
volumeTreeManagement.go Outdated Show resolved Hide resolved
@kolayne kolayne force-pushed the preserve-volumes-list branch 4 times, most recently from adf7120 to a408086 Compare June 5, 2023 08:40
Fixed some docs/comments, variables names, log messages, code style issues
Copy link
Owner Author

@kolayne kolayne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌

@kolayne kolayne merged commit c8108ab into master Jun 5, 2023
@kolayne kolayne deleted the preserve-volumes-list branch June 5, 2023 08:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Thread-safety! Feature: preserve volumes list on plugin restart
1 participant