File locking
With a lock, one process tells other processes to keep off a file, or off part of a file, while that process works on the file. On MooseFS, the Master Server keeps the locks, so the agreement holds between processes on different machines.
What it is
File locking covers two families that are independent of each other. BSD locks (flock) apply to a whole open file and are either shared or exclusive. POSIX record locks (lockf) apply to a byte range, so different parts of one file can be locked by different processes. Both families are advisory. A lock binds the processes that ask for one. Nothing stops a process that does not.
Why it matters
On a cluster, the Master Server coordinates locks. A lock taken through one mount is visible through the other mounts. An application that serializes its work with locks therefore behaves on MooseFS as it does on a local file system. The application would not behave that way if each mount kept its own lock table.
How MooseFS implements it
Both lock tables are part of the metadata that the Master Server holds, kept per object. They go into the metadata image and the changelog, so they remain after a restart of the Master Server.
A lock belongs to a session and to a lock owner within that session, not to a connection. A request that conflicts with a lock already held waits until the request can be granted. Closing the file releases what that session held on the file. Ending the session does the same (see Session and export).
A mount can turn cluster-wide POSIX record locks and BSD locks off separately, with one mount option per family. With a family turned off, the kernel handles those locks inside that one mount. No other client sees them.
The locks held at any moment are visible from outside the application that holds them. The CLI and the GUI list the locks acquired on an object. The list shows which family each lock belongs to and whether the lock is shared or exclusive. The list also shows which byte range the lock covers and which session and mount point holds the lock. The CLI and the GUI also list the files that each session has open.
The GUI shows both readings on one subtab: the files a session holds open and the locks taken on them.
Related tasks
- Open files and locks are read from the Master Server: reading which locks are held on an object and by whom.
- The CLI: the sections that print open files and acquired locks.
Related terms
- POSIX compliance: the rest of what a mount gives a POSIX application.
- Access Control Lists: the other POSIX facility that the Master Server coordinates cluster-wide.
- Extended and extra attributes: the metadata an object has beside its data.
- Master Server: the component that holds the locks and grants them.
- Client and mount: the side that asks, and where a mount option can keep a lock family local.
- Session and export: what a lock belongs to, and what its release is tied to.