{"id":17946496,"url":"https://github.com/pumpum7/rust-database","last_synced_at":"2026-01-24T11:38:40.933Z","repository":{"id":259626009,"uuid":"878502319","full_name":"PumPum7/rust-database","owner":"PumPum7","description":"A simple database system with client-server architecture in rust","archived":false,"fork":false,"pushed_at":"2024-11-01T14:43:14.000Z","size":135,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-09T03:30:11.346Z","etag":null,"topics":["database","rust"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsl-1.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/PumPum7.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-10-25T14:07:22.000Z","updated_at":"2025-01-02T21:33:11.000Z","dependencies_parsed_at":"2024-10-27T00:02:03.142Z","dependency_job_id":"f607891a-d9fd-473e-a2b4-77b58ae46f40","html_url":"https://github.com/PumPum7/rust-database","commit_stats":null,"previous_names":["pumpum7/rust-database"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PumPum7%2Frust-database","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PumPum7%2Frust-database/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PumPum7%2Frust-database/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PumPum7%2Frust-database/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PumPum7","download_url":"https://codeload.github.com/PumPum7/rust-database/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247023716,"owners_count":20870933,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["database","rust"],"created_at":"2024-10-29T07:05:53.852Z","updated_at":"2026-01-24T11:38:40.927Z","avatar_url":"https://github.com/PumPum7.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Database Project\n\nA Rust-based database system with ACID transaction support, MVCC, and a client-server architecture.\n\n## Features\n\n- **ACID Transactions**: Full transaction support with BEGIN, COMMIT, and ROLLBACK\n- **Isolation Levels**: Read Committed and Repeatable Read isolation\n- **MVCC**: Multi-Version Concurrency Control for snapshot isolation\n- **Write-Ahead Logging**: ARIES-style WAL with checkpoints, compensation log records (CLRs), and 3-phase crash recovery (Analysis, Redo, Undo)\n- **B-Tree Index**: Efficient key-value storage and retrieval\n- **TCP Protocol**: Binary protocol for client-server communication\n- **Interactive CLI**: Command-line client with tab completion\n\n## Project Structure\n\n```\n.\n├── backend/              # Database server implementation\n│   └── src/\n│       ├── btree/        # B-tree index implementation\n│       ├── command/      # Command parsing and types\n│       ├── database_handler/  # Database operations\n│       ├── protocol/     # Network protocol (frames, connections)\n│       ├── server/       # TCP server and request handling\n│       ├── storage/      # Storage engine\n│       │   ├── buffer_pool.rs   # In-memory page cache\n│       │   ├── disk_manager.rs  # Disk I/O\n│       │   ├── mvcc.rs          # Multi-version concurrency control\n│       │   ├── transaction.rs   # Transaction and snapshot management\n│       │   ├── wal.rs           # Write-ahead logging\n│       │   └── value.rs         # Value types\n│       └── tests/        # Unit tests\n└── database-client/      # Interactive CLI client\n```\n\n## Getting Started\n\n```bash\n# Build the project\ncargo build\n\n# Start the server (default port: 5432)\ncargo run --bin server\n\n# In another terminal, start the client\ncargo run --package database-client\n```\n\n## Commands\n\n### Basic Operations\n\n| Command | Description |\n|---------|-------------|\n| `GET \u003ckey\u003e` | Retrieve value by key |\n| `SET \u003ckey\u003e \u003cvalue\u003e` | Store a key-value pair |\n| `UPDATE \u003ckey\u003e \u003cvalue\u003e` | Update existing value |\n| `DEL \u003ckey\u003e` | Delete a key-value pair |\n| `ALL` | List all key-value pairs |\n\n### String Operations\n\n| Command | Description |\n|---------|-------------|\n| `STRLEN \u003ckey\u003e` | Get string length |\n| `STRCAT \u003ckey\u003e \u003cvalue\u003e` | Append to string value |\n| `SUBSTR \u003ckey\u003e \u003cstart\u003e \u003clen\u003e` | Extract substring |\n\n### Transaction Commands\n\n| Command | Description |\n|---------|-------------|\n| `BEGIN [isolation]` | Start transaction (returns txn_id) |\n| `COMMIT` | Commit current transaction |\n| `ROLLBACK` | Abort current transaction |\n\nIsolation levels: `read_committed` or `rc` (default), `repeatable_read` or `rr`\n\n### Maintenance Commands\n\n| Command | Description |\n|---------|-------------|\n| `VACUUM` | Run garbage collection on old versions |\n| `PING` | Test server connectivity |\n\n### Transactional Operations\n\nCommands can be executed within a transaction using the `TXN \u003cid\u003e` suffix:\n\n```\nBEGIN rr                 # Returns: 1 (RepeatableRead isolation)\nSET 1 100 TXN 1          # Insert within transaction\nSET 2 200 TXN 1          # Another insert\nGET 1 TXN 1              # Read within transaction (sees own writes)\nALL TXN 1                # List all within transaction snapshot\nCOMMIT                   # Commit all changes\n```\n\nRead commands that support transaction context:\n- `GET \u003ckey\u003e [TXN \u003cid\u003e]`\n- `ALL [TXN \u003cid\u003e]`\n- `STRLEN \u003ckey\u003e [TXN \u003cid\u003e]`\n\n### Expression Evaluation\n\n```\nEXPR(GET 1 + GET 2)      # Add values of key 1 and 2\nSET 3 EXPR(GET 1 * 2)    # Set key 3 to double of key 1\nEXPR(GET 1 + 3.14)       # Mix keys and literals\n```\n\n## Architecture\n\n```\n┌─────────────────────────────────────────────────────────────┐\n│                      Client Layer                            │\n│              TCP Connection + Binary Protocol                │\n└─────────────────────────────────────────────────────────────┘\n                            │\n┌─────────────────────────────────────────────────────────────┐\n│                   Transaction Layer                          │\n│  ┌─────────────┐ ┌──────────────┐ ┌──────────────────────┐  │\n│  │ Isolation   │ │   Snapshot   │ │ Transaction Manager  │  │\n│  │ RC/RR/Ser   │ │  Visibility  │ │   Active/Committed   │  │\n│  └─────────────┘ └──────────────┘ └──────────────────────┘  │\n└─────────────────────────────────────────────────────────────┘\n                            │\n┌─────────────────────────────────────────────────────────────┐\n│                      MVCC Layer                              │\n│         VersionedValue { value, xmin, xmax }                 │\n└─────────────────────────────────────────────────────────────┘\n                            │\n┌─────────────────────────────────────────────────────────────┐\n│                    Storage Layer                             │\n│  B-Tree Index → Buffer Pool → Disk Manager → WAL            │\n└─────────────────────────────────────────────────────────────┘\n```\n\n## MVCC (Multi-Version Concurrency Control)\n\nThe database uses MVCC to provide snapshot isolation:\n\n- **Version Tracking**: Each value stores `xmin` (creating transaction) and `xmax` (deleting transaction)\n- **Visibility Rules**: Transactions only see versions created by committed transactions before their snapshot\n- **No Read Locks**: Readers never block writers; writers never block readers\n- **Garbage Collection**: Use `VACUUM` to clean up old versions no longer visible to any transaction\n\n### Isolation Levels\n\n| Level | Description |\n|-------|-------------|\n| Read Committed (`rc`) | Each statement sees latest committed data |\n| Repeatable Read (`rr`) | Transaction sees consistent snapshot from start |\n\n### Example: Repeatable Read Isolation\n\n```\n# Terminal 1                    # Terminal 2\nBEGIN rr                        \nGET 1                           # Returns: 100\n                                UPDATE 1 200\n                                COMMIT\nGET 1                           # Still returns: 100 (snapshot)\nCOMMIT\nGET 1                           # Now returns: 200\n```\n\n## Development\n\n```bash\n# Run all tests\ncargo test\n\n# Run specific test module\ncargo test btree_tests\ncargo test transaction_tests\ncargo test mvcc_tests\n\n# Run a single test\ncargo test test_btree_operations -- --exact\n\n# Format code\ncargo fmt\n\n# Run linter\ncargo clippy\n```\n\n## Value Types\n\nThe database supports multiple value types:\n\n- `Integer(i64)` - 64-bit signed integers\n- `Float(f64)` - 64-bit floating point\n- `String(String)` - UTF-8 strings\n- `Boolean(bool)` - true/false\n- `Null` - null value\n\n## Configuration\n\nCurrently hardcoded defaults (configuration file support planned):\n\n| Setting | Default |\n|---------|---------|\n| Server port | 5432 |\n| Buffer pool size | 1000 pages |\n| Page size | 4KB |\n| Thread pool size | 4 |\n\n## Contributing\n\nContributions are welcome! Please feel free to submit a Pull Request.\n\n## License\n\nSee [LICENSE](LICENSE) file.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpumpum7%2Frust-database","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpumpum7%2Frust-database","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpumpum7%2Frust-database/lists"}