Skip to content

iovation/flockd

Repository files navigation

flockd 0.3.1

Build Status Coverage Status GoDoc License

flockd provides a simple file system-based key/value database that uses file locking for concurrency safety. Keys correspond to files, values to their contents, and tables to directories. Files are share-locked on read (Get and ForEach) and exclusive-locked on write (Set, Create, Update, and Delete).

This may be overkill if you have only one application using a set of files in a directory. But if you need to sync files between multiple systems, like a distributed database, assuming your sync software respects file system locks, flockd might be a great way to go. This is especially true for modestly-sized databases and databases with a single primary instance and multiple read-only secondary instances.

In any event, your file system must support proper file locking for this to work. If your file system does not, it might still work if file renaming and unlinking is atomic and flockd is used exclusively to access files. If not, then all bets are off, and you can expect occasional bad reads.

All of this may turn out to be a bad idea. YMMV. Warranty not included.

Inspirations

  • diskv: Similar use of one file per key/value pair. Uses a sync.RWMutex for concurrency protection. Lots of features, including path transformation, caching, and compression.

  • fskv: Use of buckets similar to Tables here (I stole the idea, really). Relies on temporary files for locking. Depends on afero for file management.

  • Scribble: Uses a single JSON file for the database. Relies on sync.Mutex for concurrency control.