All notable changes to this project will be documented in this file.
- Added Entry-style APIs for sync and async maps:
ShardedHashMap::entry(...) -> EntryAsyncShardedHashMap::entry(...).await -> AsyncEntryEntry::{or_insert, or_insert_with, and_modify, insert, remove}OccupiedEntry/VacantEntryand async equivalents
- Added atomic get-or-create helpers for sync and async maps:
ShardedHashMap::get_or_insert_with(...)AsyncShardedHashMap::get_or_insert_with(...).await
- Unified
compute_if_absent,get_or_insert_with, and Entry insertion paths through a shared internal hot path to avoid patch-on-patch public API forwarding. - Preserved online-rebalance fallback semantics for get-or-create operations, including active-first + previous-shard fallback lookup.
- Pinned dependency version requirements and refreshed the lockfile for the release.
- Included examples and integration tests in the packaged crate so declared targets resolve cleanly during packaging.
- Added sync and async coverage for Entry operations, atomic get-or-insert behavior, concurrent single-initializer execution, COW snapshot updates, and online rebalance fallback behavior.
- Simplified the optional Tokio dependency used by the
asyncfeature tort+sync, so downstream users are no longer forced onto Tokio's multi-thread runtime. - Made the dev Tokio dependency explicit with
default-features = falsewhile keepingmacros,rt-multi-thread, andsyncfor tests and examples. - Refreshed dependency lock state for the release.
- Refactored
lib.rsinto focused modules:types.rs,error.rs,rebalance.rs. - Extracted tests into
tests/module withsync.rs,async_tests.rs,batch.rs,snapshot.rs. lib.rsreduced from 1349 to 290 lines (-78.5%).
- Added module-level doc comments (
//!) to all source modules (types,error,rebalance,core,serde). - Added doc comments to all complex private functions in
core/sync_impl.rsandcore/async_impl.rs. - Added doc comments to
core/helpers.rsutility functions (std_read_guard,std_write_guard,normalized_shard_count,strict_shard_count,capped_shard_count). - Added doc comments to
RebalanceTrackerinternals inrebalance.rs. - Added inline comments explaining COW merge algorithm (3-phase), iteration branching (epoch cache / COW / standard / rayon), and batch operation migration fallback.
- Snapshot mode APIs (sync + async):
- Added
SnapshotMode::{Clone, Cached, Cow}. - Added constructors:
with_snapshot_mode(...)with_shards_and_hasher_and_snapshot_mode(...)with_shards_and_hasher_capped_and_snapshot_mode(...)
- Added write epoch + snapshot cache flow for repeated snapshot reads.
- Added COW snapshot shard path for snapshot-heavy workloads.
- Added snapshot mode benchmark groups in
benches/bench_main.rs. - Added snapshot mode examples:
snapshot_mode_clone_demosnapshot_mode_cached_demosnapshot_mode_cow_demomixed_workload_snapshot_tradeoff_demo
- Added
- Snapshot concurrency hardening:
- Eliminated snapshot cache race windows in sync/async paths.
- Strengthened COW snapshot + rebalance interaction consistency under concurrent writes.
- Refined snapshot/rebalance internal flow to reduce patch-on-patch branching in hot paths.
- Updated release documentation and roadmap status to
v2.2.0. - Refreshed snapshot mode guidance and runnable examples in
README.mdandREADME_CN.md.
- Adaptive rebalance APIs (sync + async):
- Added stop-the-world rebalance:
ShardedHashMap::rebalance_to(...)AsyncShardedHashMap::rebalance_to(...).await
- Added online incremental rebalance lifecycle:
start_rebalance_online(...)advance_rebalance(...)
- Added status snapshot API:
rebalance_status() -> RebalanceStatus
- Added data models:
RebalanceOptionsRebalanceReportRebalanceStatus
- Added stop-the-world rebalance:
- Routing internals for shard expansion:
- Reworked internal shard-count storage to allow safe runtime shard-count transitions.
- Added previous-epoch shard storage for online migration fallback reads.
- Updated read/write paths so online migration follows active-first, previous-fallback semantics.
- Added rebalance test coverage for:
- stop-the-world sync/async migration correctness
- status lifecycle correctness
- online incremental sync/async migration path
-
Version bump:
- Crate version updated from
1.2.0to2.0.0.
- Crate version updated from
-
Shard safety hardening (public API + behavior update):
- Added
MAX_SHARDSdefault hard cap to guard infallible constructors against oversized allocations. - Added
ShardCountErrorand strict constructors:try_with_shards_and_hasher(...)andtry_with_shards_and_hasher_capped(...)for both sync and async maps. - Added capped constructors:
with_shards_and_hasher_capped(...)for both sync and async maps. - Updated constructor behavior so oversized requests are clamped (infallible constructors) or rejected (strict constructors) instead of allocating unbounded shard vectors.
- Added
-
Internal architecture refactor:
- Split core sync implementation out of
src/lib.rsintosrc/core/sync_impl.rs. - Split core async implementation out of
src/lib.rsintosrc/core/async_impl.rs. - Extracted serde implementation into
src/serde/sync_serde.rsandsrc/serde/async_snapshot.rs. - Added core internal split files:
src/core/types.rsandsrc/core/helpers.rs. - Reduced
lib.rscomplexity by moving implementation details into focused modules.
- Split core sync implementation out of
-
Batch-path performance optimization:
- Reworked sync/async
batch_insert,batch_remove, andbatch_getgrouping to sparse per-touched-shard buckets. - Eliminated shard-count-sized per-call bucket preallocation in batch grouping paths.
- Improved async
compute_if_presentto evaluate closure before removal, aligning sync/async behavior and avoiding unnecessary remove+reinsert work.
- Reworked sync/async
-
Refactor guardrails and verification scripts:
- Added
scripts/export_api_surface.shfor API-surface snapshot/export. - Added
scripts/verify_feature_matrix.shfor repeatable feature-matrix validation.
- Added
-
CI hardening:
- Added dedicated feature matrix job in GitHub Actions.
- Added dedicated doctest job in GitHub Actions.
- Updated
README.mdandREADME_CN.mdfor2.0.0version references. - Synced feature matrix and performance notes with current
v2.0implementation status.
- Lifecycle API completion:
- Added
memory_stats()forShardedHashMapandAsyncShardedHashMapunderlifecycle. - Added
drain()forShardedHashMapandAsyncShardedHashMapunderlifecycle. - Added async
per_shard_load()forAsyncShardedHashMapunderlifecycle.
- Added
- Tests:
- Added regression tests for shard empty-count accounting.
- Added lifecycle tests for memory stats and drain behavior (sync + async).
- Shard statistics correctness:
- Fixed
ShardStats.emptycalculation in both sync and asyncshard_stats()implementations.
- Fixed
- Updated
README.mdlifecycle section to match current implementation and added examples for:per_shard_load()(sync + async)memory_stats()(sync + async)drain()(sync + async)
-
Shard Introspection:
per_shard_load(): Returns detailed load statistics (PerShardLoad) for each initialized shard, including entry count and capacity. Available for bothShardedHashMapandAsyncShardedHashMapwhen thelifecyclefeature is enabled.
-
Logging:
- Added
#[tracing::instrument]to public APIs and core helpers across sync/async maps and lifecycle/advanced modules.
- Added
- Robust Error Handling:
- Replaced
unwrap()in shard initialization and transaction shard lookup with logged fallbacks; transactions abort safely on missing shard indices.
- Replaced
- Refactoring:
- Introduced shared std
RwLockguard helpers to reduce repetitive poisoned-lock handling.
- Introduced shared std
- Feature Consolidation:
- Merged
ttl,metrics, andadvanced-iterfeatures into a singlelifecyclefeature. - Merged
transactions,cas,cow-snapshot,replication, anddiagnosticsfeatures into a singleadvancedfeature. - Promoted
batchoperations to core functionality (removedbatchfeature flag). - Updated
fullfeature to includeasync,rayon,serde,lifecycle, andadvanced.
- Merged
- Batch Operations:
- Optimized
batch_insertandbatch_removeto acquire the shard lock only once per shard group, significantly reducing lock contention.
- Optimized
-
Atomic Transactions (MVCC-based):
Transaction<K, V>: Multi-key atomic operations with read/write/remove supportexecute_transaction(): Sync and async transaction execution with deadlock preventionTransactionResult<T>: Result enum (Committed, Aborted, Conflict)- Shard-level locking with sorted indices to prevent deadlocks
-
Compare-And-Swap (CAS) Operations:
compare_and_swap(key, expected, new): Atomic value replacementcompare_and_remove(key, expected): Conditional removalCasResult<V>: Success/Failure result with current value- Full support for both sync and async variants
-
Copy-On-Write Snapshots:
cow_snapshot(): Zero-allocation snapshot for read-heavy workloadsCowSnapshot<K, V>: Immutable snapshot with version tracking- Minimal lock contention during snapshot creation
- Iterator support with snapshot isolation guarantees
-
Snapshot Isolation & Versioning:
versioned_snapshot(): Create timestamped snapshots for time-travel queriessnapshot_at_version(version): Retrieve snapshot at specific versionIsolatedSnapshot<K, V>: Version-tagged snapshot with age tracking- Monotonic version counter for consistency
-
Lock Profiling & Diagnostics:
lock_profiles(): Per-shard lock contention statisticsenable_profiling(bool): Toggle profiling with minimal overheadLockProfile: Metrics including reads, writes, contention count, wait times- Runtime-configurable profiling for production diagnostics
-
Distributed Replication Framework (async only):
Replica<K, V>trait: Interface for custom replica implementationswith_replication(): Configure map with replica set and quoruminsert_replicated()/remove_replicated(): Quorum-based operationsReplicationOp<K, V>: Serializable operation types (Insert, Remove, Clear)QuorumConfig: Majority and strict quorum configurations- Parallel async replication with configurable timeouts
ReplicaError: Comprehensive error handling for replication failures
- Type Safety: All generic types use
'staticbounds for async compatibility - Zero External Dependencies: No
dashmaporparking_lot- uses onlyhashbrownand std library - Type Aliases:
ReplicaList<K, V>to reduce type complexity (clippy-clean) - Version Tracking:
Arc<AtomicUsize>for lock-free version increments - Feature Flags: All functionality behind
advancedfeature flag
- 40+ Test Cases: Comprehensive coverage for all features
- Transaction tests (5): basic commit, multi-shard, read ops, empty, async
- CAS tests (11): success/failure scenarios, multi-threaded, async variants
- CoW snapshot tests (6): creation, isolation, iteration, race conditions
- Versioned snapshot tests (8): ordering, version queries, time-travel
- Lock profiling tests (3): enable/disable, structure validation
- Replication tests (4): quorum configs, insert/remove operations
- Integration tests (3): cross-feature interactions
- Type complexity warning (clippy): Added
ReplicaList<K, V>type alias - Lifetime errors: Added
'staticbounds to K and V types for async compatibility - Test race conditions: Used
Barrierfor proper synchronization - Quorum validation: Corrected replica count matching in tests
- 14 detailed documentation files covering implementation and fixes
- API documentation with examples for all public methods
- Comprehensive test suite serving as usage examples
- Full async/await pattern documentation
- TTL & Eviction System:
EvictionPolicyenum: LRU, LFU, TimeToLive, Custom predicatesEvictionConfig: Configurable policy, max_entries, check intervals- Background eviction task with atomic control
- Per-shard eviction statistics tracking
- Metrics Collection:
MetricsStats: Comprehensive operation countersAtomicMetrics: Lock-free metrics aggregationMemoryStats: Memory utilization tracking- Hit rate calculation and snapshot functionality
reset_metrics(): Clear accumulated statistics
- Advanced Iteration Builders:
IterBuilder<K, V>: Fluent API for complex iteration patterns- Filter, limit, and parallel control
collect(),for_each()execution methods
- Drain Operation:
DrainIterator<K, V>: Efficient bulk removal- Lock-per-shard acquisition
- ExactSizeIterator implementation
- Zero intermediate allocation
- Extended Introspection:
memory_stats(): Shard allocation and load factorper_shard_load(): Per-shard entry counts- Detailed shard distribution metrics
- New feature flags:
ttl,metrics,advanced-iter - Type aliases for reduced complexity
- Comprehensive test suite (30+ tests)
- Performance benchmarking infrastructure
- Documentation examples for each feature
Cargo.toml:
- Added optional dependencies:
parking_lot - New feature flags for modular enablement
- Updated
fullfeature set
eviction.rs: TTL, eviction policies, metrics, advanced iteration frameworkadvanced.rs: Transactions, CAS, CoW snapshots, replication, diagnostics framework
- Conditional Update Operations: Efficient in-place updates with single shard lock
compute_if_present(): Update value only if key exists; remove if closure returns Nonecompute_if_absent(): Insert only if key is absent; return final value- Single lock acquisition per operation (no extra contention)
- Ideal for check-then-update patterns common in concurrent scenarios
- Batch Operations: Amortized lock acquisition for multiple keys
batch_insert(): Insert multiple key-value pairs in grouped shard batchesbatch_remove(): Remove multiple keys with efficient per-shard groupingbatch_get(): Fetch multiple keys in one call, preserving order
- Filtering & Retention:
retain(): Remove entries where predicate returns false (per-shard locking)
- Collection Views:
keys(): Iterate over all keys (snapshot-based)values(): Iterate over all values (snapshot-based)iter(): Full key-value pair iteration with optional rayon parallelism
- Shard Introspection:
shard_stats(): ReturnsShardStatswith detailed shard distribution metricsshard_utilization(): Percentage of initialized shards for capacity planning- Per-shard load tracking and distribution analysis
- Async Equivalents: All v0.8.0 methods available on
AsyncShardedHashMap
- New feature flags:
batch(Entry API provided as methods, not as traditional enum) - Conditional operations available on both
ShardedHashMapandAsyncShardedHashMap - Comprehensive test suite (50+ new unit tests for conditional operations, batch ops, filtering)
- Example programs:
v080_entry_api.rs(conditional operations & views),v080_async_batch.rs(async variants) - ROADMAP.md: Multi-version development plan (v0.8, v0.9, v1.0)
- IMPLEMENTATION_SUMMARY.md: Design decisions, architecture, performance characteristics
- add cross-platform test
- chore(deps): bump tokio from 1.48.0 to 1.49.0 and serde_json from 1.0.145 to 1.0.149
- set
starshardversion 0.6.0 - upgrade
actions/checkoutfromv5tov6 - upgrade crates version
- chore(deps): bump github/codeql-action from 3 to 4 (#1)
- Replace
fxhashwithrustc-hashfor improved hashing performance and compatibility
- improve for README
- feat(serde): finalize serde support, add async snapshot serialization, doc updates
- improve for v0.3.0
- rename async func
- fmt MIT License
- chore(init): bootstrap starshard crate (sync/async sharded HashMap)