starshard

Starshard 2.x vs 1.x: Usage Differences

1. Scope

This document focuses on usage-level differences and migration guidance.

2. Quick Summary

3. High-Level Differences

Area 1.x 2.x
Shard-count safety very large shard_count could cause memory pressure default MAX_SHARDS guard, plus strict constructors
Constructor strategy mostly direct constructors compatibility + capped + strict constructor paths
Dynamic rebalance not available rebalance_to, start_rebalance_online, advance_rebalance
Snapshot strategy traditional path SnapshotMode::{Clone, Cached, Cow}
Migration effort - low for default usage, incremental for advanced usage

4. Detailed Usage Changes

4.1 Constructor and Shard Safety (2.0.0)

New practical behavior in 2.x:

Recommended for external/user-driven configs:

use starshard::ShardedHashMap;
use rustc_hash::FxBuildHasher;

let map = ShardedHashMap::<String, i32>::try_with_shards_and_hasher_capped(
    4096,
    FxBuildHasher,
    8192,
)?;

Migration note:

4.2 Rebalance APIs (2.1+)

1.x has no dynamic rebalance APIs.

2.1+ adds:

use starshard::{RebalanceOptions, ShardedHashMap};

let m: ShardedHashMap<String, i32> = ShardedHashMap::new(8);
m.rebalance_to(32, RebalanceOptions::default())?;

4.3 Snapshot Mode Selection (2.2+)

2.2+ makes snapshot strategy explicit:

And adds mode-aware constructors:

use starshard::{ShardedHashMap, SnapshotMode};

let map: ShardedHashMap<String, i32> =
    ShardedHashMap::with_snapshot_mode(64, SnapshotMode::Cached);

4.4 Performance-Relevant Behavior

These are mostly transparent to callers.

4.5 Upgrading from 2.3.x to 2.4.0

Existing CRUD and Entry signatures remain available. New APIs include shared_snapshot(), get_borrowed, contains_borrowed, remove_borrowed, and read_with.

Run the feature combinations you deploy and remeasure workload-specific latency, throughput, and memory. Allocation/hash reductions are not a universal throughput or p99 guarantee.

4.6 Upgrading from 2.4.0 to 2.4.1

This patch preserves existing public API signatures and error variants. It closes entry-loss windows when user hashing/cloning fails during promotion, extends unwind-safe length/cache accounting to single-key and transaction mutations, and prepares all replica operation copies before dispatch. Async memory statistics include both shard generations, and rebalance status is captured coherently.

User code panicking during a transaction does not roll back earlier operations. Replica preparation failure leaves an applied local write in place and returns QuorumFailed without partial remote fanout. These are recovery boundaries, not an unconditional guarantee for reentrant callbacks, double panics, or non-cooperative tasks.

The release also refreshes dependencies, including Tokio 1.54.1. Existing limitations remain: no autonomous TTL/eviction scheduler, no measured lock profiling, no enforced migration time budget, and no consensus or quorum reads. Workload-specific throughput/p99 and live replica fault behavior still require deployment validation.

5. Feature Flag Reminder

If migrating from early 1.x, re-check Cargo.toml feature selection:

[dependencies]
starshard = { version = "2.4.1", features = ["async", "rayon", "serde", "lifecycle", "advanced"] }

6. Migration Checklist

  1. Upgrade dependency to 2.x (recommended: 2.4.x).
  2. Review constructor entry points:
    • external input -> use try_with_*
    • fixed internal params -> compatibility constructors are fine
  3. Adopt rebalance APIs only if you need runtime shard transitions.
  4. Evaluate SnapshotMode::Cached / Cow for snapshot-heavy workloads.
  5. Run validation:
    • cargo test --all-features
    • workload-specific latency/throughput/memory checks

7. Compatibility Conclusion