pub struct StreamId(/* private fields */);Expand description
One stream: a run of one runtime of one node. <node 32 hex>-<runtime 16 hex>-<instance 16 hex>. The node is the machine’s key, the runtime is one checkout’s server on that
machine, the instance is one process run of that server — so two worktrees on one
machine are two streams, and a restart is a new stream of the same runtime.
Numbering events within a stream rather than globally is what makes replication cheap
and unambiguous: a gap in one stream is visible without coordinating with anyone, and
(stream, seq) identifies an event on every machine that holds it.
use majordomus_cli::mesh::journal::StreamId;
let id = StreamId::new(&"a".repeat(32), &"b".repeat(16), &"c".repeat(16)).unwrap();
assert_eq!(id.node(), "a".repeat(32));
assert_eq!(id.runtime(), "b".repeat(16));
// a restart is a new stream, and the same runtime
let after = StreamId::new(&"a".repeat(32), &"b".repeat(16), &"d".repeat(16)).unwrap();
assert_ne!(after, id);
assert_eq!(after.runtime_key(), id.runtime_key());Implementations§
Source§impl StreamId
impl StreamId
Sourcepub fn new(node: &str, runtime: &str, instance: &str) -> Option<Self>
pub fn new(node: &str, runtime: &str, instance: &str) -> Option<Self>
A stream id from its three parts; None unless each is lowercase hex of its width.
The widths are checked here rather than trusted, because every accessor slices the text at fixed offsets: an id built from a part of the wrong length would be a panic waiting in a peer’s marks, and the parts often come from another machine.
use majordomus_cli::mesh::journal::StreamId;
assert!(StreamId::new(&"a".repeat(32), &"b".repeat(16), &"c".repeat(16)).is_some());
assert!(StreamId::new("short", &"b".repeat(16), &"c".repeat(16)).is_none());
assert!(StreamId::new(&"A".repeat(32), &"b".repeat(16), &"c".repeat(16)).is_none(),
"one spelling only: lowercase hex");Sourcepub fn parse(text: &str) -> Option<Self>
pub fn parse(text: &str) -> Option<Self>
Parse a stream id, refusing anything that is not exactly the three hex parts.
use majordomus_cli::mesh::journal::StreamId;
assert!(StreamId::parse("nope").is_none());
let id = format!("{}-{}-{}", "a".repeat(32), "b".repeat(16), "c".repeat(16));
assert_eq!(StreamId::parse(&id).unwrap().runtime_key(), format!("{}-{}", "a".repeat(32), "b".repeat(16)));Sourcepub fn node(&self) -> &str
pub fn node(&self) -> &str
The node (machine key digest) part: which machine’s key signs everything this stream carries. Two streams that share a node are two servers of one machine, and the per-node bounds of the journal are counted against this.
use majordomus_cli::mesh::journal::StreamId;
let id = StreamId::new(&"a".repeat(32), &"b".repeat(16), &"c".repeat(16)).unwrap();
let sibling = StreamId::new(&"a".repeat(32), &"e".repeat(16), &"f".repeat(16)).unwrap();
assert_eq!(id.node(), sibling.node(), "two runtimes of one machine");
assert_ne!(id.runtime_key(), sibling.runtime_key());Sourcepub fn runtime(&self) -> &str
pub fn runtime(&self) -> &str
The runtime part: which server of that machine — one per checkout — so two worktrees of one clone are told apart and can claim against each other.
use majordomus_cli::mesh::journal::StreamId;
let id = StreamId::new(&"a".repeat(32), &"b".repeat(16), &"c".repeat(16)).unwrap();
assert_eq!(id.runtime(), "b".repeat(16));
assert_eq!(id.runtime_key(), format!("{}-{}", id.node(), id.runtime()));Sourcepub fn instance(&self) -> &str
pub fn instance(&self) -> &str
The instance part: which run of that server. It is what makes a restart visible — the same runtime with a new instance has a fresh sequence, so a peer knows to say hello again rather than resume a link whose counters no longer mean anything.
use majordomus_cli::mesh::journal::StreamId;
let before = StreamId::new(&"a".repeat(32), &"b".repeat(16), &"c".repeat(16)).unwrap();
let after = StreamId::new(&"a".repeat(32), &"b".repeat(16), &"d".repeat(16)).unwrap();
assert_ne!(before.instance(), after.instance(), "a restart is a new run");
assert_eq!(before.runtime(), after.runtime(), "of the same server");Sourcepub fn runtime_key(&self) -> String
pub fn runtime_key(&self) -> String
<node>-<runtime>: the durable identity of a runtime across its restarts. It is
what the peer table, a claim key and mesh peer are all keyed by, because a worker
cares which server it is talking to and not which run of it.
use majordomus_cli::mesh::journal::StreamId;
let before = StreamId::new(&"a".repeat(32), &"b".repeat(16), &"c".repeat(16)).unwrap();
let after = StreamId::new(&"a".repeat(32), &"b".repeat(16), &"d".repeat(16)).unwrap();
assert_eq!(before.runtime_key(), after.runtime_key(), "one peer, two runs");
assert_eq!(before.runtime_key().len(), 49);Trait Implementations§
Source§impl<'de> Deserialize<'de> for StreamId
impl<'de> Deserialize<'de> for StreamId
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for StreamId
Source§impl JsonSchema for StreamId
impl JsonSchema for StreamId
Source§fn schema_id() -> Cow<'static, str>
fn schema_id() -> Cow<'static, str>
Source§fn json_schema(generator: &mut SchemaGenerator) -> Schema
fn json_schema(generator: &mut SchemaGenerator) -> Schema
Source§fn inline_schema() -> bool
fn inline_schema() -> bool
$ref keyword. Read moreSource§impl Ord for StreamId
impl Ord for StreamId
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialOrd for StreamId
impl PartialOrd for StreamId
impl StructuralPartialEq for StreamId
Auto Trait Implementations§
impl Freeze for StreamId
impl RefUnwindSafe for StreamId
impl Send for StreamId
impl Sync for StreamId
impl Unpin for StreamId
impl UnsafeUnpin for StreamId
impl UnwindSafe for StreamId
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.