Skip to content

About

πŸ””πŸ“¨ C-based key-value store extended into a client-server system with inter-process communication and notifications.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

Β 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

KVS Client-Server Key-Value Store

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.


Project Description

The server continues to support job-processing and key-value storage functionality, including:

  • WRITE
  • READ
  • DELETE
  • SHOW
  • WAIT
  • BACKUP
  • HELP

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.


Main Features

Base Functionality

  • In-memory key-value storage
  • Support for batch execution of .job files
  • Output generation in matching .out files
  • Non-blocking backups using fork
  • Parallel processing of job files with multiple worker threads

Client-Server Extensions

  • 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_connect
    • kvs_disconnect
    • kvs_subscribe
    • kvs_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

Architecture Overview

The system is organized into three main components:

Server

The server:

  • loads and processes .job files 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 SIGUSR1 to disconnect all clients without shutting down the server

Client

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

Common Layer

The common module contains:

  • shared constants
  • protocol definitions
  • I/O helpers
  • safe utility functions

Project Structure

.
β”œβ”€β”€ 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

Client-Server Communication

The server is launched with:

./kvs dir_jobs max_threads backups_max register_fifo

The client is launched with:

./client client_id register_fifo

Session Setup

To establish a session, the client:

  1. creates three FIFOs:
    • request FIFO
    • response FIFO
    • notification FIFO
  2. sends their names to the server through the registration FIFO
  3. waits for the server to accept the session

Supported Client Operations

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)

Synchronization and Concurrency

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.


Signal Handling

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.


Compilation

Use the provided Makefile:

make

To clean generated files:

make clean

Running the Project

Start the server

./kvs <jobs_directory> <max_threads> <max_backups> <register_fifo>

Example:

./kvs jobs 4 2 register_fifo

Start a client

./client/client <client_id> <register_fifo>

Example:

./client/client c1 register_fifo

You can also redirect client commands from a test file:

./client/client c2 register_fifo < src/tests/client_tests.txt

Example Client Commands

A 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.


Technical Highlights

  • 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

Credits

This project was developed by:

About

πŸ””πŸ“¨ C-based key-value store extended into a client-server system with inter-process communication and notifications.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages