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 serde::{Deserialize, Serialize};
5use serde_json::Value;
6
7/// Replication mode
8#[derive(Serialize, Deserialize, Clone, Copy, Debug, PartialEq, Eq)]
9#[serde(rename_all = "lowercase")]
10pub enum ReplicationMode {
11    /// Replication is active and sends records
12    Enabled,
13    /// Replication stores transactions but doesn't send them
14    Paused,
15    /// Replication ignores new transactions
16    Disabled,
17}
18
19impl Default for ReplicationMode {
20    fn default() -> Self {
21        Self::Enabled
22    }
23}
24
25/// Compression of batch payloads during transfer
26#[derive(Serialize, Deserialize, Clone, Copy, Debug, PartialEq, Eq, Default)]
27#[serde(rename_all = "lowercase")]
28pub enum ReplicationCompression {
29    /// No compression
30    #[default]
31    None,
32    /// Zstandard compression
33    Zstd,
34    /// Gzip compression
35    Gzip,
36}
37
38/// Replication settings
39#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Default)]
40pub struct ReplicationSettings {
41    /// Source bucket
42    pub src_bucket: String,
43    /// Destination bucket
44    pub dst_bucket: String,
45    /// Destination host URL (e.g. https://reductstore.com)
46    pub dst_host: String,
47    /// Destination access token
48    pub dst_token: Option<String>,
49    /// Entries to replicate. If empty, all entries are replicated. Supports exact names,
50    /// glob-like `*` and `**` wildcards, and `!` exclusion patterns.
51    #[serde(default)]
52    pub entries: Vec<String>,
53    /// Prefix to add to destination entry names
54    #[serde(default)]
55    pub dst_prefix: String,
56    /// When condition
57    #[serde(default)]
58    pub when: Option<Value>,
59    /// Mode
60    #[serde(default)]
61    pub mode: ReplicationMode,
62    /// Compression of batch payloads during transfer
63    #[serde(default)]
64    pub compression: ReplicationCompression,
65}
66
67/// Replication info
68#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
69pub struct ReplicationInfo {
70    /// Replication name
71    pub name: String,
72    /// Replication mode
73    #[serde(default)] // for backward compatibility with older versions of reduct-rs
74    pub mode: ReplicationMode,
75    /// Remote instance is available and replication is active
76    pub is_active: bool,
77    /// Replication is provisioned
78    pub is_provisioned: bool,
79    /// Number of records pending replication
80    pub pending_records: u64,
81}
82
83/// Payload for updating replication mode
84#[derive(Serialize, Deserialize, Clone, Copy, Debug, PartialEq, Eq)]
85pub struct ReplicationModePayload {
86    pub mode: ReplicationMode,
87}
88
89/// Replication list
90#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Default)]
91pub struct ReplicationList {
92    /// Replication list
93    pub replications: Vec<ReplicationInfo>,
94}
95
96/// Replication settings
97#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
98pub struct FullReplicationInfo {
99    /// Info
100    pub info: ReplicationInfo,
101    /// Settings
102    pub settings: ReplicationSettings,
103    /// Diagnostics
104    pub diagnostics: Diagnostics,
105}