Skip to main content

reduct_base/msg/
replication_api.rs

1// Copyright 2021-2026 ReductSoftware UG
2// Licensed under the Apache License, Version 2.0
3use crate::msg::diagnostics::Diagnostics;
4use crate::Labels;
5use serde::{Deserialize, Serialize};
6use serde_json::Value;
7
8/// Replication mode
9#[derive(Serialize, Deserialize, Clone, Copy, Debug, PartialEq, Eq)]
10#[serde(rename_all = "lowercase")]
11pub enum ReplicationMode {
12    /// Replication is active and sends records
13    Enabled,
14    /// Replication stores transactions but doesn't send them
15    Paused,
16    /// Replication ignores new transactions
17    Disabled,
18}
19
20impl Default for ReplicationMode {
21    fn default() -> Self {
22        Self::Enabled
23    }
24}
25
26/// Replication settings
27#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Default)]
28pub struct ReplicationSettings {
29    /// Source bucket
30    pub src_bucket: String,
31    /// Destination bucket
32    pub dst_bucket: String,
33    /// Destination host URL (e.g. https://reductstore.com)
34    pub dst_host: String,
35    /// Destination access token
36    pub dst_token: Option<String>,
37    /// Entries to replicate. If empty, all entries are replicated. Wildcards are supported.
38    #[serde(default)]
39    pub entries: Vec<String>,
40    /// Labels to include
41    #[serde(default)]
42    pub include: Labels,
43    /// Labels to exclude
44    #[serde(default)]
45    pub exclude: Labels,
46    /// Replication each N-th record
47    #[serde(default)]
48    pub each_n: Option<u64>,
49    /// Replication a record every S seconds
50    #[serde(default)]
51    pub each_s: Option<f64>,
52    /// When condition
53    #[serde(default)]
54    pub when: Option<Value>,
55    /// Mode
56    #[serde(default)]
57    pub mode: ReplicationMode,
58}
59
60/// Replication info
61#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
62pub struct ReplicationInfo {
63    /// Replication name
64    pub name: String,
65    /// Replication mode
66    #[serde(default)] // for backward compatibility with older versions of reduct-rs
67    pub mode: ReplicationMode,
68    /// Remote instance is available and replication is active
69    pub is_active: bool,
70    /// Replication is provisioned
71    pub is_provisioned: bool,
72    /// Number of records pending replication
73    pub pending_records: u64,
74}
75
76/// Payload for updating replication mode
77#[derive(Serialize, Deserialize, Clone, Copy, Debug, PartialEq, Eq)]
78pub struct ReplicationModePayload {
79    pub mode: ReplicationMode,
80}
81
82/// Replication list
83#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Default)]
84pub struct ReplicationList {
85    /// Replication list
86    pub replications: Vec<ReplicationInfo>,
87}
88
89/// Replication settings
90#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
91pub struct FullReplicationInfo {
92    /// Info
93    pub info: ReplicationInfo,
94    /// Settings
95    pub settings: ReplicationSettings,
96    /// Diagnostics
97    pub diagnostics: Diagnostics,
98}