* add Jemalloc * feat: optimize AI rules with unified .rules.md (#401) * feat: optimize AI rules with unified .rules.md and entry points - Create .rules.md as the central AI coding rules file - Add .copilot-rules.md as GitHub Copilot entry point - Add CLAUDE.md as Claude AI entry point - Incorporate principles from rustfs.com project - Add three critical rules: 1. Use English for all code comments and documentation 2. Clean up temporary scripts after use 3. Only make confident modifications * Update CLAUDE.md --------- Co-authored-by: Cursor Agent <cursoragent@cursor.com> * feat: translate chinese to english (#402) * Checkpoint before follow-up message Co-authored-by: anzhengchao <anzhengchao@gmail.com> * Translate project documentation and comments from Chinese to English Co-authored-by: anzhengchao <anzhengchao@gmail.com> * Fix typo: "unparseable" to "unparsable" in version test comment Co-authored-by: anzhengchao <anzhengchao@gmail.com> * Refactor compression test code with minor syntax improvements Co-authored-by: anzhengchao <anzhengchao@gmail.com> --------- Co-authored-by: Cursor Agent <cursoragent@cursor.com> * fix: the automatic logout issue and user list display failure on Windows systems (#353) (#343) (#403) Co-authored-by: 安正超 <anzhengchao@gmail.com> * upgrade version * improve code for profiling * fix * Initial plan * feat: Implement layered DNS resolver with caching and validation Co-authored-by: houseme <4829346+houseme@users.noreply.github.com> * feat: Integrate DNS resolver into main application and fix formatting Co-authored-by: houseme <4829346+houseme@users.noreply.github.com> * feat: Implement enhanced DNS resolver with Moka cache and layered fallback Co-authored-by: houseme <4829346+houseme@users.noreply.github.com> * feat: Implement hickory-resolver with TLS support for enhanced DNS resolution Co-authored-by: houseme <4829346+houseme@users.noreply.github.com> * upgrade * add .gitignore config * fix * add * add * up * improve linux profiling * fix * fix * fix * feat(admin): Refactor profiling endpoints Replaces the existing pprof profiling endpoints with new trigger-based APIs for CPU and memory profiling. This change simplifies the handler logic by moving the profiling implementation to a dedicated module. A new handler file `admin/handlers/profile.rs` is created to contain the logic for these new endpoints. The core profiling functions are now expected to be in the `profiling` module, which the new handlers call to generate and save profile data. * cargo shear --fix * fix * fix * fix --------- Co-authored-by: 安正超 <anzhengchao@gmail.com> Co-authored-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: shiro.lee <69624924+shiroleeee@users.noreply.github.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: houseme <4829346+houseme@users.noreply.github.com>
12 KiB
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Project Overview
RustFS is a high-performance distributed object storage software built with Rust, providing S3-compatible APIs and advanced features like data lakes, AI, and big data support. It's designed as an alternative to MinIO with better performance and a more business-friendly Apache 2.0 license.
Build Commands
Primary Build Commands
cargo build --release- Build the main RustFS binary./build-rustfs.sh- Recommended build script that handles console resources and cross-platform compilation./build-rustfs.sh --dev- Development build with debug symbolsmake buildorjust build- Use Make/Just for standardized builds
Platform-Specific Builds
./build-rustfs.sh --platform x86_64-unknown-linux-musl- Build for musl target./build-rustfs.sh --platform aarch64-unknown-linux-gnu- Build for ARM64make build-muslorjust build-musl- Build musl variantmake build-cross-all- Build all supported architectures
Testing Commands
cargo test --workspace --exclude e2e_test- Run unit tests (excluding e2e tests)cargo nextest run --all --exclude e2e_test- Use nextest if available (faster)cargo test --all --doc- Run documentation testsmake testorjust test- Run full test suitemake pre-commit- Run all quality checks (fmt, clippy, check, test)
End-to-End Testing
cargo test --package e2e_test- Run all e2e tests./scripts/run_e2e_tests.sh- Run e2e tests via script./scripts/run_scanner_benchmarks.sh- Run scanner performance benchmarks
KMS-Specific Testing (with proxy bypass)
NO_PROXY=127.0.0.1,localhost HTTP_PROXY= HTTPS_PROXY= http_proxy= https_proxy= cargo test --package e2e_test test_local_kms_end_to_end -- --nocapture --test-threads=1 -
Run complete KMS end-to-end test
NO_PROXY=127.0.0.1,localhost HTTP_PROXY= HTTPS_PROXY= http_proxy= https_proxy= cargo test --package e2e_test kms:: -- --nocapture --test-threads=1 -
Run all KMS tests
cargo test --package e2e_test test_local_kms_key_isolation -- --nocapture --test-threads=1- Test KMS key isolationcargo test --package e2e_test test_local_kms_large_file -- --nocapture --test-threads=1- Test KMS with large files
Code Quality
cargo fmt --all- Format codecargo clippy --all-targets --all-features -- -D warnings- Lint codemake pre-commitorjust pre-commit- Run all quality checks (fmt, clippy, check, test)
Quick Development Commands
make helporjust help- Show all available commands with descriptionsmake help-build- Show detailed build options and cross-compilation helpmake help-docker- Show comprehensive Docker build and deployment options./scripts/dev_deploy.sh <IP>- Deploy development build to remote server./scripts/run.sh- Start local development server./scripts/probe.sh- Health check and connectivity testing
Docker Build Commands
make docker-buildx- Build multi-architecture production imagesmake docker-dev-local- Build development image for local use./docker-buildx.sh --push- Build and push production images
Architecture Overview
Core Components
Main Binary (rustfs/):
- Entry point at
rustfs/src/main.rs - Core modules: admin, auth, config, server, storage, license management, profiling
- HTTP server with S3-compatible APIs
- Service state management and graceful shutdown
- Parallel service initialization with DNS resolver, bucket metadata, and IAM
Key Crates (crates/):
ecstore- Erasure coding storage implementation (core storage layer)iam- Identity and Access Managementkms- Key Management Service for encryption and key handlingmadmin- Management dashboard and admin API interfaces3select-api&s3select-query- S3 Select API and query engineconfig- Configuration management with notify featurescrypto- Cryptography and security featureslock- Distributed locking implementationfilemeta- File metadata managementrio- Rust I/O utilities and abstractionscommon- Shared utilities and data structuresprotos- Protocol buffer definitionsaudit-logger- Audit logging for file operationsnotify- Event notification systemobs- Observability utilitiesworkers- Worker thread pools and task schedulingappauth- Application authentication and authorizationahm- Asynchronous Hash Map for concurrent data structuresmcp- MCP server for S3 operationssigner- Client request signing utilitieschecksums- Client checksum calculation utilitiesutils- General utility functions and helperszip- ZIP file handling and compressiontargets- Target-specific configurations and utilities
Build System
- Cargo workspace with 25+ crates (including new KMS functionality)
- Custom
build-rustfs.shscript for advanced build options - Multi-architecture Docker builds via
docker-buildx.sh - Both Make and Just task runners supported with comprehensive help
- Cross-compilation support for multiple Linux targets
- Automated CI/CD with GitHub Actions for testing, building, and Docker publishing
- Performance benchmarking and audit workflows
Key Dependencies
axum- HTTP framework for S3 API servertokio- Async runtimes3s- S3 protocol implementation librarydatafusion- For S3 Select query processinghyper/hyper-util- HTTP client/server utilitiesrustls- TLS implementationserde/serde_json- Serializationtracing- Structured logging and observabilitypprof- Performance profiling with flamegraph supporttikv-jemallocator- Memory allocator for Linux GNU builds
Development Workflow
- Console resources are embedded during build via
rust-embed - Protocol buffers generated via custom
gprotobinary - E2E tests in separate crate (
e2e_test) with comprehensive KMS testing - Shadow build for version/metadata embedding
- Support for both GNU and musl libc targets
- Development scripts in
scripts/directory for common tasks - Git hooks setup available via
make setup-hooksorjust setup-hooks
Performance & Observability
- Performance profiling available with
pprofintegration (disabled on Windows) - Profiling enabled via environment variables in production
- Built-in observability with OpenTelemetry integration
- Background services (scanner, heal) can be controlled via environment variables:
RUSTFS_ENABLE_SCANNER(default: true)RUSTFS_ENABLE_HEAL(default: true)
Service Architecture
- Service state management with graceful shutdown handling
- Parallel initialization of core systems (DNS, bucket metadata, IAM)
- Event notification system with MQTT and webhook support
- Auto-heal and data scanner for storage integrity
- Jemalloc allocator for Linux GNU targets for better performance
Environment Variables
RUSTFS_ENABLE_SCANNER- Enable/disable background data scanner (default: true)RUSTFS_ENABLE_HEAL- Enable/disable auto-heal functionality (default: true)- Various profiling and observability controls
- Build-time variables for Docker builds (RELEASE, REGISTRY, etc.)
- Test environment configurations in
scripts/dev_rustfs.env
KMS Environment Variables
NO_PROXY=127.0.0.1,localhost- Required for KMS E2E tests to bypass proxyHTTP_PROXY=HTTPS_PROXY=http_proxy=https_proxy=- Clear proxy settings for local KMS testing
KMS (Key Management Service) Architecture
KMS Implementation Status
- Full KMS Integration: Complete implementation with Local and Vault backends
- Automatic Configuration: KMS auto-configures on startup with
--kms-enableflag - Encryption Support: Full S3-compatible server-side encryption (SSE-S3, SSE-KMS, SSE-C)
- Admin API: Complete KMS management via HTTP admin endpoints
- Production Ready: Comprehensive testing including large files and key isolation
KMS Configuration
- Local Backend:
--kms-backend local --kms-key-dir <path> --kms-default-key-id <id> - Vault Backend:
--kms-backend vault --kms-vault-endpoint <url> --kms-vault-key-name <name> - Auto-startup: KMS automatically initializes when
--kms-enableis provided - Manual Configuration: Also supports dynamic configuration via admin API
S3 Encryption Support
- SSE-S3: Server-side encryption with S3-managed keys (
ServerSideEncryption: AES256) - SSE-KMS: Server-side encryption with KMS-managed keys (
ServerSideEncryption: aws:kms) - SSE-C: Server-side encryption with customer-provided keys
- Response Headers: All encryption types return correct
server_side_encryptionheaders in PUT/GET responses
KMS Testing Architecture
- Comprehensive E2E Tests: Located in
crates/e2e_test/src/kms/ - Test Environments: Automated test environment setup with temporary directories
- Encryption Coverage: Tests all three encryption types (SSE-S3, SSE-KMS, SSE-C)
- API Coverage: Tests all KMS admin APIs (CreateKey, DescribeKey, ListKeys, etc.)
- Edge Cases: Key isolation, large file handling, error scenarios
Key Files for KMS
crates/kms/- Core KMS implementation with Local/Vault backendsrustfs/src/main.rs- KMS auto-initialization ininit_kms_system()rustfs/src/storage/ecfs.rs- SSE encryption/decryption in PUT/GET operationsrustfs/src/admin/handlers/kms*.rs- KMS admin endpointscrates/e2e_test/src/kms/- Comprehensive KMS test suitecrates/rio/src/encrypt_reader.rs- Streaming encryption for large files
Code Style and Safety Requirements
- Language Requirements:
- Communicate with me in Chinese, but only English can be used in code files
- Code comments, function names, variable names, and all text in source files must be in English only
- No Chinese characters, emojis, or non-ASCII characters are allowed in any source code files
- This includes comments, strings, documentation, and any other text within code files
- Safety-Critical Rules:
unsafe_code = "deny"enforced at workspace level- Never use
unwrap(),expect(), or panic-inducing code except in tests - Avoid blocking I/O operations in async contexts
- Use proper error handling with
Result<T, E>andOption<T> - Follow Rust's ownership and borrowing rules strictly
- Performance Guidelines:
- Use
cargo clippy --all-targets --all-features -- -D warningsto catch issues - Prefer
anyhowfor error handling in applications,thiserrorfor libraries - Use appropriate async runtimes and avoid blocking calls
- Use
- Testing Standards:
- All new features must include comprehensive tests
- Use
#[cfg(test)]for test-only code that may use panic macros - E2E tests should cover KMS integration scenarios
Common Development Tasks
Running KMS Tests Locally
- Clear proxy settings: KMS tests require direct localhost connections
- Use serial execution:
--test-threads=1prevents port conflicts - Enable output:
--nocaptureshows detailed test logs - Full command:
NO_PROXY=127.0.0.1,localhost HTTP_PROXY= HTTPS_PROXY= http_proxy= https_proxy= cargo test --package e2e_test test_local_kms_end_to_end -- --nocapture --test-threads=1
KMS Development Workflow
- Code changes: Modify KMS-related code in
crates/kms/orrustfs/src/ - Compile: Always run
cargo buildafter changes - Test specific functionality: Use targeted test commands for faster iteration
- Full validation: Run complete end-to-end tests before commits
Debugging KMS Issues
- Server startup: Check that KMS auto-initializes with debug logs
- Encryption failures: Verify SSE headers are correctly set in both PUT and GET responses
- Test failures: Use
--nocaptureto see detailed error messages - Key management: Test admin API endpoints with proper authentication
Important Reminders
- Always compile after code changes: Use
cargo buildto catch errors early - Don't bypass tests: All functionality must be properly tested, not worked around
- Use proper error handling: Never use
unwrap()orexpect()in production code (except tests) - Follow S3 compatibility: Ensure all encryption types return correct HTTP response headers
important-instruction-reminders
Do what has been asked; nothing more, nothing less. NEVER create files unless they're absolutely necessary for achieving your goal. ALWAYS prefer editing an existing file to creating a new one. NEVER proactively create documentation files (*.md) or README files. Only create documentation files if explicitly requested by the User.