Skip to content

Commit e915efe

Browse files
docs(nns): Add a comment regarding routing table shards (#5806)
Better document the invariants for routing table shards so that it's clearer that tests set up with a single shard key `make_canister_ranges_key(CanisterId::from_u64(0))` is correct. It should also help with future functionalities where shards are partially read (e.g. binary search a specific shard)
1 parent a5673c2 commit e915efe

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

rs/registry/canister/src/mutations/routing_table.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,32 @@ impl std::fmt::Display for GetSubnetForCanisterError {
3939

4040
const MAX_RANGES_PER_CANISTER_RANGES: u16 = 20;
4141

42+
/// Returns a list of mutations of routing table shards so that applying them to the registry will
43+
/// result in the routing table (represented as routing table shards) being updated to the given new
44+
/// routing table.
45+
///
46+
/// Invariants that should hold before and after the mutations:
47+
///
48+
/// * each shard is a valid routing table - the canister ranges in the entries are sorted and
49+
/// disjoint.
50+
/// * for each shard, the start canister id of the first entry *is larger than or equal* to the
51+
/// canister id in the shard key.
52+
/// * for each shard, the end canister id of the last entry + 1 *is smaller than or equal to* the
53+
/// canister id in the next shard key.
54+
///
55+
/// Note that the method does not require the following invariants:
56+
///
57+
/// * for the last two invariants, we do not require equality as a precondition, even though the
58+
/// method should produce mutations that result in equality except for the shard key with
59+
/// `CanisterId(0)`.
60+
/// * each shard can have more than `MAX_RANGES_PER_CANISTER_RANGES` entries, even though this
61+
/// method should produce mutations that result in <= `MAX_RANGES_PER_CANISTER_RANGES` entries for
62+
/// each shard.
63+
///
64+
/// Relaxing the invariants as preconditions does not make it more difficult to compute the
65+
/// mutations, while it helps with setting up tests, since a single shard with all the entries can
66+
/// be inserted with a smallest possible shard key, i.e., `CanisterId::from_u64(0)`.
67+
///
4268
/// Complexity O(n)
4369
fn mutations_for_canister_ranges(
4470
registry: &Registry,

0 commit comments

Comments
 (0)