1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
//! Wire-format namespace routing constants.
//!
//! Both the SDK encoder (which writes `RequestHeader.namespace`) and the
//! server-side sharding layer (which hashes it to a shard) must agree on
//! how stream/topic/partition triples pack into the namespace `u64`. Any
//! drift between the two silently routes writes to the wrong shard, so the
//! single source of truth lives here in the wire-format crate that both
//! sides already depend on.
pub const MAX_STREAMS: usize = 4096;
pub const MAX_TOPICS: usize = 4096;
pub const MAX_PARTITIONS: usize = 1_000_000;
pub const
pub const STREAM_BITS: u32 = bits_required;
pub const TOPIC_BITS: u32 = bits_required;
pub const PARTITION_BITS: u32 = bits_required;
pub const PARTITION_SHIFT: u32 = 0;
pub const TOPIC_SHIFT: u32 = PARTITION_SHIFT + PARTITION_BITS;
pub const STREAM_SHIFT: u32 = TOPIC_SHIFT + TOPIC_BITS;
pub const PARTITION_MASK: u64 = - 1;
pub const TOPIC_MASK: u64 = - 1;
pub const STREAM_MASK: u64 = - 1;
/// Total bits used by the packed namespace layout (stream | topic | partition).
/// Any `u64` whose set bits all sit within this range is a legal packable namespace.
pub const PACKED_NAMESPACE_BITS: u32 = STREAM_BITS + TOPIC_BITS + PARTITION_BITS;
/// Largest `u64` value producible by the packed layout.
/// Equivalent to `(1 << PACKED_NAMESPACE_BITS) - 1`.
pub const PACKED_NAMESPACE_MAX: u64 = - 1;
/// Reserved consensus-namespace identifier for the cluster's metadata replica.
///
/// The packed layout uses only bits `0..PACKED_NAMESPACE_BITS`, so the top
/// bit is unreachable from any packed namespace value. Routers distinguish
/// metadata's single global consensus group from per-partition consensus
/// groups by value alone.
pub const METADATA_CONSENSUS_NAMESPACE: u64 = 1u64 << 63;
// Compile-time invariants. Bumping `MAX_STREAMS`/`MAX_TOPICS`/`MAX_PARTITIONS`
// past the values here would silently collapse the sentinel-above-packed-range
// guarantee and route writes to the wrong shard; the assertions guard against
// that in every build (release included), not only under `cargo test`.
const _: = ;