Project 9: Record Locking Database
A simple key-value store where concurrent processes can read and write records using fcntl byte-range locks.
Quick Reference
| Attribute | Value |
|---|---|
| Primary Language | C |
| Alternative Languages | N/A |
| Difficulty | Level 3 (Advanced) |
| Time Estimate | See main guide |
| Knowledge Area | File Systems, Databases |
| Tooling | See main guide |
| Prerequisites | See main guide |
What You Will Build
A simple key-value store where concurrent processes can read and write records using fcntl byte-range locks.
Why It Matters
This project builds core skills that appear repeatedly in real-world systems and tooling.
Core Challenges
- Deadlock detection → fcntl with F_SETLKW can deadlock
- Lock inheritance → What happens across fork()?
- Advisory nature → Uncooperative processes can ignore locks
Key Concepts
- Map the project to core concepts before you code.
Real-World Outcome
# Start multiple concurrent clients
$ ./kvstore set key1 value1 &
$ ./kvstore set key2 value2 &
$ ./kvstore get key1 &
$ ./kvstore set key1 updated &
# All complete without corruption
$ ./kvstore get key1
updated
$ ./kvstore get key2
value2
# Verify locking works
$ ./kvstore lock-test key1
Process 1: Acquired write lock on key1
Process 2: Waiting for lock...
(Process 1 holds lock for 2 seconds)
Process 1: Released lock
Process 2: Acquired write lock on key1
Implementation Guide
- Reproduce the simplest happy-path scenario.
- Build the smallest working version of the core feature.
- Add input validation and error handling.
- Add instrumentation/logging to confirm behavior.
- Refactor into clean modules with tests.
Milestones
- Milestone 1: Minimal working program that runs end-to-end.
- Milestone 2: Correct outputs for typical inputs.
- Milestone 3: Robust handling of edge cases.
- Milestone 4: Clean structure and documented usage.
Validation Checklist
- Output matches the real-world outcome example
- Handles invalid inputs safely
- Provides clear errors and exit codes
- Repeatable results across runs
References
- Main guide:
UNIX_IPC_STEVENS_VOL2_MASTERY.md - Primary references are listed in the main guide