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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
use crate::client::Client;
use crate::error::Result;
use crate::models::{
GenericResponse, GetOplogResponse, OplogStatusResponse, RegisterReplicaRequest,
UnRegisterReplicaRequest, UpdateReplicaLSNRequest, UpdateReplicaLSNResponse,
};
use std::collections::HashMap;
impl Client {
/// Retrieves oplog entries after a specific LSN for replica synchronization
/// Parameters:
/// - collection: Collection name to retrieve oplog entries for (optional, if empty returns entries for all collections)
/// - after_lsn: LSN after which to retrieve oplog entries (required)
/// - limit: Maximum number of oplog entries to retrieve (optional)
pub async fn get_oplog_entries(
&self,
collection: Option<&str>,
after_lsn: u64,
limit: Option<i32>,
) -> Result<GetOplogResponse> {
let mut params = HashMap::new();
params.insert("after_lsn".to_string(), after_lsn.to_string());
if let Some(coll) = collection {
params.insert("collection".to_string(), coll.to_string());
}
if let Some(lim) = limit {
params.insert("limit".to_string(), lim.to_string());
}
self.do_request::<GetOplogResponse, ()>(
reqwest::Method::GET,
"/api/oplog/v1/",
None,
Some(¶ms),
)
.await
}
/// Updates the last applied LSN for a replica (heartbeat)
/// Parameters:
/// - collection: Collection name
/// - replica_id: Replica identifier
/// - lsn: Last applied LSN
pub async fn update_replica_lsn(
&self,
collection: &str,
replica_id: &str,
lsn: u64,
) -> Result<UpdateReplicaLSNResponse> {
let req = UpdateReplicaLSNRequest {
collection: collection.to_string(),
replica_id: replica_id.to_string(),
lsn,
};
self.do_request(
reqwest::Method::POST,
"/api/oplog/v1/heartbeat",
Some(&req),
None,
)
.await
}
/// Registers a replica for oplog retention tracking
/// Parameters:
/// - replica_id: Replica identifier
pub async fn register_replica(&self, replica_id: &str) -> Result<GenericResponse> {
let req = RegisterReplicaRequest {
replica_id: replica_id.to_string(),
};
self.do_request(
reqwest::Method::POST,
"/api/oplog/v1/register",
Some(&req),
None,
)
.await
}
/// Unregisters a replica for oplog retention tracking
/// Parameters:
/// - replica_id: Replica identifier
pub async fn unregister_replica(&self, replica_id: &str) -> Result<GenericResponse> {
let req = UnRegisterReplicaRequest {
replica_id: replica_id.to_string(),
};
self.do_request(
reqwest::Method::POST,
"/api/oplog/v1/unregister",
Some(&req),
None,
)
.await
}
/// Retrieves current oplog status and statistics for a collection
/// Parameters:
/// - collection: Collection name to retrieve oplog status for (required)
pub async fn get_oplog_status(&self, collection: &str) -> Result<OplogStatusResponse> {
let mut params = HashMap::new();
params.insert("collection".to_string(), collection.to_string());
self.do_request::<OplogStatusResponse, ()>(
reqwest::Method::GET,
"/api/oplog/v1/status",
None,
Some(¶ms),
)
.await
}
}