8000 GitHub - tjb/CadiaDB
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

tjb/CadiaDB

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CadiaDB

A modern educational database engine implementation in Rust, inspired by SQLite and DuckDB. Built to teach database internals while leveraging Rust's safety and performance features.

Project Overview

CadiaDB is a simple but powerful database engine that implements core database concepts:

  • Page-based storage engine
  • Buffer pool management
  • Table and record management
  • B-Tree indexing
  • Basic query processing
  • Transaction management
  • Column-oriented storage support

Learning Roadmap

Phase 0: Project Setup and Design

  • Initial project structure
  • Basic error handling
  • Design document for storage engine
  • Test infrastructure setup

1. Storage Engine (Current Focus)

The foundation of our database. We'll implement:

  • Project setup
  • Page structure
    • Fixed-size pages (4KB)
    • Page header with metadata
    • Data region
    • Slotted page layout for records
  • Disk manager
    • Page allocation
    • Read/write operations
    • Free page management
    • Page cache interface
    • File format specification

2. Buffer Management

Memory management layer that sits between storage and table operations:

  • Buffer pool manager
    • Page table (mapping page_id -> frame_id)
    • Frame allocation strategy
  • Page replacement (LRU)
    • Clock algorithm implementation
    • Victim selection
  • Dirty page handling
    • Write-back policy
    • Background flusher
  • Pin counting
    • Reference counting
    • Deadlock prevention

3. Table Management

Data organization and access methods:

  • Table metadata
    • Schema definition
    • Column types
    • Constraints
  • Record formats
    • Fixed-length records
    • Variable-length records
    • NULL handling
  • CRUD operations
    • Record insertion
    • Record deletion
    • Record updates
    • Sequential scan
  • Page directory
    • Free space management
    • Record location tracking

4. Indexing

B-Tree implementation for fast data access:

  • B-Tree implementation
    • Node structure
    • Tree traversal
    • Rebalancing
  • Key operations
    • Binary search
    • Range scans
    • Bulk loading
  • Page splits and merges
    • Split algorithms
    • Merge strategies
    • Redistribution
  • Iterator implementation
    • Forward scanning
    • Backward scanning
    • Range iteration

5. Query Processing

SQL parsing and execution:

  • Query parser
    • Lexer implementation
    • Parser implementation
    • AST definition
  • Execution engine
    • Plan nodes
    • Expression evaluation
    • Join algorithms
  • Basic SQL support
    • SELECT implementation
    • WHERE clause handling
    • JOIN support
    • Aggregations

6. Transactions

ACID guarantees and concurrency:

  • Transaction manager
    • Transaction states
    • Savepoints
    • Rollback support
  • Lock-based concurrency
    • Lock manager
    • Deadlock detection
    • Isolation levels
  • Write-ahead logging
    • Log records
    • Checkpointing
    • Recovery algorithms
  • Recovery
    • ARIES implementation
    • Crash recovery
    • Media recovery

Advanced Topics (Optional) 7368

  • Query optimization
    • Cost-based optimization
    • Statistics collection
    • Plan caching
  • Column store support
    • Column compression
    • Vectorized execution
    • Late materialization
  • Parallel execution
    • Parallel scan
    • Parallel join
    • Task scheduling

Getting Started

  1. Build the project:
# Clone the repository
git clone https://github.com/yourusername/cadiadb.git
cd cadiadb

# Build in debug mode
cargo build

# Build in release mode
cargo build --release
  1. Run the tests:
# Run all tests
cargo test

# Run tests with output
cargo test -- --nocapture

# Run specific test module
cargo test storage::page::tests
  1. Development Setup:
# Install helpful tools
cargo install cargo-watch  # For automatic rebuilds
cargo install cargo-edit  # For dependency management
cargo install cargo-audit # For security audits

# Set up git hooks (optional)
cargo install cargo-husky

Project Structure

src/
├── storage/       # Storage engine implementation
│   ├── page.rs   # Page structure
│   └── disk_manager.rs # Disk I/O
├── buffer/       # Buffer pool management
├── table/        # Table and record management
├── index/        # B-Tree implementation
├── query/        # Query processing
├── transaction/  # Transaction handling
└── error.rs     # Error types

Development Workflow

  1. Pick a task from the Learning Roadmap
  2. Create a new branch for the feature
  3. Write tests first (TDD approach)
  4. Implement the feature
  5. Run tests and benchmarks
  6. Submit a PR for review

Contributing

This is an educational project. Feel free to:

  • Submit bug fixes
  • Add new features
  • Improve documentation
  • Share learning resources

License

MIT License - See LICENSE file for details

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

0