src/storage/chunk_engine/README.md
Arc to manage ownership of chunk position:
Arc<ChunkPos>. If persistence fails, the position is automatically released when the Arc is dropped.Arc<ChunkPos>, ensuring safe data access even during concurrent writes or deletions.Storage hierarchy:
This configuration supports up to ~1.2 billion chunks and ~5 million groups per machine.
Implementation details:
uint64_t) to track allocation status.allocated_groups: Groups with allocated space but no chunks assigned.unallocated_groups: Groups without allocated space.active_groups: Map of <group_id, group_state> tracking allocation status.active_groups using __builtin_ctz for fast bitwise operations.active_groups is empty, acquire a new group from allocated_groups.allocated_groups is empty, fetch a group from unallocated_groups and allocate disk space synchronously.allocate_thread: Maintains active_groups within a target size range to ensure in-memory allocation efficiency.compact_thread: Periodically scans active_groups, migrates all chunks from selected groups, releases space, and returns groups to allocated_groups.Persists three mappings:
chunk_id -> chunk_meta: Metadata includes chunk location, length, hash, version, etc., serialized using derse.group_id -> group_state: Tracks chunk allocation status within groups, leveraging RocksDB's MergeOp for atomic updates.chunk_pos -> chunk_id: Maps physical positions to chunk IDs, used by compact_thread during chunk migration.chunk_id -> chunk_info mapping, where chunk_info includes chunk_meta and Arc<ChunkPos>.chunk_info. The Arc<ChunkPos> ensures safe data access until the read completes.MetaCache to retrieve the current chunk_info.Allocator::allocate() to obtain a new chunk position.new_chunk_info.new_chunk_info to the MetaStore along with a release record for the original chunk position.