Oregami
Repositories/oxedyne/fe2o3

oxedyne/fe2o3/fe2o3_o3db_sync/src/base/id.rs

4.5 KiB, 16 runs

created by r1870400018:723, which is this file's identity for as long as the history lasts, whatever it is later renamed to

download · who wrote it · its history

1use crate::{
2 base::index::{
3 BotPoolInd,
4 WorkerInd,
5 ZoneInd,
6 },
7 bots::worker::bot::WorkerType,
8};
9use oxedyne_fe2o3_core::{
10 prelude::*,
11 rand::RanDef,
12};
13use oxedyne_fe2o3_jdat::{
14 id::IdDat,
15 kind::Kind,
16 usr::UsrKindId,
17};
18
19use std::{
20 fmt::{
21 self,
22 Debug,
23 Display,
24 },
25 mem,
26};
27
28pub type BidTyp = u64;
29pub const BID_LEN: usize = mem::size_of::<BidTyp>();
30pub type Bid = IdDat<{ BID_LEN }, BidTyp>;
31
32pub type TicketTyp = u64;
33// A random ticket that tags a database request so that its responses can be
34// correlated back to the originating call.
35new_type!(Ticket, TicketTyp, Clone, Copy, Default, Eq, Ord, PartialEq, PartialOrd);
36
37impl fmt::Display for Ticket {
38 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
39 write!(f, "{:x?}", self.0)
40 }
41}
42
43impl fmt::Debug for Ticket {
44 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
45 write!(f, "Ticket({:x?})", self.0)
46 }
47}
48
49impl Ticket {
50 pub fn new() -> Self {
51 Self(TicketTyp::randef())
52 }
53 pub fn zero() -> Self {
54 Self(0)
55 }
56}
57
58#[derive(Clone, Eq, Hash, PartialEq)]
59pub enum OzoneBotId {
60 CacheBot(Bid, ZoneInd, BotPoolInd),
61 ConfigBot(Bid),
62 FileBot(Bid, ZoneInd, BotPoolInd),
63 InitGarbageBot(Bid, ZoneInd, BotPoolInd),
64 Master(Bid),
65 ReaderBot(Bid, ZoneInd, BotPoolInd),
66 ScanBot(Bid, ZoneInd, BotPoolInd),
67 ServerBot(Bid, BotPoolInd),
68 Supervisor(Bid),
69 WriterBot(Bid, ZoneInd, BotPoolInd),
70 ZoneBot(Bid, ZoneInd),
71}
72
73impl Debug for OzoneBotId {
74 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
75 match self {
76 Self::CacheBot(bid, zind, bpind) => write!(f, "CacheBot:{}:{}:{}", zind, bpind, bid),
77 Self::ConfigBot(bid) => write!(f, "ConfigBot:{}", bid),
78 Self::FileBot(bid, zind, bpind) => write!(f, "FileBot:{}:{}:{}", zind, bpind, bid),
79 Self::InitGarbageBot(bid, zind, bpind) => write!(f, "InitGarbageBot:{}:{}:{}", zind, bpind, bid),
80 Self::Master(bid) => write!(f, "Master:{}", bid),
81 Self::ReaderBot(bid, zind, bpind) => write!(f, "ReaderBot:{}:{}:{}", zind, bpind, bid),
82 Self::ScanBot(bid, zind, bpind) => write!(f, "ScanBot:{}:{}:{}", zind, bpind, bid),
83 Self::ServerBot(bid, bpind) => write!(f, "ServerBot:{}:{}", bpind, bid),
84 Self::Supervisor(bid) => write!(f, "Supervisor:{}", bid),
85 Self::WriterBot(bid, zind, bpind) => write!(f, "WriterBot:{}:{}:{}", zind, bpind, bid),
86 Self::ZoneBot(bid, zind) => write!(f, "ZoneBot:{}:{}", zind, bid),
87 }
88 }
89}
90
91impl Display for OzoneBotId {
92 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
93 write!(f, "{:?}", self)
94 }
95}
96
97impl OzoneBotId {
98 pub fn bid(&self) -> Bid {
99 match self {
100 Self::CacheBot(bid, ..) => *bid,
101 Self::ConfigBot(bid) => *bid,
102 Self::FileBot(bid, ..) => *bid,
103 Self::InitGarbageBot(bid, ..) => *bid,
104 Self::Master(bid) => *bid,
105 Self::ReaderBot(bid, ..) => *bid,
106 Self::ScanBot(bid, ..) => *bid,
107 Self::ServerBot(bid, ..) => *bid,
108 Self::Supervisor(bid) => *bid,
109 Self::WriterBot(bid, ..) => *bid,
110 Self::ZoneBot(bid, ..) => *bid,
111 }
112 }
113 pub fn new_worker(wtyp: &WorkerType, wind: &WorkerInd) -> Self {
114 match wtyp {
115 WorkerType::Cache => Self::CacheBot(Bid::randef(), *wind.zind(), *wind.bpind()),
116 WorkerType::File => Self::FileBot(Bid::randef(), *wind.zind(), *wind.bpind()),
117 WorkerType::InitGarbage => Self::InitGarbageBot(Bid::randef(), *wind.zind(), *wind.bpind()),
118 WorkerType::Reader => Self::ReaderBot(Bid::randef(), *wind.zind(), *wind.bpind()),
119 WorkerType::Scan => Self::ScanBot(Bid::randef(), *wind.zind(), *wind.bpind()),
120 WorkerType::Writer => Self::WriterBot(Bid::randef(), *wind.zind(), *wind.bpind()),
121 }
122 }
123}
124
125pub fn usr_kind_id_user() -> UsrKindId {
126 UsrKindId::new(
127 64_000,
128 Some("USER"),
129 Some(Kind::U128),
130 )
131}
132
133pub fn usr_kind_id_deleted() -> UsrKindId {
134 UsrKindId::new(
135 64_100,
136 Some("DELETED"),
137 Some(Kind::Empty),
138 )
139}