1use mssf_core::{
10 WString,
11 runtime::{
12 executor::BoxedCancelToken,
13 stateful::{PrimaryReplicator, Replicator},
14 stateful_proxy::StatefulServicePartition,
15 },
16 types::{
17 Epoch, ReplicaInformation, ReplicaRole, ReplicaSetConfig, ReplicaSetQuorumMode,
18 ServicePartitionAccessStatus,
19 },
20};
21
22#[derive(Clone)]
26pub struct EmptyReplicator {
27 name: WString,
28 partition: Option<StatefulServicePartition>,
29}
30
31impl EmptyReplicator {
32 fn read_status(&self) -> Option<ServicePartitionAccessStatus> {
34 self.partition
35 .as_ref()
36 .map(|p| p.get_read_status().ok())
37 .unwrap_or(None)
38 }
39
40 fn write_status(&self) -> Option<ServicePartitionAccessStatus> {
42 self.partition
43 .as_ref()
44 .map(|p| p.get_write_status().ok())
45 .unwrap_or(None)
46 }
47}
48
49impl std::fmt::Debug for EmptyReplicator {
51 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
52 write!(f, "EmptyReplicator-{}", self.name)
53 }
54}
55
56impl EmptyReplicator {
57 pub fn new(name: WString, partition: Option<StatefulServicePartition>) -> EmptyReplicator {
59 EmptyReplicator { name, partition }
60 }
61}
62
63impl Replicator for EmptyReplicator {
65 #[tracing::instrument(err, ret)]
66 async fn open(&self, _: BoxedCancelToken) -> mssf_core::Result<WString> {
67 Ok(WString::from("NoProtocol://localhost:0"))
69 }
70
71 #[tracing::instrument(err, ret)]
72 async fn close(&self, _: BoxedCancelToken) -> mssf_core::Result<()> {
73 Ok(())
74 }
75
76 #[tracing::instrument(fields(read_status = ?self.read_status(), write_status = ?self.write_status()), err, ret)]
77 async fn change_role(
78 &self,
79 epoch: &Epoch,
80 role: &ReplicaRole,
81 _: BoxedCancelToken,
82 ) -> mssf_core::Result<()> {
83 Ok(())
84 }
85
86 #[tracing::instrument(fields(read_status = ?self.read_status(), write_status = ?self.write_status()), err, ret)]
87 async fn update_epoch(&self, epoch: &Epoch, _: BoxedCancelToken) -> mssf_core::Result<()> {
88 Ok(())
89 }
90
91 #[tracing::instrument(err, ret)]
92 fn get_current_progress(&self) -> mssf_core::Result<i64> {
93 Ok(1)
94 }
95
96 #[tracing::instrument(err, ret)]
97 fn get_catch_up_capability(&self) -> mssf_core::Result<i64> {
98 Ok(1)
99 }
100
101 #[tracing::instrument(skip(self))]
102 fn abort(&self) {
103 tracing::info!("abort");
104 }
105}
106
107impl PrimaryReplicator for EmptyReplicator {
109 async fn on_data_loss(&self, _: BoxedCancelToken) -> mssf_core::Result<u8> {
110 Ok(0)
111 }
112
113 #[tracing::instrument(err, ret)]
114 fn update_catch_up_replica_set_configuration(
115 &self,
116 currentconfiguration: &ReplicaSetConfig,
117 previousconfiguration: &ReplicaSetConfig,
118 ) -> mssf_core::Result<()> {
119 Ok(())
120 }
121
122 #[tracing::instrument(fields(read_status = ?self.read_status(), write_status = ?self.write_status()), err, ret)]
123 async fn wait_for_catch_up_quorum(
124 &self,
125 catchupmode: ReplicaSetQuorumMode,
126 _: BoxedCancelToken,
127 ) -> mssf_core::Result<()> {
128 Ok(())
149 }
150
151 #[tracing::instrument(err, ret)]
152 fn update_current_replica_set_configuration(
153 &self,
154 currentconfiguration: &ReplicaSetConfig,
155 ) -> mssf_core::Result<()> {
156 Ok(())
157 }
158
159 #[tracing::instrument(err, ret)]
160 async fn build_replica(
161 &self,
162 replica: &ReplicaInformation,
163 _: BoxedCancelToken,
164 ) -> mssf_core::Result<()> {
165 Ok(())
166 }
167
168 #[tracing::instrument(err, ret)]
169 fn remove_replica(&self, _replicaid: i64) -> mssf_core::Result<()> {
170 Ok(())
171 }
172}