arete_server/
mutation_batch.rs1use arete_interpreter::Mutation;
4use smallvec::SmallVec;
5use tracing::Span;
6
7#[derive(Debug, Clone, Copy, Default)]
10pub struct SlotContext {
11 pub slot: u64,
13 pub slot_index: u64,
15}
16
17impl SlotContext {
18 pub fn new(slot: u64, slot_index: u64) -> Self {
19 Self { slot, slot_index }
20 }
21
22 pub fn to_seq_string(&self) -> String {
26 format!("{}:{:012}", self.slot, self.slot_index)
27 }
28}
29
30#[derive(Debug)]
35pub struct MutationBatch {
36 pub span: Span,
38 pub mutations: SmallVec<[Mutation; 6]>,
40 pub slot_context: Option<SlotContext>,
42 pub event_context: Option<EventContext>,
44 pub flush_ack: Option<tokio::sync::oneshot::Sender<()>>,
48 pub(crate) snapshot_guard: Option<crate::snapshot::SnapshotProcessingGuard>,
51}
52
53#[derive(Debug, Clone)]
54pub struct EventContext {
55 pub program: String,
56 pub event_kind: String,
57 pub event_type: String,
58 pub account: Option<String>,
59 pub accounts_count: Option<usize>,
60}
61
62impl MutationBatch {
63 pub fn new(mutations: SmallVec<[Mutation; 6]>) -> Self {
64 Self {
65 span: Span::current(),
66 mutations,
67 slot_context: None,
68 event_context: None,
69 flush_ack: None,
70 snapshot_guard: None,
71 }
72 }
73
74 pub fn with_span(span: Span, mutations: SmallVec<[Mutation; 6]>) -> Self {
75 Self {
76 span,
77 mutations,
78 slot_context: None,
79 event_context: None,
80 flush_ack: None,
81 snapshot_guard: None,
82 }
83 }
84
85 pub fn with_slot_context(
86 mutations: SmallVec<[Mutation; 6]>,
87 slot_context: SlotContext,
88 ) -> Self {
89 Self {
90 span: Span::current(),
91 mutations,
92 slot_context: Some(slot_context),
93 event_context: None,
94 flush_ack: None,
95 snapshot_guard: None,
96 }
97 }
98
99 pub fn flush_marker(ack: tokio::sync::oneshot::Sender<()>) -> Self {
102 Self {
103 span: Span::current(),
104 mutations: SmallVec::new(),
105 slot_context: None,
106 event_context: None,
107 flush_ack: Some(ack),
108 snapshot_guard: None,
109 }
110 }
111
112 pub fn with_snapshot_guard(mut self, guard: crate::snapshot::SnapshotProcessingGuard) -> Self {
115 self.snapshot_guard = Some(guard);
116 self
117 }
118
119 pub fn with_event_context(mut self, event_context: EventContext) -> Self {
120 self.event_context = Some(event_context);
121 self
122 }
123
124 pub fn len(&self) -> usize {
125 self.mutations.len()
126 }
127
128 pub fn is_empty(&self) -> bool {
129 self.mutations.is_empty()
130 }
131}