Implemented the complete HTTP proxy layer with full Meilisearch API compatibility.
## Core Components
**HTTP Server (main.rs)**
- axum server on port 7700 with metrics endpoint on port 9090
- Graceful shutdown handling for SIGINT/SIGTERM
- Structured JSON logging middleware
- Prometheus metrics collection
**Write Path (documents.rs, write.rs, scatter.rs)**
- Hash-based sharding using XxHash64 (seed 0) for primary key → shard mapping
- Automatic injection of _miroir_shard field into all documents
- Fan-out to RG × RF nodes per replica group
- Per-group quorum enforcement (floor(RF/2)+1)
- X-Miroir-Degraded header when any group misses quorum
- 503 miroir_no_quorum only when no group met quorum
- Orchestrator-side retry cache for idempotency
**Read Path (search.rs, merger.rs)**
- Replica group selection via query_seq % RG (round-robin)
- Intra-group covering set construction for all shards
- Parallel scatter to covering set nodes
- Global result merge by _rankingScore descending
- Offset/limit applied AFTER merge (global ordering preserved)
- Automatic stripping of _miroir_* reserved fields
- Conditional stripping of _rankingScore (only if not requested)
- Facet aggregation across shards (sum counts)
- Group fallback when covering set has holes
**Index Lifecycle (indexes.rs, settings.rs)**
- Create: broadcasts to all nodes + injects _miroir_shard into filterableAttributes
- Settings: sequential apply-with-rollback on failure
- Delete: broadcasts to all nodes
- Stats: aggregates numberOfDocuments (max) + fieldDistribution (merge)
**Tasks (tasks.rs, task_manager.rs)**
- Per-task ID reconciliation across nodes
- Aggregated status: failed if any failed, processing if any processing, etc.
- Node completion tracking in task metadata
**Error Handling (error_response.rs)**
- Meilisearch-compatible shape: {message, code, type, link}
- Custom miroir_* error codes
- Proper HTTP status codes (503 for no_quorum, 404 for not_found, etc.)
**Auth (auth.rs)**
- Bearer token dispatch per plan §5 rules 2-5
- master-key: full access to all endpoints
- admin-key: admin-only endpoints (/admin/*, /_miroir/*)
- No token: public endpoints only (/health, /version)
- Invalid token: 403 Forbidden
**Admin Endpoints (admin.rs, health.rs)**
- GET /health - public health check
- GET /version - version info
- GET /_miroir/ready - readiness check (requires healthy nodes)
- GET /_miroir/topology - cluster topology with node health
- GET /_miroir/shards - shard assignment information
- GET /_miroir/metrics - Prometheus metrics (admin-key gated)
- GET /admin/stats - aggregated stats across all nodes
## Bug Fixes
This commit includes several bug fixes:
- Fixed query value extraction before moving req in search.rs
- Fixed JSON deserialization in settings.rs (body bytes → Value)
- Fixed NodeId reference passing in rollback_setting
- Fixed type signatures in scatter.rs (headers slice, error types)
- Fixed response body handling in scatter (use bytes directly)
## Testing
Integration tests written in tests/phase2_integration_test.rs:
- test_1000_documents_indexed_retrievable_by_id
- test_unique_keyword_search_finds_all_docs_once
- test_facet_aggregation_sums_correctly
- test_offset_limit_paging_preserves_global_ordering
- test_write_with_degraded_group_succeeds_with_header
- test_topology_endpoint_shape
- test_error_format_parity
- test_index_stats_aggregation
Tests marked #[ignore] as they require running Meilisearch nodes.
## Definition of Done
- [x] axum server on port 7700, metrics on 9090
- [x] Write path with hash, _miroir_shard injection, fan-out, quorum
- [x] Read path with group selection, covering set, merge, fallback
- [x] Index lifecycle with broadcast, settings rollback, delete, stats
- [x] Tasks with ID reconciliation and aggregation
- [x] Meilisearch-compatible error format
- [x] Reserved fields contract (_miroir_shard always-reserved)
- [x] Bearer token auth (master-key, admin-key)
- [x] /health, /version, /_miroir/* endpoints
- [x] Structured JSON logging + Prometheus metrics
- [x] Scatter-gather with retry cache
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
- Fix JSON response parsing in documents and indexes routes
- Ensure proper serde_json deserialization of proxy responses
- Improve error handling for malformed responses
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Update scatter.rs to use async_trait for async scatter execution.
This allows the scatter implementation to perform async I/O when
fanning out requests to nodes.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
- Remove openraft dependency (validit crate uses unstable let_chains)
- Comment out raft-proto module temporarily
- Fix benchmark targets: [[bin]] → [[bench]] to resolve duplicate target warnings
- Update Cargo.lock with dependency changes
This fixes the clippy --all-features build that was failing due to
openraft 0.9.22 not compiling on stable Rust 1.87.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
- Add resharding load simulation model with real router hash functions
- Benchmark confirms storage amplification is exactly 2.0× and dual-write
amplification is exactly 2.0× across all test matrix scenarios (1KB/10GB,
10KB/100GB, 1MB/1TB), with hash distribution CV < 5% in all cases
- CLI window guard: resharding.allowed_windows config restricts resharding
to named time windows (e.g. "02:00-06:00 UTC"), CLI refuses outside
windows without --force
- Integration tests confirm rejection outside window, --force override,
no-restriction mode, and disabled config handling
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
- LICENSE: MIT (per plan §12)
- CHANGELOG.md: Keep a Changelog 1.1.0 skeleton with [Unreleased]
and [0.1.0] sections matching the awk extractor from plan §7
- .gitignore: Rust target/, editor junk; Cargo.lock kept in VCS
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>