|
1 | 1 |
|
2 | | -# ⚡ VoltCache |
| 2 | +--- |
3 | 3 |
|
4 | | -<p align="left"> <img src="https://img.shields.io/badge/status-Stable-brightgreen.svg" /> <img src="https://img.shields.io/github/license/arshc0der/VoltCache?color=green" /> <img src="https://img.shields.io/github/stars/arshc0der/VoltCache?style=social" /> <img src="https://img.shields.io/github/forks/arshc0der/VoltCache?style=social" /> <img src="https://img.shields.io/github/issues/arshc0der/VoltCache" /> <img src="https://img.shields.io/github/last-commit/arshc0der/VoltCache" /> <img src="https://img.shields.io/badge/language-C%2B%2B17-00599C?logo=c%2B%2B&logoColor=white" /> <img src="https://img.shields.io/badge/build-CMake-064F8C?logo=cmake&logoColor=white" /> <img src="https://img.shields.io/badge/platform-Windows%20%7C%20Linux-lightgrey" /> <img src="https://img.shields.io/badge/threading-std::shared__mutex-blue" /> <img src="https://img.shields.io/badge/persistence-Write--Ahead%20Logging-orange" /> <img src="https://img.shields.io/badge/testing-Python%20Integration%20Suite-yellow" /> <img src="https://img.shields.io/badge/dependencies-Zero-success" /> </p> |
| 4 | +# ⚡ VoltCache |
5 | 5 |
|
6 | | -<p align="center"> |
7 | | - <img src="https://raw.githubusercontent.com/arshc0der/VoltCache/refs/heads/main/Testing/preview/logo.png" width="100%" alt="VoltCache"/> |
| 6 | +### High-Performance In-Memory Key-Value Engine (C++17) |
| 7 | +<p align="center"> <img src="https://raw.githubusercontent.com/arshc0der/VoltCache/refs/heads/main/Testing/preview/logo.png" width="100%" alt="VoltCache"/> </p> |
| 8 | +<p align="left"> |
| 9 | + <img src="https://img.shields.io/badge/status-Stable-brightgreen.svg" /> |
| 10 | + <img src="https://img.shields.io/github/license/arshc0der/VoltCache?color=green" /> |
| 11 | + <img src="https://img.shields.io/github/stars/arshc0der/VoltCache?style=social" /> |
| 12 | + <img src="https://img.shields.io/github/forks/arshc0der/VoltCache?style=social" /> |
| 13 | + <img src="https://img.shields.io/github/issues/arshc0der/VoltCache" /> |
| 14 | + <img src="https://img.shields.io/github/last-commit/arshc0der/VoltCache" /> |
| 15 | + <img src="https://img.shields.io/badge/language-C%2B%2B17-00599C?logo=c%2B%2B&logoColor=white" /> |
| 16 | + <img src="https://img.shields.io/badge/build-CMake-064F8C?logo=cmake&logoColor=white" /> |
| 17 | + <img src="https://img.shields.io/badge/architecture-Multithreaded-critical" /> |
| 18 | + <img src="https://img.shields.io/badge/concurrency-Reader--Writer%20Lock-blueviolet" /> |
| 19 | + <img src="https://img.shields.io/badge/persistence-Write--Ahead%20Logging-orange" /> |
| 20 | + <img src="https://img.shields.io/badge/dependencies-Zero-success" /> |
8 | 21 | </p> |
9 | 22 |
|
10 | | -> **Status:** High-performance in-memory engine with completed Durability (WAL) and Thread-Safe Concurrency layers. |
| 23 | +--- |
| 24 | + |
| 25 | +## 🚀 Overview |
| 26 | + |
| 27 | +**VoltCache** is a lightweight, high-performance, multithreaded in-memory key-value store built in **C++17**. |
11 | 28 |
|
12 | | -VoltCache is a lightweight, multithreaded in-memory key-value store built with **C++17**. It is designed to handle low-latency data access while ensuring data integrity through a Write-Ahead Logging system. By utilizing modern C++ synchronization primitives, VoltCache supports high-throughput concurrent client connections. |
| 29 | +It is engineered to deliver: |
| 30 | + |
| 31 | +* ⚡ Ultra-low latency reads |
| 32 | +* 🔒 Thread-safe concurrent access |
| 33 | +* 💾 Durable persistence via Write-Ahead Logging (WAL) |
| 34 | +* 🧵 Modern C++ synchronization using RAII |
| 35 | + |
| 36 | +Designed to simulate production-grade caching systems like Redis — but implemented from scratch to demonstrate deep systems-level understanding. |
13 | 37 |
|
14 | 38 | --- |
15 | 39 |
|
16 | | -### 🚀 Core Features (Implemented) |
| 40 | +## ✨ Key Features |
| 41 | + |
| 42 | +### 🧵 Thread-Safe Concurrency |
| 43 | + |
| 44 | +* Implements **Reader-Writer Lock pattern** |
| 45 | +* Uses `std::shared_mutex` |
| 46 | +* Unlimited concurrent reads |
| 47 | +* Exclusive writes via `std::unique_lock` |
| 48 | +* RAII-based lock safety |
| 49 | + |
| 50 | +### 💾 Durability with Write-Ahead Logging |
17 | 51 |
|
18 | | -* **Thread-Safe Engine:** Implements a **Reader-Writer Lock pattern** using `std::shared_mutex`. This allows unlimited concurrent reads while ensuring exclusive access for writes, maximizing throughput. |
19 | | -* **Durability (Write-Ahead Logging):** Every `SET` operation is flushed to `data/volt.log` before memory update. On system restart, the engine automatically replays the log to restore the state. |
20 | | -* **Structured Data Support:** Advanced tokenization allows for storing complex strings and **JSON** objects (handling spaces and delimiters correctly). |
21 | | -* **Zero-Dependency Build:** Managed entirely via **CMake**, ensuring the project is portable and easy to compile in any C++ environment. |
| 52 | +* Every `SET` operation is logged before memory mutation |
| 53 | +* Log file: `data/volt.log` |
| 54 | +* Crash recovery via automatic WAL replay |
| 55 | +* Prevents recursive re-logging during restore |
| 56 | + |
| 57 | +### 📦 Structured Data Support |
| 58 | + |
| 59 | +* Advanced token parsing |
| 60 | +* Stores: |
| 61 | + |
| 62 | + * Strings with spaces |
| 63 | + * Delimiter-safe values |
| 64 | + * JSON payloads |
| 65 | + |
| 66 | +### ⚙️ Zero Dependency Build |
| 67 | + |
| 68 | +* Fully managed via **CMake** |
| 69 | +* No external libraries |
| 70 | +* Portable across Windows & Linux |
22 | 71 |
|
23 | 72 | --- |
24 | 73 |
|
25 | | -### 🛠️ Technical Deep-Dive |
| 74 | +## 🏗 Architecture |
26 | 75 |
|
27 | | -#### **Concurrency & RAII** |
| 76 | +``` |
| 77 | +Client Threads |
| 78 | + │ |
| 79 | + ▼ |
| 80 | +┌───────────────────────┐ |
| 81 | +│ Shared Hash Map │ |
| 82 | +│ (std::unordered_map) │ |
| 83 | +└───────────────────────┘ |
| 84 | + ▲ |
| 85 | + │ |
| 86 | + Reader-Writer Lock |
| 87 | + │ |
| 88 | + ▼ |
| 89 | + Write-Ahead Log (WAL) |
| 90 | +``` |
28 | 91 |
|
29 | | -The system uses RAII (Resource Acquisition Is Initialization) to manage thread safety. |
| 92 | +### Concurrency Model |
30 | 93 |
|
31 | | -* **Writes:** Handled via `std::unique_lock` for exclusive access. |
32 | | -* **Reads:** Handled via `std::shared_lock` for concurrent access. |
| 94 | +| Operation | Lock Type | Behavior | |
| 95 | +| --------- | ----------- | ----------- | |
| 96 | +| GET | shared_lock | Concurrent | |
| 97 | +| SET | unique_lock | Exclusive | |
| 98 | +| WAL Flush | File I/O | Synchronous | |
33 | 99 |
|
34 | | -#### **Data Recovery** |
| 100 | +--- |
35 | 101 |
|
36 | | -The `load_from_wal()` sequence ensures that the database is fault-tolerant: |
| 102 | +## 🔄 Crash Recovery Flow |
37 | 103 |
|
38 | | -1. Check for existing `data/volt.log`. |
39 | | -2. Parse commands and tokens line-by-line. |
40 | | -3. Inject data into the hash map without re-logging, preventing log recursion. |
| 104 | +1. Detect `data/volt.log` |
| 105 | +2. Parse commands line-by-line |
| 106 | +3. Inject data directly into memory |
| 107 | +4. Skip logging during recovery phase |
| 108 | +5. Restore complete state |
41 | 109 |
|
42 | 110 | --- |
43 | 111 |
|
44 | | -### 📂 Project Structure |
| 112 | +## 📂 Project Structure |
45 | 113 |
|
46 | 114 | ```text |
47 | 115 | VoltCache/ |
48 | | -├── include/ # Header files (Engine declarations) |
49 | | -├── src/ # Core Implementation (Server & Engine logic) |
50 | | -├── Testing/ # Python-based Integration Test Suite |
51 | | -├── data/ # Persistent WAL storage (ignored by git) |
52 | | -├── CMakeLists.txt # Cross-platform build configuration |
53 | | -└── .gitignore # Configured to keep build/ and logs out of repo |
54 | | -
|
| 116 | +├── include/ # Engine declarations |
| 117 | +├── src/ # Server & engine implementation |
| 118 | +├── Testing/ # Python integration tests |
| 119 | +├── data/ # WAL persistence layer |
| 120 | +├── CMakeLists.txt |
| 121 | +└── README.md |
55 | 122 | ``` |
56 | 123 |
|
57 | 124 | --- |
58 | 125 |
|
59 | | -### ⚙️ Installation & Build |
| 126 | +## ⚙️ Installation |
60 | 127 |
|
61 | | -**Prerequisites:** |
| 128 | +### 🔧 Requirements |
62 | 129 |
|
63 | 130 | * CMake 3.10+ |
64 | | -* MinGW-w64 (UCRT64 recommended) or GCC |
| 131 | +* GCC / MinGW-w64 (UCRT64 recommended) |
| 132 | +* Python 3 (for integration tests) |
65 | 133 |
|
66 | | -**Building:** |
| 134 | +### 🏗 Build |
67 | 135 |
|
68 | 136 | ```bash |
69 | 137 | mkdir build && cd build |
70 | 138 | cmake -G "MinGW Makefiles" .. |
71 | 139 | cmake --build . |
72 | | - |
73 | 140 | ``` |
74 | 141 |
|
75 | | -**Running the Server:** |
| 142 | +### ▶ Run Server |
76 | 143 |
|
77 | 144 | ```bash |
78 | | -.\VoltCache.exe |
79 | | - |
| 145 | +./VoltCache |
80 | 146 | ``` |
81 | 147 |
|
82 | | -**Running Tests:** |
| 148 | +### 🧪 Run Integration Tests |
83 | 149 |
|
84 | 150 | ```bash |
85 | 151 | python Testing/test_volt.py |
86 | | - |
87 | 152 | ``` |
88 | 153 |
|
89 | 154 | --- |
90 | 155 |
|
91 | | -### 🗺️ Roadmap (Upcoming Features) |
| 156 | +## 📈 Performance Goals |
| 157 | + |
| 158 | +* O(1) average lookup (hash map) |
| 159 | +* Minimal lock contention |
| 160 | +* WAL durability with low overhead |
| 161 | +* Safe concurrent client simulation |
| 162 | + |
| 163 | +--- |
| 164 | + |
| 165 | +## 🗺 Roadmap |
92 | 166 |
|
93 | | -* [ ] **LRU Eviction Policy:** Implement `std::list` + `std::unordered_map` for O(1) eviction of least recently used keys when memory limits are reached. |
94 | | -* [ ] **Lock Striping:** Horizontal partitioning (sharding) of the database into 16 discrete buckets to reduce lock contention. |
95 | | -* [ ] **Google Test Integration:** Unit testing for core engine components to ensure 100% logic coverage. |
| 167 | +* [ ] LRU Eviction Policy (O(1) eviction via list + hashmap) |
| 168 | +* [ ] Lock Striping (16 bucket sharding) |
| 169 | +* [ ] GoogleTest unit coverage |
| 170 | +* [ ] Benchmark suite (throughput + latency metrics) |
| 171 | +* [ ] Optional async WAL mode |
| 172 | +* [ ] Snapshotting mechanism |
96 | 173 |
|
97 | 174 | --- |
98 | 175 |
|
99 | | -### 🏆 Why this project? |
| 176 | +## 🧠 Design Philosophy |
| 177 | + |
| 178 | +VoltCache is built to demonstrate: |
| 179 | + |
| 180 | +* Advanced C++17 mastery |
| 181 | +* RAII-driven concurrency safety |
| 182 | +* File I/O durability guarantees |
| 183 | +* Real-world system design principles |
| 184 | + |
| 185 | +This is not just a CRUD store — it’s a **mini database engine**. |
| 186 | + |
| 187 | +--- |
100 | 188 |
|
101 | | -This project demonstrates proficiency in **System Design**, **Modern C++ synchronization**, and **File I/O performance**. It is built to simulate real-world constraints found in systems like Redis and Memcached. |
| 189 | +## 🏆 Why VoltCache Stands Out |
102 | 190 |
|
103 | | ---- |
| 191 | +✔ Fully thread-safe architecture |
| 192 | + |
| 193 | +✔ Persistent durability layer |
| 194 | + |
| 195 | +✔ Clean modular structure |
| 196 | + |
| 197 | +✔ Zero third-party dependencies |
| 198 | + |
| 199 | +Built as a foundational stepping stone toward distributed caching and database engines. |
| 200 | + |
| 201 | +--- |
| 202 | + |
| 203 | +## 🤝 Contributing |
| 204 | + |
| 205 | +Contributions are welcome. |
| 206 | +If you'd like to improve performance, add benchmarking, or implement eviction strategies — open a PR. |
| 207 | + |
| 208 | +--- |
0 commit comments