C implementation of a client-server key-value store project, extended with session-based client communication through named pipes, subscription management, notifications on key updates, and signal-based client disconnection.
The server continues to support job-processing and key-value storage functionality, including:
WRITEREADDELETESHOWWAITBACKUPHELP
On top of that:
- A standalone KVS server
- Client connections through named pipes (FIFOs)
- Session establishment through a registration FIFO
- Support for multiple concurrent client sessions
- Subscription and unsubscription to key updates
- Asynchronous notifications sent to subscribed clients
- Signal-based disconnection of all clients using
SIGUSR1
Although this implementation builds on the first project stage, the repository is focused on the Part 2 functionality.
- In-memory key-value storage
- Support for batch execution of
.jobfiles - Output generation in matching
.outfiles - Non-blocking backups using
fork - Parallel processing of job files with multiple worker threads
- Server launched as an autonomous process
- Registration of client sessions through a server registration FIFO
- Dedicated request, response, and notification FIFOs per client
- Client API with support for:
kvs_connectkvs_disconnectkvs_subscribekvs_unsubscribe
- Notification delivery whenever a subscribed key is updated
- Notification of deleted keys using
DELETED - Support for multiple simultaneous sessions
- Producer-consumer coordination between the host task and session manager tasks
- Session termination and cleanup on
SIGUSR1
The system is organized into three main components:
The server:
- loads and processes
.jobfiles from a given directory - maintains the shared key-value store
- handles client registration through a named pipe
- manages active sessions
- sends notifications to subscribed clients
- processes
SIGUSR1to disconnect all clients without shutting down the server
Each client:
- creates its own named pipes
- connects to the server through the registration FIFO
- sends subscribe / unsubscribe / disconnect requests
- uses one thread for request-response handling
- uses a second thread to receive asynchronous notifications
The common module contains:
- shared constants
- protocol definitions
- I/O helpers
- safe utility functions
.
βββ Makefile
βββ README.md
βββ src/
βββ client/
β βββ api.c
β βββ api.h
β βββ main.c
β βββ parser.c
β βββ parser.h
βββ common/
β βββ constants.h
β βββ io.c
β βββ io.h
β βββ protocol.h
β βββ safeFunctions.c
β βββ safeFunctions.h
βββ server/
β βββ avl.c
β βββ avl.h
β βββ constants.h
β βββ kvs.c
β βββ kvs.h
β βββ main.c
β βββ operations.c
β βββ operations.h
β βββ parser.c
β βββ parser.h
β βββ README.md
βββ tests/
βββ client_tests.txt
The server is launched with:
./kvs dir_jobs max_threads backups_max register_fifoThe client is launched with:
./client client_id register_fifoTo establish a session, the client:
- creates three FIFOs:
- request FIFO
- response FIFO
- notification FIFO
- sends their names to the server through the registration FIFO
- waits for the server to accept the session
After connecting, a client can:
- subscribe to a key
- unsubscribe from a key
- disconnect from the server
Whenever a subscribed key changes, the server sends a notification in the form:
(key,value)
If a subscribed key is deleted, the client receives:
(key,DELETED)
This project combines several synchronization and operating-systems concepts:
- multiple threads for parallelism
- named pipes (FIFOs) for inter-process communication
- mutexes and semaphores for synchronization
- producer-consumer coordination between the host task and session manager tasks
- signals for external session termination
- fork-based backups inherited from the first project stage
The server processes .job files concurrently while also handling client subscriptions and notifications.
The server redefines the handling of SIGUSR1.
When the host task receives this signal, it:
- removes all current subscriptions
- closes all client notification and response FIFOs
- forces clients to terminate
- keeps the server running and ready to accept new future sessions
This means that SIGUSR1 disconnects all clients, but does not stop the server itself.
Use the provided Makefile:
makeTo clean generated files:
make clean./kvs <jobs_directory> <max_threads> <max_backups> <register_fifo>Example:
./kvs jobs 4 2 register_fifo./client/client <client_id> <register_fifo>Example:
./client/client c1 register_fifoYou can also redirect client commands from a test file:
./client/client c2 register_fifo < src/tests/client_tests.txtA connected client may issue commands such as:
SUBSCRIBE key1
UNSUBSCRIBE key1
DELAY 2
DISCONNECT
The client prints responses returned by the server and separately prints notifications received through the notification FIFO.
- Developed in C
- Client-server architecture
- Named-pipe based communication
- Session-based subscription model
- Asynchronous notifications
- Multithreaded server design
- Signal-aware session cleanup
- Concurrent job processing and backup support
- Modular organization into client, server, and common layers
This project was developed by: