Skip to content

StarWindv/Wind-KVStore

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

91 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Wind-KVStore

δΈ­ζ–‡

GitHub License Rust Version Ask DeepWiki

Wind-KVStore is a lightweight, efficient, and persistent key-value storage engine implemented in Rust. The project combines a high-performance storage engine with a user-friendly command-line interface and net server, making it suitable for scenarios requiring local persistent storage.

✨ Features

  • πŸ“ Persistent Storage - Data securely written to disk with crash recovery support
  • πŸ“ Write-Ahead Log (WAL) - Ensures operation atomicity and durability
  • ⚑ Memory-Mapped Files - Provides high-performance file access
  • πŸ—‚οΈ LRU Caching - Automatically manages hot data caching
  • πŸ”’ Paged Storage - Supports overflow pages for large value data
  • ♻️ Free Page Management - Efficient disk space reuse
  • πŸ—œοΈ Database Compression - Optimizes storage space utilization
  • >_ Interactive Shell - Offers intuitive command-line interface
  • πŸ–₯️ Server - Provides clean server interface with built-in session management

πŸš€ Quick Start

Prerequisites

Installation & Running

# Clone repository
git clone https://github.com/starwindv/wind-kvstore
cd wind-kvstore

# Build project
cargo build --release

# Run interactive Shell
cargo run --bin wkshell --release

# Run server
cargo run --bin wkserver --release

>_ Interactive Shell Guide

Shell Documentation

πŸ–₯️ Server Guide

Server Documentation

πŸ“¦ Using as a Library

Add Dependency

Add to your Cargo.toml:

[dependencies]
wind-kvstore = { git = "https://github.com/starwindv/wind-kvstore" }

Library Usage Example

use wind_kvstore::KVStore;
use anyhow::Result;

fn main() -> Result<()> {
    // Open database
    let mut store = KVStore::open("app_data.db", Some("MyAppDB"))?;
    
    // Store data
    store.put(b"username", b"alice")?;
    
    // Retrieve data
    if let Some(value) = store.get(b"username")? {
        println!("Username: {}", String::from_utf8_lossy(&value));
    }
    
    // Delete data
    store.delete(b"username")?;
    
    // Set database identifier
    store.set_identifier("UserDatabase")?;
    
    // Compact database
    store.compact()?;
    
    // Close database
    store.close()?;
    
    Ok(())
}

Core API

impl KVStore {
    /// Open or create database
    pub fn open<P: AsRef<Path>>(
        path: P, 
        db_identifier: Option<&str>
    ) -> Result<Self>{}
    
    /// Store key-value pair
    pub fn put(&mut self, key: &[u8], value: &[u8]) -> Result<()>{}
    
    /// Retrieve value
    pub fn get(&mut self, key: &[u8]) -> Result<Option<Vec<u8>>>{}
    
    /// Delete key-value
    pub fn delete(&mut self, key: &[u8]) -> Result<()>{}
    
    /// Compact database
    pub fn compact(&mut self) -> Result<()>{}
    
    /// Get database identifier
    pub fn get_identifier(&self) -> &str{}
    
    /// Set database identifier
    pub fn set_identifier(&mut self, identifier: &str) -> Result<()>{}
    
    /// Close database
    pub fn close(mut self) -> Result<()>{}
}

πŸ—οΈ Project Structure

β”œβ”€β”€ build.rs            # Build script (records compilation time)
β”œβ”€β”€ Cargo.toml          # Project configuration and dependency management
β”œβ”€β”€ doc/                # Another documentation(Chinese and English)
β”œβ”€β”€ README.md           # Project documentation (English)
β”œβ”€β”€ README_CN.md        # Project documentation (Chinese)
β”œβ”€β”€ LICENSE             # MIT
β”œβ”€β”€ sdk
β”‚   β”œβ”€β”€ python/         # Wind-KVStore server's sdk for python
β”‚   └── test/           # Test sdk
β”œβ”€β”€ GUI
β”‚   β”œβ”€β”€ src/            # Wind KVStore's visualize interface
β”‚   └── LICENSE         # GPLv3
└── src
    β”œβ”€β”€ config.rs       # Server configuration loader
    β”œβ”€β”€ kvstore.rs      # Core KV storage engine implementation
    β”œβ”€β”€ server.rs       # Server main logic
    β”œβ”€β”€ server_main.rs  # Server entry point
    β”œβ”€β”€ shell.rs        # Interactive shell main logic
    β”œβ”€β”€ shell_main.rs   # Interactive shell entry point
    └── utils.rs        # Utility functions

πŸ“¦ Another Modules

Visualize Interface

Python SDK

Python Lib

βš™οΈ Technical Implementation

Storage Architecture

+-----------------------+
|    File Header (128B) |
+-----------------------+
|    Page Header (16B)  |
+-----------------------+
|      Key-Value Data   |
+-----------------------+
|    Overflow Page Ptr  |
+-----------------------+
|         ...           |
+-----------------------+

Key Features

  1. Paged Storage

    • Fixed-size pages (default 1KB)
    • Overflow page support for large values
    • Free page linked list management
  2. Write-Ahead Log

    • Operation logging
    • Automatic crash recovery
    • Atomic operation guarantee
  3. Cache Management

    • LRU caching strategy
    • Automatic hot data management
    • Default 100KB cache size
  4. Space Optimization

    • Automatic free page recycling
    • Online database compression
    • Efficient storage layout

🀝 Contribution Guide

We welcome all forms of contributions! When contributing, we recommend:

  • Updating relevant documentation
  • Submitting clear PR descriptions
  • Not worrying about communication language - we accept both English and Chinese descriptions. If you're not comfortable with these languages, feel free to use your preferred language

πŸ“œ License

This project is licensed under the MIT License

About

Lightweight Key-Value Store engine (rust), using LRU as a cache eliminate strategy ,and to provide server and interactive shellProvide comprehensive and rich documentation and easy-to-use SDK.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors